/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-03-25 11:54:30 UTC
  • mfrom: (6855.4.10 more-bees)
  • Revision ID: breezy.the.bot@gmail.com-20180325115430-75xnlbrmzjoomd83
Add more bees. In particular:

* for file ids
* for revision ids
* for file contents in build_tree_contents()

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
        b = wt.branch
117
117
        with open('hello', 'w') as f: f.write('hello world')
118
118
        wt.add('hello')
119
 
        revid = wt.commit(message='add hello', rev_id='revid', lossy=True)
 
119
        revid = wt.commit(message='add hello', rev_id=b'revid', lossy=True)
120
120
        self.assertEqual('revid', revid)
121
121
 
122
122
    def test_commit_lossy_foreign(self):
153
153
        wt = self.make_branch_and_tree('.')
154
154
        b = wt.branch
155
155
        with open('hello', 'w') as f: f.write('hello world')
156
 
        wt.add(['hello'], ['hello-id'])
 
156
        wt.add(['hello'], [b'hello-id'])
157
157
        wt.commit(message='add hello')
158
158
 
159
159
        os.remove('hello')
160
160
        reporter = CapturingReporter()
161
 
        wt.commit('removed hello', rev_id='rev2', reporter=reporter)
 
161
        wt.commit('removed hello', rev_id=b'rev2', reporter=reporter)
162
162
        self.assertEqual(
163
163
            [('missing', u'hello'), ('deleted', u'hello')],
164
164
            reporter.calls)
165
165
 
166
166
        tree = b.repository.revision_tree('rev2')
167
 
        self.assertFalse(tree.has_id('hello-id'))
 
167
        self.assertFalse(tree.has_id(b'hello-id'))
168
168
 
169
169
    def test_partial_commit_move(self):
170
170
        """Test a partial commit where a file was renamed but not committed.
183
183
        wt.add(['annotate', 'olive', 'annotate/foo.py', 'olive/dialog.py'])
184
184
        wt.commit(message='add files')
185
185
        wt.rename_one("olive/dialog.py", "aaa")
186
 
        self.build_tree_contents([('annotate/foo.py', 'modified\n')])
 
186
        self.build_tree_contents([('annotate/foo.py', b'modified\n')])
187
187
        wt.commit('renamed hello', specific_files=["annotate"])
188
188
 
189
189
    def test_pointless_commit(self):
221
221
        wt.add(['hello', 'buongia'],
222
222
              ['hello-id', 'buongia-id'])
223
223
        wt.commit(message='add files',
224
 
                 rev_id='test@rev-1')
 
224
                 rev_id=b'test@rev-1')
225
225
 
226
226
        os.remove('hello')
227
227
        with open('buongia', 'w') as f: f.write('new text')
228
228
        wt.commit(message='update text',
229
229
                 specific_files=['buongia'],
230
230
                 allow_pointless=False,
231
 
                 rev_id='test@rev-2')
 
231
                 rev_id=b'test@rev-2')
232
232
 
233
233
        wt.commit(message='remove hello',
234
234
                 specific_files=['hello'],
235
235
                 allow_pointless=False,
236
 
                 rev_id='test@rev-3')
 
236
                 rev_id=b'test@rev-3')
237
237
 
238
238
        eq = self.assertEqual
239
239
        eq(b.revno(), 3)
256
256
        tree = self.make_branch_and_tree('.')
257
257
        b = tree.branch
258
258
        self.build_tree(['hello'], line_endings='binary')
259
 
        tree.add(['hello'], ['hello-id'])
260
 
        tree.commit(message='one', rev_id='test@rev-1', allow_pointless=False)
 
259
        tree.add(['hello'], [b'hello-id'])
 
260
        tree.commit(message='one', rev_id=b'test@rev-1', allow_pointless=False)
261
261
 
262
262
        tree.rename_one('hello', 'fruity')
263
 
        tree.commit(message='renamed', rev_id='test@rev-2', allow_pointless=False)
 
263
        tree.commit(message='renamed', rev_id=b'test@rev-2', allow_pointless=False)
264
264
 
265
265
        eq = self.assertEqual
266
 
        tree1 = b.repository.revision_tree('test@rev-1')
 
266
        tree1 = b.repository.revision_tree(b'test@rev-1')
267
267
        tree1.lock_read()
268
268
        self.addCleanup(tree1.unlock)
269
 
        eq(tree1.id2path('hello-id'), 'hello')
 
269
        eq(tree1.id2path(b'hello-id'), 'hello')
270
270
        eq(tree1.get_file_text('hello'), 'contents of hello\n')
271
271
        self.assertFalse(tree1.has_filename('fruity'))
272
272
        self.check_tree_shape(tree1, ['hello'])
273
 
        eq(tree1.get_file_revision('hello'), 'test@rev-1')
 
273
        eq(tree1.get_file_revision('hello'), b'test@rev-1')
274
274
 
275
 
        tree2 = b.repository.revision_tree('test@rev-2')
 
275
        tree2 = b.repository.revision_tree(b'test@rev-2')
276
276
        tree2.lock_read()
277
277
        self.addCleanup(tree2.unlock)
278
 
        eq(tree2.id2path('hello-id'), 'fruity')
 
278
        eq(tree2.id2path(b'hello-id'), 'fruity')
279
279
        eq(tree2.get_file_text('fruity'), 'contents of hello\n')
280
280
        self.check_tree_shape(tree2, ['fruity'])
281
 
        eq(tree2.get_file_revision('fruity'), 'test@rev-2')
 
281
        eq(tree2.get_file_revision('fruity'), b'test@rev-2')
282
282
 
283
283
    def test_reused_rev_id(self):
284
284
        """Test that a revision id cannot be reused in a branch"""
285
285
        wt = self.make_branch_and_tree('.')
286
286
        b = wt.branch
287
 
        wt.commit('initial', rev_id='test@rev-1', allow_pointless=True)
 
287
        wt.commit('initial', rev_id=b'test@rev-1', allow_pointless=True)
288
288
        self.assertRaises(Exception,
289
289
                          wt.commit,
290
290
                          message='reused id',
291
 
                          rev_id='test@rev-1',
 
291
                          rev_id=b'test@rev-1',
292
292
                          allow_pointless=True)
293
293
 
294
294
    def test_commit_move(self):
296
296
        eq = self.assertEqual
297
297
        wt = self.make_branch_and_tree('.')
298
298
        b = wt.branch
299
 
        r1 = 'test@rev-1'
 
299
        r1 = b'test@rev-1'
300
300
        self.build_tree(['hello', 'a/', 'b/'])
301
 
        wt.add(['hello', 'a', 'b'], ['hello-id', 'a-id', 'b-id'])
 
301
        wt.add(['hello', 'a', 'b'], [b'hello-id', b'a-id', b'b-id'])
302
302
        wt.commit('initial', rev_id=r1, allow_pointless=False)
303
303
        wt.move(['hello'], 'a')
304
 
        r2 = 'test@rev-2'
 
304
        r2 = b'test@rev-2'
305
305
        wt.commit('two', rev_id=r2, allow_pointless=False)
306
306
        wt.lock_read()
307
307
        try:
310
310
            wt.unlock()
311
311
 
312
312
        wt.move(['b'], 'a')
313
 
        r3 = 'test@rev-3'
 
313
        r3 = b'test@rev-3'
314
314
        wt.commit('three', rev_id=r3, allow_pointless=False)
315
315
        wt.lock_read()
316
316
        try:
322
322
            wt.unlock()
323
323
 
324
324
        wt.move(['a/hello'], 'a/b')
325
 
        r4 = 'test@rev-4'
 
325
        r4 = b'test@rev-4'
326
326
        wt.commit('four', rev_id=r4, allow_pointless=False)
327
327
        wt.lock_read()
328
328
        try:
331
331
            wt.unlock()
332
332
 
333
333
        inv = b.repository.get_inventory(r4)
334
 
        eq(inv.get_entry('hello-id').revision, r4)
335
 
        eq(inv.get_entry('a-id').revision, r1)
336
 
        eq(inv.get_entry('b-id').revision, r3)
 
334
        eq(inv.get_entry(b'hello-id').revision, r4)
 
335
        eq(inv.get_entry(b'a-id').revision, r1)
 
336
        eq(inv.get_entry(b'b-id').revision, r3)
337
337
 
338
338
    def test_removed_commit(self):
339
339
        """Commit with a removed file"""
340
340
        wt = self.make_branch_and_tree('.')
341
341
        b = wt.branch
342
342
        with open('hello', 'w') as f: f.write('hello world')
343
 
        wt.add(['hello'], ['hello-id'])
 
343
        wt.add(['hello'], [b'hello-id'])
344
344
        wt.commit(message='add hello')
345
345
        wt.remove('hello')
346
 
        wt.commit('removed hello', rev_id='rev2')
 
346
        wt.commit('removed hello', rev_id=b'rev2')
347
347
 
348
348
        tree = b.repository.revision_tree('rev2')
349
349
        self.assertFalse(tree.has_id('hello-id'))
356
356
        for i in range(4):
357
357
            with open('hello', 'w') as f: f.write((str(i) * 4) + '\n')
358
358
            if i == 0:
359
 
                wt.add(['hello'], ['hello-id'])
 
359
                wt.add(['hello'], [b'hello-id'])
360
360
            rev_id = 'test@rev-%d' % (i+1)
361
361
            rev_ids.append(rev_id)
362
362
            wt.commit(message='rev %d' % (i+1),
371
371
        self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
372
372
        wt.add(['dir', 'dir/file1', 'dir/file2'],
373
373
              ['dirid', 'file1id', 'file2id'])
374
 
        wt.commit('dir/file1', specific_files=['dir/file1'], rev_id='1')
 
374
        wt.commit('dir/file1', specific_files=['dir/file1'], rev_id=b'1')
375
375
        inv = b.repository.get_inventory('1')
376
376
        self.assertEqual('1', inv.get_entry('dirid').revision)
377
377
        self.assertEqual('1', inv.get_entry('file1id').revision)
422
422
        oldstrategy = breezy.gpg.GPGStrategy
423
423
        wt = self.make_branch_and_tree('.')
424
424
        branch = wt.branch
425
 
        wt.commit("base", allow_pointless=True, rev_id='A')
 
425
        wt.commit("base", allow_pointless=True, rev_id=b'A')
426
426
        self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
427
427
        try:
428
428
            from ..testament import Testament
432
432
create_signatures=always
433
433
''')
434
434
            commit.Commit(config_stack=conf).commit(
435
 
                message="base", allow_pointless=True, rev_id='B',
 
435
                message="base", allow_pointless=True, rev_id=b'B',
436
436
                working_tree=wt)
437
437
            def sign(text):
438
438
                return breezy.gpg.LoopbackGPGStrategy(None).sign(
449
449
        oldstrategy = breezy.gpg.GPGStrategy
450
450
        wt = self.make_branch_and_tree('.')
451
451
        branch = wt.branch
452
 
        wt.commit("base", allow_pointless=True, rev_id='A')
 
452
        wt.commit("base", allow_pointless=True, rev_id=b'A')
453
453
        self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
454
454
        try:
455
455
            # monkey patch gpg signing mechanism
461
461
                              commit.Commit(config_stack=conf).commit,
462
462
                              message="base",
463
463
                              allow_pointless=True,
464
 
                              rev_id='B',
 
464
                              rev_id=b'B',
465
465
                              working_tree=wt)
466
466
            branch = Branch.open(self.get_url('.'))
467
467
            self.assertEqual(branch.last_revision(), 'A')
480
480
        try:
481
481
            conf = config.MemoryStack('post_commit=breezy.ahook breezy.ahook')
482
482
            commit.Commit(config_stack=conf).commit(
483
 
                message = "base", allow_pointless=True, rev_id='A',
 
483
                message = "base", allow_pointless=True, rev_id=b'A',
484
484
                working_tree = wt)
485
485
            self.assertEqual(['called', 'called'], calls)
486
486
        finally:
518
518
        bound_tree = self.make_branch_and_tree('bound')
519
519
        bound_tree.branch.bind(master_branch)
520
520
 
521
 
        self.build_tree_contents([('bound/content_file', 'initial contents\n')])
 
521
        self.build_tree_contents([('bound/content_file', b'initial contents\n')])
522
522
        bound_tree.add(['content_file'])
523
523
        bound_tree.commit(message='woo!')
524
524
 
528
528
        # do a commit to the other branch changing the content file so
529
529
        # that our commit after merging will have a merged revision in the
530
530
        # content file history.
531
 
        self.build_tree_contents([('other/content_file', 'change in other\n')])
 
531
        self.build_tree_contents([('other/content_file', b'change in other\n')])
532
532
        other_tree.commit('change in other')
533
533
 
534
534
        # do a merge into the bound branch from other, and then change the
535
535
        # content file locally to force a new revision (rather than using the
536
536
        # revision from other). This forces extra processing in commit.
537
537
        bound_tree.merge_from_branch(other_tree.branch)
538
 
        self.build_tree_contents([('bound/content_file', 'change in bound\n')])
 
538
        self.build_tree_contents([('bound/content_file', b'change in bound\n')])
539
539
 
540
540
        # before #34959 was fixed, this failed with 'revision not present in
541
541
        # weave' when trying to implicitly push from the bound branch to the master
581
581
            other_tree.remove(['dirtoremove', 'filetoremove'])
582
582
            self.build_tree_contents([
583
583
                ('other/newdir/', ),
584
 
                ('other/filetomodify', 'new content'),
585
 
                ('other/newfile', 'new file content')])
 
584
                ('other/filetomodify', b'new content'),
 
585
                ('other/newfile', b'new file content')])
586
586
            other_tree.add('newfile')
587
587
            other_tree.add('newdir/')
588
588
            other_tree.commit('modify all sample files and dirs.')
626
626
        self.build_tree(['a'])
627
627
        tree.add('a')
628
628
        tree.commit('added a', timestamp=1153248633.4186721, timezone=0,
629
 
                    rev_id='a1')
 
629
                    rev_id=b'a1')
630
630
 
631
631
        rev = tree.branch.repository.get_revision('a1')
632
632
        self.assertEqual(1153248633.419, rev.timestamp)
636
636
        tree = self.make_branch_and_tree('.')
637
637
        self.build_tree(['a'])
638
638
        tree.add('a')
639
 
        tree.commit('added a', rev_id='a1')
 
639
        tree.commit('added a', rev_id=b'a1')
640
640
 
641
641
        rev = tree.branch.repository.get_revision('a1')
642
642
        timestamp = rev.timestamp
655
655
        self.requireFeature(SymlinkFeature)
656
656
        tree = self.make_branch_and_tree('.')
657
657
        os.symlink('target', 'name')
658
 
        tree.add('name', 'a-file-id')
 
658
        tree.add('name', b'a-file-id')
659
659
        tree.commit('Added a symlink')
660
660
        self.assertBasisTreeKind('symlink', tree, 'name')
661
661
 
829
829
        # make_branch_and_tree ignores shared repos
830
830
        branch = controldir.ControlDir.create_branch_convenience('repo/branch')
831
831
        tree2 = branch.create_checkout('repo/tree2')
832
 
        tree2.commit('message', rev_id='rev1')
 
832
        tree2.commit('message', rev_id=b'rev1')
833
833
        self.assertTrue(tree2.branch.repository.has_revision('rev1'))
834
834
 
835
835