/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: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
        """Commit and check two versions of a single file."""
89
89
        wt = self.make_branch_and_tree('.')
90
90
        b = wt.branch
91
 
        with open('hello', 'w') as f: f.write('hello world')
 
91
        with open('hello', 'w') as f:
 
92
            f.write('hello world')
92
93
        wt.add('hello')
93
94
        rev1 = wt.commit(message='add hello')
94
95
 
95
 
        with open('hello', 'w') as f: f.write('version 2')
 
96
        with open('hello', 'w') as f:
 
97
            f.write('version 2')
96
98
        rev2 = wt.commit(message='commit 2')
97
99
 
98
100
        eq = self.assertEqual
116
118
        """Attempt a lossy commit to a native branch."""
117
119
        wt = self.make_branch_and_tree('.')
118
120
        b = wt.branch
119
 
        with open('hello', 'w') as f: f.write('hello world')
 
121
        with open('hello', 'w') as f:
 
122
            f.write('hello world')
120
123
        wt.add('hello')
121
124
        revid = wt.commit(message='add hello', rev_id=b'revid', lossy=True)
122
125
        self.assertEqual(b'revid', revid)
125
128
        """Attempt a lossy commit to a foreign branch."""
126
129
        test_foreign.register_dummy_foreign_for_test(self)
127
130
        wt = self.make_branch_and_tree('.',
128
 
            format=test_foreign.DummyForeignVcsDirFormat())
 
131
                                       format=test_foreign.DummyForeignVcsDirFormat())
129
132
        b = wt.branch
130
 
        with open('hello', 'w') as f: f.write('hello world')
 
133
        with open('hello', 'w') as f:
 
134
            f.write('hello world')
131
135
        wt.add('hello')
132
136
        revid = wt.commit(message='add hello', lossy=True,
133
 
            timestamp=1302659388, timezone=0)
 
137
                          timestamp=1302659388, timezone=0)
134
138
        self.assertEqual(b'dummy-v1:1302659388-0-UNKNOWN', revid)
135
139
 
136
140
    def test_commit_bound_lossy_foreign(self):
137
141
        """Attempt a lossy commit to a bzr branch bound to a foreign branch."""
138
142
        test_foreign.register_dummy_foreign_for_test(self)
139
143
        foreign_branch = self.make_branch('foreign',
140
 
            format=test_foreign.DummyForeignVcsDirFormat())
 
144
                                          format=test_foreign.DummyForeignVcsDirFormat())
141
145
        wt = foreign_branch.create_checkout("local")
142
146
        b = wt.branch
143
 
        with open('local/hello', 'w') as f: f.write('hello world')
 
147
        with open('local/hello', 'w') as f:
 
148
            f.write('hello world')
144
149
        wt.add('hello')
145
150
        revid = wt.commit(message='add hello', lossy=True,
146
 
            timestamp=1302659388, timezone=0)
 
151
                          timestamp=1302659388, timezone=0)
147
152
        self.assertEqual(b'dummy-v1:1302659388-0-0', revid)
148
153
        self.assertEqual(b'dummy-v1:1302659388-0-0',
149
 
            foreign_branch.last_revision())
 
154
                         foreign_branch.last_revision())
150
155
        self.assertEqual(b'dummy-v1:1302659388-0-0',
151
 
            wt.branch.last_revision())
 
156
                         wt.branch.last_revision())
152
157
 
153
158
    def test_missing_commit(self):
154
159
        """Test a commit with a missing file"""
155
160
        wt = self.make_branch_and_tree('.')
156
161
        b = wt.branch
157
 
        with open('hello', 'w') as f: f.write('hello world')
 
162
        with open('hello', 'w') as f:
 
163
            f.write('hello world')
158
164
        wt.add(['hello'], [b'hello-id'])
159
165
        wt.commit(message='add hello')
160
166
 
181
187
        b = wt.branch
182
188
        self.build_tree(['annotate/', 'annotate/foo.py',
183
189
                         'olive/', 'olive/dialog.py'
184
 
                        ])
 
190
                         ])
185
191
        wt.add(['annotate', 'olive', 'annotate/foo.py', 'olive/dialog.py'])
186
192
        wt.commit(message='add files')
187
193
        wt.rename_one("olive/dialog.py", "aaa")
192
198
        """Commit refuses unless there are changes or it's forced."""
193
199
        wt = self.make_branch_and_tree('.')
194
200
        b = wt.branch
195
 
        with open('hello', 'w') as f: f.write('hello')
 
201
        with open('hello', 'w') as f:
 
202
            f.write('hello')
196
203
        wt.add(['hello'])
197
204
        wt.commit(message='add hello')
198
205
        self.assertEqual(b.revno(), 1)
218
225
        """Selective commit in tree with deletions"""
219
226
        wt = self.make_branch_and_tree('.')
220
227
        b = wt.branch
221
 
        with open('hello', 'w') as f: f.write('hello')
222
 
        with open('buongia', 'w') as f: f.write('buongia')
 
228
        with open('hello', 'w') as f:
 
229
            f.write('hello')
 
230
        with open('buongia', 'w') as f:
 
231
            f.write('buongia')
223
232
        wt.add(['hello', 'buongia'],
224
 
              [b'hello-id', b'buongia-id'])
 
233
               [b'hello-id', b'buongia-id'])
225
234
        wt.commit(message='add files',
226
 
                 rev_id=b'test@rev-1')
 
235
                  rev_id=b'test@rev-1')
227
236
 
228
237
        os.remove('hello')
229
 
        with open('buongia', 'w') as f: f.write('new text')
 
238
        with open('buongia', 'w') as f:
 
239
            f.write('new text')
230
240
        wt.commit(message='update text',
231
 
                 specific_files=['buongia'],
232
 
                 allow_pointless=False,
233
 
                 rev_id=b'test@rev-2')
 
241
                  specific_files=['buongia'],
 
242
                  allow_pointless=False,
 
243
                  rev_id=b'test@rev-2')
234
244
 
235
245
        wt.commit(message='remove hello',
236
 
                 specific_files=['hello'],
237
 
                 allow_pointless=False,
238
 
                 rev_id=b'test@rev-3')
 
246
                  specific_files=['hello'],
 
247
                  allow_pointless=False,
 
248
                  rev_id=b'test@rev-3')
239
249
 
240
250
        eq = self.assertEqual
241
251
        eq(b.revno(), 3)
262
272
        tree.commit(message='one', rev_id=b'test@rev-1', allow_pointless=False)
263
273
 
264
274
        tree.rename_one('hello', 'fruity')
265
 
        tree.commit(message='renamed', rev_id=b'test@rev-2', allow_pointless=False)
 
275
        tree.commit(message='renamed', rev_id=b'test@rev-2',
 
276
                    allow_pointless=False)
266
277
 
267
278
        eq = self.assertEqual
268
279
        tree1 = b.repository.revision_tree(b'test@rev-1')
317
328
        wt.lock_read()
318
329
        try:
319
330
            self.check_tree_shape(wt,
320
 
                                       ['a/', 'a/hello', 'a/b/'])
 
331
                                  ['a/', 'a/hello', 'a/b/'])
321
332
            self.check_tree_shape(b.repository.revision_tree(r3),
322
 
                                       ['a/', 'a/hello', 'a/b/'])
 
333
                                  ['a/', 'a/hello', 'a/b/'])
323
334
        finally:
324
335
            wt.unlock()
325
336
 
341
352
        """Commit with a removed file"""
342
353
        wt = self.make_branch_and_tree('.')
343
354
        b = wt.branch
344
 
        with open('hello', 'w') as f: f.write('hello world')
 
355
        with open('hello', 'w') as f:
 
356
            f.write('hello world')
345
357
        wt.add(['hello'], [b'hello-id'])
346
358
        wt.commit(message='add hello')
347
359
        wt.remove('hello')
356
368
        b = wt.branch
357
369
        rev_ids = []
358
370
        for i in range(4):
359
 
            with open('hello', 'w') as f: f.write((str(i) * 4) + '\n')
 
371
            with open('hello', 'w') as f:
 
372
                f.write((str(i) * 4) + '\n')
360
373
            if i == 0:
361
374
                wt.add(['hello'], [b'hello-id'])
362
 
            rev_id = b'test@rev-%d' % (i+1)
 
375
            rev_id = b'test@rev-%d' % (i + 1)
363
376
            rev_ids.append(rev_id)
364
 
            wt.commit(message='rev %d' % (i+1),
365
 
                     rev_id=rev_id)
 
377
            wt.commit(message='rev %d' % (i + 1),
 
378
                      rev_id=rev_id)
366
379
        for i in range(4):
367
 
            self.assertThat(rev_ids[:i+1],
368
 
                MatchesAncestry(b.repository, rev_ids[i]))
 
380
            self.assertThat(rev_ids[:i + 1],
 
381
                            MatchesAncestry(b.repository, rev_ids[i]))
369
382
 
370
383
    def test_commit_new_subdir_child_selective(self):
371
384
        wt = self.make_branch_and_tree('.')
372
385
        b = wt.branch
373
386
        self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
374
387
        wt.add(['dir', 'dir/file1', 'dir/file2'],
375
 
              [b'dirid', b'file1id', b'file2id'])
 
388
               [b'dirid', b'file1id', b'file2id'])
376
389
        wt.commit('dir/file1', specific_files=['dir/file1'], rev_id=b'1')
377
390
        inv = b.repository.get_inventory(b'1')
378
391
        self.assertEqual(b'1', inv.get_entry(b'dirid').revision)
385
398
        from ..errors import StrictCommitFailed
386
399
        wt = self.make_branch_and_tree('.')
387
400
        b = wt.branch
388
 
        with open('hello', 'w') as f: f.write('hello world')
 
401
        with open('hello', 'w') as f:
 
402
            f.write('hello world')
389
403
        wt.add('hello')
390
 
        with open('goodbye', 'w') as f: f.write('goodbye cruel world!')
 
404
        with open('goodbye', 'w') as f:
 
405
            f.write('goodbye cruel world!')
391
406
        self.assertRaises(StrictCommitFailed, wt.commit,
392
 
            message='add hello but not goodbye', strict=True)
 
407
                          message='add hello but not goodbye', strict=True)
393
408
 
394
409
    def test_strict_commit_without_unknowns(self):
395
410
        """Try and commit with no unknown files and strict = True,
396
411
        should work."""
397
412
        wt = self.make_branch_and_tree('.')
398
413
        b = wt.branch
399
 
        with open('hello', 'w') as f: f.write('hello world')
 
414
        with open('hello', 'w') as f:
 
415
            f.write('hello world')
400
416
        wt.add('hello')
401
417
        wt.commit(message='add hello', strict=True)
402
418
 
404
420
        """Try and commit with unknown files and strict = False, should work."""
405
421
        wt = self.make_branch_and_tree('.')
406
422
        b = wt.branch
407
 
        with open('hello', 'w') as f: f.write('hello world')
 
423
        with open('hello', 'w') as f:
 
424
            f.write('hello world')
408
425
        wt.add('hello')
409
 
        with open('goodbye', 'w') as f: f.write('goodbye cruel world!')
 
426
        with open('goodbye', 'w') as f:
 
427
            f.write('goodbye cruel world!')
410
428
        wt.commit(message='add hello but not goodbye', strict=False)
411
429
 
412
430
    def test_nonstrict_commit_without_unknowns(self):
414
432
        should work."""
415
433
        wt = self.make_branch_and_tree('.')
416
434
        b = wt.branch
417
 
        with open('hello', 'w') as f: f.write('hello world')
 
435
        with open('hello', 'w') as f:
 
436
            f.write('hello world')
418
437
        wt.add('hello')
419
438
        wt.commit(message='add hello', strict=False)
420
439
 
427
446
        wt.commit("base", allow_pointless=True, rev_id=b'A')
428
447
        self.assertFalse(branch.repository.has_signature_for_revision_id(b'A'))
429
448
        try:
430
 
            from ..testament import Testament
 
449
            from ..bzr.testament import Testament
431
450
            # monkey patch gpg signing mechanism
432
451
            breezy.gpg.GPGStrategy = breezy.gpg.LoopbackGPGStrategy
433
452
            conf = config.MemoryStack(b'''
436
455
            commit.Commit(config_stack=conf).commit(
437
456
                message="base", allow_pointless=True, rev_id=b'B',
438
457
                working_tree=wt)
 
458
 
439
459
            def sign(text):
440
460
                return breezy.gpg.LoopbackGPGStrategy(None).sign(
441
 
                        text, breezy.gpg.MODE_CLEAR)
 
461
                    text, breezy.gpg.MODE_CLEAR)
442
462
            self.assertEqual(sign(Testament.from_revision(branch.repository,
443
463
                                                          b'B').as_short_text()),
444
464
                             branch.repository.get_signature_text(b'B'))
476
496
        wt = self.make_branch_and_tree('.')
477
497
        branch = wt.branch
478
498
        calls = []
 
499
 
479
500
        def called(branch, rev_id):
480
501
            calls.append('called')
481
502
        breezy.ahook = called
482
503
        try:
483
504
            conf = config.MemoryStack(b'post_commit=breezy.ahook breezy.ahook')
484
505
            commit.Commit(config_stack=conf).commit(
485
 
                message = "base", allow_pointless=True, rev_id=b'A',
486
 
                working_tree = wt)
 
506
                message="base", allow_pointless=True, rev_id=b'A',
 
507
                working_tree=wt)
487
508
            self.assertEqual(['called', 'called'], calls)
488
509
        finally:
489
510
            del breezy.ahook
496
517
        self.assertEqual(wt.branch.revno(), 1)
497
518
        self.assertEqual({},
498
519
                         wt.branch.repository.get_revision(
499
 
                            wt.branch.last_revision()).properties)
 
520
            wt.branch.last_revision()).properties)
500
521
 
501
522
    def test_safe_master_lock(self):
502
523
        os.mkdir('master')
520
541
        bound_tree = self.make_branch_and_tree('bound')
521
542
        bound_tree.branch.bind(master_branch)
522
543
 
523
 
        self.build_tree_contents([('bound/content_file', b'initial contents\n')])
 
544
        self.build_tree_contents(
 
545
            [('bound/content_file', b'initial contents\n')])
524
546
        bound_tree.add(['content_file'])
525
547
        bound_tree.commit(message='woo!')
526
548
 
530
552
        # do a commit to the other branch changing the content file so
531
553
        # that our commit after merging will have a merged revision in the
532
554
        # content file history.
533
 
        self.build_tree_contents([('other/content_file', b'change in other\n')])
 
555
        self.build_tree_contents(
 
556
            [('other/content_file', b'change in other\n')])
534
557
        other_tree.commit('change in other')
535
558
 
536
559
        # do a merge into the bound branch from other, and then change the
537
560
        # content file locally to force a new revision (rather than using the
538
561
        # revision from other). This forces extra processing in commit.
539
562
        bound_tree.merge_from_branch(other_tree.branch)
540
 
        self.build_tree_contents([('bound/content_file', b'change in bound\n')])
 
563
        self.build_tree_contents(
 
564
            [('bound/content_file', b'change in bound\n')])
541
565
 
542
566
        # before #34959 was fixed, this failed with 'revision not present in
543
567
        # weave' when trying to implicitly push from the bound branch to the master
579
603
            other_tree.rename_one('dirtorename', 'renameddir')
580
604
            other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
581
605
            other_tree.rename_one('filetorename', 'renamedfile')
582
 
            other_tree.rename_one('filetoreparent', 'renameddir/reparentedfile')
 
606
            other_tree.rename_one(
 
607
                'filetoreparent', 'renameddir/reparentedfile')
583
608
            other_tree.remove(['dirtoremove', 'filetoremove'])
584
609
            self.build_tree_contents([
585
610
                ('other/newdir/', ),
777
802
        cb = self.Callback(u'commit 2', self)
778
803
        repository = tree.branch.repository
779
804
        # simulate network failure
 
805
 
780
806
        def raise_(self, arg, arg2, arg3=None, arg4=None):
781
807
            raise errors.NoSuchFile('foo')
782
808
        repository.add_inventory = raise_
793
819
        self.build_tree(['foo/bar', 'foo/baz'])
794
820
        tree.add(['bar', 'baz'])
795
821
        err = self.assertRaises(CannotCommitSelectedFileMerge,
796
 
            tree.commit, 'commit 2', specific_files=['bar', 'baz'])
 
822
                                tree.commit, 'commit 2', specific_files=['bar', 'baz'])
797
823
        self.assertEqual(['bar', 'baz'], err.files)
798
824
        self.assertEqual('Selected-file commit of merges is not supported'
799
825
                         ' yet: files bar, baz', str(err))
843
869
    def test_multiple_authors(self):
844
870
        tree = self.make_branch_and_tree('foo')
845
871
        rev_id = tree.commit('commit 1',
846
 
                authors=['John Doe <jdoe@example.com>',
847
 
                         'Jane Rey <jrey@example.com>'])
 
872
                             authors=['John Doe <jdoe@example.com>',
 
873
                                      'Jane Rey <jrey@example.com>'])
848
874
        rev = tree.branch.repository.get_revision(rev_id)
849
875
        self.assertEqual('John Doe <jdoe@example.com>\n'
850
 
                'Jane Rey <jrey@example.com>', rev.properties['authors'])
 
876
                         'Jane Rey <jrey@example.com>', rev.properties['authors'])
851
877
        self.assertFalse('author' in rev.properties)
852
878
 
853
879
    def test_author_with_newline_rejected(self):
854
880
        tree = self.make_branch_and_tree('foo')
855
881
        self.assertRaises(AssertionError, tree.commit, 'commit 1',
856
 
                authors=['John\nDoe <jdoe@example.com>'])
 
882
                          authors=['John\nDoe <jdoe@example.com>'])
857
883
 
858
884
    def test_commit_with_checkout_and_branch_sharing_repo(self):
859
885
        repo = self.make_repository('repo', shared=True)
871
897
            ('fid', (None, 'newpath'),
872
898
             0, (False, False), ('pid', 'pid'), ('newpath', 'newpath'),
873
899
             ('file', 'file'), (True, True))]
874
 
        self.assertEqual(changes, list(filter_excluded(changes, ['otherpath'])))
 
900
        self.assertEqual(changes, list(
 
901
            filter_excluded(changes, ['otherpath'])))
875
902
 
876
903
    def test_add_file_excluded(self):
877
904
        changes = [