/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_commit.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
        """Commit and check two versions of a single file."""
87
87
        wt = self.make_branch_and_tree('.')
88
88
        b = wt.branch
89
 
        with open('hello', 'w') as f: f.write('hello world')
 
89
        with open('hello', 'w') as f:
 
90
            f.write('hello world')
90
91
        wt.add('hello')
91
92
        rev1 = wt.commit(message='add hello')
92
93
 
93
 
        with open('hello', 'w') as f: f.write('version 2')
 
94
        with open('hello', 'w') as f:
 
95
            f.write('version 2')
94
96
        rev2 = wt.commit(message='commit 2')
95
97
 
96
98
        eq = self.assertEqual
114
116
        """Attempt a lossy commit to a native branch."""
115
117
        wt = self.make_branch_and_tree('.')
116
118
        b = wt.branch
117
 
        with open('hello', 'w') as f: f.write('hello world')
 
119
        with open('hello', 'w') as f:
 
120
            f.write('hello world')
118
121
        wt.add('hello')
119
122
        revid = wt.commit(message='add hello', rev_id=b'revid', lossy=True)
120
123
        self.assertEqual(b'revid', revid)
123
126
        """Attempt a lossy commit to a foreign branch."""
124
127
        test_foreign.register_dummy_foreign_for_test(self)
125
128
        wt = self.make_branch_and_tree('.',
126
 
            format=test_foreign.DummyForeignVcsDirFormat())
 
129
                                       format=test_foreign.DummyForeignVcsDirFormat())
127
130
        b = wt.branch
128
 
        with open('hello', 'w') as f: f.write('hello world')
 
131
        with open('hello', 'w') as f:
 
132
            f.write('hello world')
129
133
        wt.add('hello')
130
134
        revid = wt.commit(message='add hello', lossy=True,
131
 
            timestamp=1302659388, timezone=0)
 
135
                          timestamp=1302659388, timezone=0)
132
136
        self.assertEqual(b'dummy-v1:1302659388-0-UNKNOWN', revid)
133
137
 
134
138
    def test_commit_bound_lossy_foreign(self):
135
139
        """Attempt a lossy commit to a bzr branch bound to a foreign branch."""
136
140
        test_foreign.register_dummy_foreign_for_test(self)
137
141
        foreign_branch = self.make_branch('foreign',
138
 
            format=test_foreign.DummyForeignVcsDirFormat())
 
142
                                          format=test_foreign.DummyForeignVcsDirFormat())
139
143
        wt = foreign_branch.create_checkout("local")
140
144
        b = wt.branch
141
 
        with open('local/hello', 'w') as f: f.write('hello world')
 
145
        with open('local/hello', 'w') as f:
 
146
            f.write('hello world')
142
147
        wt.add('hello')
143
148
        revid = wt.commit(message='add hello', lossy=True,
144
 
            timestamp=1302659388, timezone=0)
 
149
                          timestamp=1302659388, timezone=0)
145
150
        self.assertEqual(b'dummy-v1:1302659388-0-0', revid)
146
151
        self.assertEqual(b'dummy-v1:1302659388-0-0',
147
 
            foreign_branch.last_revision())
 
152
                         foreign_branch.last_revision())
148
153
        self.assertEqual(b'dummy-v1:1302659388-0-0',
149
 
            wt.branch.last_revision())
 
154
                         wt.branch.last_revision())
150
155
 
151
156
    def test_missing_commit(self):
152
157
        """Test a commit with a missing file"""
153
158
        wt = self.make_branch_and_tree('.')
154
159
        b = wt.branch
155
 
        with open('hello', 'w') as f: f.write('hello world')
 
160
        with open('hello', 'w') as f:
 
161
            f.write('hello world')
156
162
        wt.add(['hello'], [b'hello-id'])
157
163
        wt.commit(message='add hello')
158
164
 
179
185
        b = wt.branch
180
186
        self.build_tree(['annotate/', 'annotate/foo.py',
181
187
                         'olive/', 'olive/dialog.py'
182
 
                        ])
 
188
                         ])
183
189
        wt.add(['annotate', 'olive', 'annotate/foo.py', 'olive/dialog.py'])
184
190
        wt.commit(message='add files')
185
191
        wt.rename_one("olive/dialog.py", "aaa")
190
196
        """Commit refuses unless there are changes or it's forced."""
191
197
        wt = self.make_branch_and_tree('.')
192
198
        b = wt.branch
193
 
        with open('hello', 'w') as f: f.write('hello')
 
199
        with open('hello', 'w') as f:
 
200
            f.write('hello')
194
201
        wt.add(['hello'])
195
202
        wt.commit(message='add hello')
196
203
        self.assertEqual(b.revno(), 1)
216
223
        """Selective commit in tree with deletions"""
217
224
        wt = self.make_branch_and_tree('.')
218
225
        b = wt.branch
219
 
        with open('hello', 'w') as f: f.write('hello')
220
 
        with open('buongia', 'w') as f: f.write('buongia')
 
226
        with open('hello', 'w') as f:
 
227
            f.write('hello')
 
228
        with open('buongia', 'w') as f:
 
229
            f.write('buongia')
221
230
        wt.add(['hello', 'buongia'],
222
 
              [b'hello-id', b'buongia-id'])
 
231
               [b'hello-id', b'buongia-id'])
223
232
        wt.commit(message='add files',
224
 
                 rev_id=b'test@rev-1')
 
233
                  rev_id=b'test@rev-1')
225
234
 
226
235
        os.remove('hello')
227
 
        with open('buongia', 'w') as f: f.write('new text')
 
236
        with open('buongia', 'w') as f:
 
237
            f.write('new text')
228
238
        wt.commit(message='update text',
229
 
                 specific_files=['buongia'],
230
 
                 allow_pointless=False,
231
 
                 rev_id=b'test@rev-2')
 
239
                  specific_files=['buongia'],
 
240
                  allow_pointless=False,
 
241
                  rev_id=b'test@rev-2')
232
242
 
233
243
        wt.commit(message='remove hello',
234
 
                 specific_files=['hello'],
235
 
                 allow_pointless=False,
236
 
                 rev_id=b'test@rev-3')
 
244
                  specific_files=['hello'],
 
245
                  allow_pointless=False,
 
246
                  rev_id=b'test@rev-3')
237
247
 
238
248
        eq = self.assertEqual
239
249
        eq(b.revno(), 3)
260
270
        tree.commit(message='one', rev_id=b'test@rev-1', allow_pointless=False)
261
271
 
262
272
        tree.rename_one('hello', 'fruity')
263
 
        tree.commit(message='renamed', rev_id=b'test@rev-2', allow_pointless=False)
 
273
        tree.commit(message='renamed', rev_id=b'test@rev-2',
 
274
                    allow_pointless=False)
264
275
 
265
276
        eq = self.assertEqual
266
277
        tree1 = b.repository.revision_tree(b'test@rev-1')
315
326
        wt.lock_read()
316
327
        try:
317
328
            self.check_tree_shape(wt,
318
 
                                       ['a/', 'a/hello', 'a/b/'])
 
329
                                  ['a/', 'a/hello', 'a/b/'])
319
330
            self.check_tree_shape(b.repository.revision_tree(r3),
320
 
                                       ['a/', 'a/hello', 'a/b/'])
 
331
                                  ['a/', 'a/hello', 'a/b/'])
321
332
        finally:
322
333
            wt.unlock()
323
334
 
339
350
        """Commit with a removed file"""
340
351
        wt = self.make_branch_and_tree('.')
341
352
        b = wt.branch
342
 
        with open('hello', 'w') as f: f.write('hello world')
 
353
        with open('hello', 'w') as f:
 
354
            f.write('hello world')
343
355
        wt.add(['hello'], [b'hello-id'])
344
356
        wt.commit(message='add hello')
345
357
        wt.remove('hello')
354
366
        b = wt.branch
355
367
        rev_ids = []
356
368
        for i in range(4):
357
 
            with open('hello', 'w') as f: f.write((str(i) * 4) + '\n')
 
369
            with open('hello', 'w') as f:
 
370
                f.write((str(i) * 4) + '\n')
358
371
            if i == 0:
359
372
                wt.add(['hello'], [b'hello-id'])
360
 
            rev_id = b'test@rev-%d' % (i+1)
 
373
            rev_id = b'test@rev-%d' % (i + 1)
361
374
            rev_ids.append(rev_id)
362
 
            wt.commit(message='rev %d' % (i+1),
363
 
                     rev_id=rev_id)
 
375
            wt.commit(message='rev %d' % (i + 1),
 
376
                      rev_id=rev_id)
364
377
        for i in range(4):
365
 
            self.assertThat(rev_ids[:i+1],
366
 
                MatchesAncestry(b.repository, rev_ids[i]))
 
378
            self.assertThat(rev_ids[:i + 1],
 
379
                            MatchesAncestry(b.repository, rev_ids[i]))
367
380
 
368
381
    def test_commit_new_subdir_child_selective(self):
369
382
        wt = self.make_branch_and_tree('.')
370
383
        b = wt.branch
371
384
        self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
372
385
        wt.add(['dir', 'dir/file1', 'dir/file2'],
373
 
              [b'dirid', b'file1id', b'file2id'])
 
386
               [b'dirid', b'file1id', b'file2id'])
374
387
        wt.commit('dir/file1', specific_files=['dir/file1'], rev_id=b'1')
375
388
        inv = b.repository.get_inventory(b'1')
376
389
        self.assertEqual(b'1', inv.get_entry(b'dirid').revision)
383
396
        from ..errors import StrictCommitFailed
384
397
        wt = self.make_branch_and_tree('.')
385
398
        b = wt.branch
386
 
        with open('hello', 'w') as f: f.write('hello world')
 
399
        with open('hello', 'w') as f:
 
400
            f.write('hello world')
387
401
        wt.add('hello')
388
 
        with open('goodbye', 'w') as f: f.write('goodbye cruel world!')
 
402
        with open('goodbye', 'w') as f:
 
403
            f.write('goodbye cruel world!')
389
404
        self.assertRaises(StrictCommitFailed, wt.commit,
390
 
            message='add hello but not goodbye', strict=True)
 
405
                          message='add hello but not goodbye', strict=True)
391
406
 
392
407
    def test_strict_commit_without_unknowns(self):
393
408
        """Try and commit with no unknown files and strict = True,
394
409
        should work."""
395
410
        wt = self.make_branch_and_tree('.')
396
411
        b = wt.branch
397
 
        with open('hello', 'w') as f: f.write('hello world')
 
412
        with open('hello', 'w') as f:
 
413
            f.write('hello world')
398
414
        wt.add('hello')
399
415
        wt.commit(message='add hello', strict=True)
400
416
 
402
418
        """Try and commit with unknown files and strict = False, should work."""
403
419
        wt = self.make_branch_and_tree('.')
404
420
        b = wt.branch
405
 
        with open('hello', 'w') as f: f.write('hello world')
 
421
        with open('hello', 'w') as f:
 
422
            f.write('hello world')
406
423
        wt.add('hello')
407
 
        with open('goodbye', 'w') as f: f.write('goodbye cruel world!')
 
424
        with open('goodbye', 'w') as f:
 
425
            f.write('goodbye cruel world!')
408
426
        wt.commit(message='add hello but not goodbye', strict=False)
409
427
 
410
428
    def test_nonstrict_commit_without_unknowns(self):
412
430
        should work."""
413
431
        wt = self.make_branch_and_tree('.')
414
432
        b = wt.branch
415
 
        with open('hello', 'w') as f: f.write('hello world')
 
433
        with open('hello', 'w') as f:
 
434
            f.write('hello world')
416
435
        wt.add('hello')
417
436
        wt.commit(message='add hello', strict=False)
418
437
 
434
453
            commit.Commit(config_stack=conf).commit(
435
454
                message="base", allow_pointless=True, rev_id=b'B',
436
455
                working_tree=wt)
 
456
 
437
457
            def sign(text):
438
458
                return breezy.gpg.LoopbackGPGStrategy(None).sign(
439
 
                        text, breezy.gpg.MODE_CLEAR)
 
459
                    text, breezy.gpg.MODE_CLEAR)
440
460
            self.assertEqual(sign(Testament.from_revision(branch.repository,
441
461
                                                          b'B').as_short_text()),
442
462
                             branch.repository.get_signature_text(b'B'))
474
494
        wt = self.make_branch_and_tree('.')
475
495
        branch = wt.branch
476
496
        calls = []
 
497
 
477
498
        def called(branch, rev_id):
478
499
            calls.append('called')
479
500
        breezy.ahook = called
480
501
        try:
481
502
            conf = config.MemoryStack(b'post_commit=breezy.ahook breezy.ahook')
482
503
            commit.Commit(config_stack=conf).commit(
483
 
                message = "base", allow_pointless=True, rev_id=b'A',
484
 
                working_tree = wt)
 
504
                message="base", allow_pointless=True, rev_id=b'A',
 
505
                working_tree=wt)
485
506
            self.assertEqual(['called', 'called'], calls)
486
507
        finally:
487
508
            del breezy.ahook
494
515
        self.assertEqual(wt.branch.revno(), 1)
495
516
        self.assertEqual({},
496
517
                         wt.branch.repository.get_revision(
497
 
                            wt.branch.last_revision()).properties)
 
518
            wt.branch.last_revision()).properties)
498
519
 
499
520
    def test_safe_master_lock(self):
500
521
        os.mkdir('master')
518
539
        bound_tree = self.make_branch_and_tree('bound')
519
540
        bound_tree.branch.bind(master_branch)
520
541
 
521
 
        self.build_tree_contents([('bound/content_file', b'initial contents\n')])
 
542
        self.build_tree_contents(
 
543
            [('bound/content_file', b'initial contents\n')])
522
544
        bound_tree.add(['content_file'])
523
545
        bound_tree.commit(message='woo!')
524
546
 
528
550
        # do a commit to the other branch changing the content file so
529
551
        # that our commit after merging will have a merged revision in the
530
552
        # content file history.
531
 
        self.build_tree_contents([('other/content_file', b'change in other\n')])
 
553
        self.build_tree_contents(
 
554
            [('other/content_file', b'change in other\n')])
532
555
        other_tree.commit('change in other')
533
556
 
534
557
        # do a merge into the bound branch from other, and then change the
535
558
        # content file locally to force a new revision (rather than using the
536
559
        # revision from other). This forces extra processing in commit.
537
560
        bound_tree.merge_from_branch(other_tree.branch)
538
 
        self.build_tree_contents([('bound/content_file', b'change in bound\n')])
 
561
        self.build_tree_contents(
 
562
            [('bound/content_file', b'change in bound\n')])
539
563
 
540
564
        # before #34959 was fixed, this failed with 'revision not present in
541
565
        # weave' when trying to implicitly push from the bound branch to the master
577
601
            other_tree.rename_one('dirtorename', 'renameddir')
578
602
            other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
579
603
            other_tree.rename_one('filetorename', 'renamedfile')
580
 
            other_tree.rename_one('filetoreparent', 'renameddir/reparentedfile')
 
604
            other_tree.rename_one(
 
605
                'filetoreparent', 'renameddir/reparentedfile')
581
606
            other_tree.remove(['dirtoremove', 'filetoremove'])
582
607
            self.build_tree_contents([
583
608
                ('other/newdir/', ),
746
771
        cb = self.Callback(u'commit 2', self)
747
772
        repository = tree.branch.repository
748
773
        # simulate network failure
 
774
 
749
775
        def raise_(self, arg, arg2, arg3=None, arg4=None):
750
776
            raise errors.NoSuchFile('foo')
751
777
        repository.add_inventory = raise_
762
788
        self.build_tree(['foo/bar', 'foo/baz'])
763
789
        tree.add(['bar', 'baz'])
764
790
        err = self.assertRaises(CannotCommitSelectedFileMerge,
765
 
            tree.commit, 'commit 2', specific_files=['bar', 'baz'])
 
791
                                tree.commit, 'commit 2', specific_files=['bar', 'baz'])
766
792
        self.assertEqual(['bar', 'baz'], err.files)
767
793
        self.assertEqual('Selected-file commit of merges is not supported'
768
794
                         ' yet: files bar, baz', str(err))
812
838
    def test_multiple_authors(self):
813
839
        tree = self.make_branch_and_tree('foo')
814
840
        rev_id = tree.commit('commit 1',
815
 
                authors=['John Doe <jdoe@example.com>',
816
 
                         'Jane Rey <jrey@example.com>'])
 
841
                             authors=['John Doe <jdoe@example.com>',
 
842
                                      'Jane Rey <jrey@example.com>'])
817
843
        rev = tree.branch.repository.get_revision(rev_id)
818
844
        self.assertEqual('John Doe <jdoe@example.com>\n'
819
 
                'Jane Rey <jrey@example.com>', rev.properties['authors'])
 
845
                         'Jane Rey <jrey@example.com>', rev.properties['authors'])
820
846
        self.assertFalse('author' in rev.properties)
821
847
 
822
848
    def test_author_with_newline_rejected(self):
823
849
        tree = self.make_branch_and_tree('foo')
824
850
        self.assertRaises(AssertionError, tree.commit, 'commit 1',
825
 
                authors=['John\nDoe <jdoe@example.com>'])
 
851
                          authors=['John\nDoe <jdoe@example.com>'])
826
852
 
827
853
    def test_commit_with_checkout_and_branch_sharing_repo(self):
828
854
        repo = self.make_repository('repo', shared=True)
840
866
            ('fid', (None, 'newpath'),
841
867
             0, (False, False), ('pid', 'pid'), ('newpath', 'newpath'),
842
868
             ('file', 'file'), (True, True))]
843
 
        self.assertEqual(changes, list(filter_excluded(changes, ['otherpath'])))
 
869
        self.assertEqual(changes, list(
 
870
            filter_excluded(changes, ['otherpath'])))
844
871
 
845
872
    def test_add_file_excluded(self):
846
873
        changes = [