/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: 2018-02-18 15:21:06 UTC
  • mto: This revision was merged to the branch mainline in revision 6928.
  • Revision ID: jelmer@jelmer.uk-20180218152106-m8bmfurzlspweyu4
Yet more bees.

Show diffs side-by-side

added added

removed removed

Lines of Context:
117
117
        b = wt.branch
118
118
        with open('hello', 'w') as f: f.write('hello world')
119
119
        wt.add('hello')
120
 
        revid = wt.commit(message='add hello', rev_id='revid', lossy=True)
 
120
        revid = wt.commit(message='add hello', rev_id=b'revid', lossy=True)
121
121
        self.assertEqual('revid', revid)
122
122
 
123
123
    def test_commit_lossy_foreign(self):
154
154
        wt = self.make_branch_and_tree('.')
155
155
        b = wt.branch
156
156
        with open('hello', 'w') as f: f.write('hello world')
157
 
        wt.add(['hello'], ['hello-id'])
 
157
        wt.add(['hello'], [b'hello-id'])
158
158
        wt.commit(message='add hello')
159
159
 
160
160
        os.remove('hello')
161
161
        reporter = CapturingReporter()
162
 
        wt.commit('removed hello', rev_id='rev2', reporter=reporter)
 
162
        wt.commit('removed hello', rev_id=b'rev2', reporter=reporter)
163
163
        self.assertEqual(
164
164
            [('missing', u'hello'), ('deleted', u'hello')],
165
165
            reporter.calls)
166
166
 
167
167
        tree = b.repository.revision_tree('rev2')
168
 
        self.assertFalse(tree.has_id('hello-id'))
 
168
        self.assertFalse(tree.has_id(b'hello-id'))
169
169
 
170
170
    def test_partial_commit_move(self):
171
171
        """Test a partial commit where a file was renamed but not committed.
184
184
        wt.add(['annotate', 'olive', 'annotate/foo.py', 'olive/dialog.py'])
185
185
        wt.commit(message='add files')
186
186
        wt.rename_one("olive/dialog.py", "aaa")
187
 
        self.build_tree_contents([('annotate/foo.py', 'modified\n')])
 
187
        self.build_tree_contents([('annotate/foo.py', b'modified\n')])
188
188
        wt.commit('renamed hello', specific_files=["annotate"])
189
189
 
190
190
    def test_pointless_commit(self):
222
222
        wt.add(['hello', 'buongia'],
223
223
              ['hello-id', 'buongia-id'])
224
224
        wt.commit(message='add files',
225
 
                 rev_id='test@rev-1')
 
225
                 rev_id=b'test@rev-1')
226
226
 
227
227
        os.remove('hello')
228
228
        with open('buongia', 'w') as f: f.write('new text')
229
229
        wt.commit(message='update text',
230
230
                 specific_files=['buongia'],
231
231
                 allow_pointless=False,
232
 
                 rev_id='test@rev-2')
 
232
                 rev_id=b'test@rev-2')
233
233
 
234
234
        wt.commit(message='remove hello',
235
235
                 specific_files=['hello'],
236
236
                 allow_pointless=False,
237
 
                 rev_id='test@rev-3')
 
237
                 rev_id=b'test@rev-3')
238
238
 
239
239
        eq = self.assertEqual
240
240
        eq(b.revno(), 3)
257
257
        tree = self.make_branch_and_tree('.')
258
258
        b = tree.branch
259
259
        self.build_tree(['hello'], line_endings='binary')
260
 
        tree.add(['hello'], ['hello-id'])
261
 
        tree.commit(message='one', rev_id='test@rev-1', allow_pointless=False)
 
260
        tree.add(['hello'], [b'hello-id'])
 
261
        tree.commit(message='one', rev_id=b'test@rev-1', allow_pointless=False)
262
262
 
263
263
        tree.rename_one('hello', 'fruity')
264
 
        tree.commit(message='renamed', rev_id='test@rev-2', allow_pointless=False)
 
264
        tree.commit(message='renamed', rev_id=b'test@rev-2', allow_pointless=False)
265
265
 
266
266
        eq = self.assertEqual
267
 
        tree1 = b.repository.revision_tree('test@rev-1')
 
267
        tree1 = b.repository.revision_tree(b'test@rev-1')
268
268
        tree1.lock_read()
269
269
        self.addCleanup(tree1.unlock)
270
 
        eq(tree1.id2path('hello-id'), 'hello')
 
270
        eq(tree1.id2path(b'hello-id'), 'hello')
271
271
        eq(tree1.get_file_text('hello'), 'contents of hello\n')
272
272
        self.assertFalse(tree1.has_filename('fruity'))
273
273
        self.check_tree_shape(tree1, ['hello'])
274
 
        eq(tree1.get_file_revision('hello'), 'test@rev-1')
 
274
        eq(tree1.get_file_revision('hello'), b'test@rev-1')
275
275
 
276
 
        tree2 = b.repository.revision_tree('test@rev-2')
 
276
        tree2 = b.repository.revision_tree(b'test@rev-2')
277
277
        tree2.lock_read()
278
278
        self.addCleanup(tree2.unlock)
279
 
        eq(tree2.id2path('hello-id'), 'fruity')
 
279
        eq(tree2.id2path(b'hello-id'), 'fruity')
280
280
        eq(tree2.get_file_text('fruity'), 'contents of hello\n')
281
281
        self.check_tree_shape(tree2, ['fruity'])
282
 
        eq(tree2.get_file_revision('fruity'), 'test@rev-2')
 
282
        eq(tree2.get_file_revision('fruity'), b'test@rev-2')
283
283
 
284
284
    def test_reused_rev_id(self):
285
285
        """Test that a revision id cannot be reused in a branch"""
286
286
        wt = self.make_branch_and_tree('.')
287
287
        b = wt.branch
288
 
        wt.commit('initial', rev_id='test@rev-1', allow_pointless=True)
 
288
        wt.commit('initial', rev_id=b'test@rev-1', allow_pointless=True)
289
289
        self.assertRaises(Exception,
290
290
                          wt.commit,
291
291
                          message='reused id',
292
 
                          rev_id='test@rev-1',
 
292
                          rev_id=b'test@rev-1',
293
293
                          allow_pointless=True)
294
294
 
295
295
    def test_commit_move(self):
297
297
        eq = self.assertEqual
298
298
        wt = self.make_branch_and_tree('.')
299
299
        b = wt.branch
300
 
        r1 = 'test@rev-1'
 
300
        r1 = b'test@rev-1'
301
301
        self.build_tree(['hello', 'a/', 'b/'])
302
 
        wt.add(['hello', 'a', 'b'], ['hello-id', 'a-id', 'b-id'])
 
302
        wt.add(['hello', 'a', 'b'], [b'hello-id', b'a-id', b'b-id'])
303
303
        wt.commit('initial', rev_id=r1, allow_pointless=False)
304
304
        wt.move(['hello'], 'a')
305
 
        r2 = 'test@rev-2'
 
305
        r2 = b'test@rev-2'
306
306
        wt.commit('two', rev_id=r2, allow_pointless=False)
307
307
        wt.lock_read()
308
308
        try:
311
311
            wt.unlock()
312
312
 
313
313
        wt.move(['b'], 'a')
314
 
        r3 = 'test@rev-3'
 
314
        r3 = b'test@rev-3'
315
315
        wt.commit('three', rev_id=r3, allow_pointless=False)
316
316
        wt.lock_read()
317
317
        try:
323
323
            wt.unlock()
324
324
 
325
325
        wt.move(['a/hello'], 'a/b')
326
 
        r4 = 'test@rev-4'
 
326
        r4 = b'test@rev-4'
327
327
        wt.commit('four', rev_id=r4, allow_pointless=False)
328
328
        wt.lock_read()
329
329
        try:
332
332
            wt.unlock()
333
333
 
334
334
        inv = b.repository.get_inventory(r4)
335
 
        eq(inv['hello-id'].revision, r4)
336
 
        eq(inv['a-id'].revision, r1)
337
 
        eq(inv['b-id'].revision, r3)
 
335
        eq(inv[b'hello-id'].revision, r4)
 
336
        eq(inv[b'a-id'].revision, r1)
 
337
        eq(inv[b'b-id'].revision, r3)
338
338
 
339
339
    def test_removed_commit(self):
340
340
        """Commit with a removed file"""
341
341
        wt = self.make_branch_and_tree('.')
342
342
        b = wt.branch
343
343
        with open('hello', 'w') as f: f.write('hello world')
344
 
        wt.add(['hello'], ['hello-id'])
 
344
        wt.add(['hello'], [b'hello-id'])
345
345
        wt.commit(message='add hello')
346
346
        wt.remove('hello')
347
 
        wt.commit('removed hello', rev_id='rev2')
 
347
        wt.commit('removed hello', rev_id=b'rev2')
348
348
 
349
349
        tree = b.repository.revision_tree('rev2')
350
350
        self.assertFalse(tree.has_id('hello-id'))
357
357
        for i in range(4):
358
358
            with open('hello', 'w') as f: f.write((str(i) * 4) + '\n')
359
359
            if i == 0:
360
 
                wt.add(['hello'], ['hello-id'])
 
360
                wt.add(['hello'], [b'hello-id'])
361
361
            rev_id = 'test@rev-%d' % (i+1)
362
362
            rev_ids.append(rev_id)
363
363
            wt.commit(message='rev %d' % (i+1),
372
372
        self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
373
373
        wt.add(['dir', 'dir/file1', 'dir/file2'],
374
374
              ['dirid', 'file1id', 'file2id'])
375
 
        wt.commit('dir/file1', specific_files=['dir/file1'], rev_id='1')
 
375
        wt.commit('dir/file1', specific_files=['dir/file1'], rev_id=b'1')
376
376
        inv = b.repository.get_inventory('1')
377
377
        self.assertEqual('1', inv['dirid'].revision)
378
378
        self.assertEqual('1', inv['file1id'].revision)
423
423
        oldstrategy = breezy.gpg.GPGStrategy
424
424
        wt = self.make_branch_and_tree('.')
425
425
        branch = wt.branch
426
 
        wt.commit("base", allow_pointless=True, rev_id='A')
 
426
        wt.commit("base", allow_pointless=True, rev_id=b'A')
427
427
        self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
428
428
        try:
429
429
            from ..testament import Testament
433
433
create_signatures=always
434
434
''')
435
435
            commit.Commit(config_stack=conf).commit(
436
 
                message="base", allow_pointless=True, rev_id='B',
 
436
                message="base", allow_pointless=True, rev_id=b'B',
437
437
                working_tree=wt)
438
438
            def sign(text):
439
439
                return breezy.gpg.LoopbackGPGStrategy(None).sign(text)
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.')
629
629
        self.build_tree(['a'])
630
630
        tree.add('a')
631
631
        tree.commit('added a', timestamp=1153248633.4186721, timezone=0,
632
 
                    rev_id='a1')
 
632
                    rev_id=b'a1')
633
633
 
634
634
        rev = tree.branch.repository.get_revision('a1')
635
635
        self.assertEqual(1153248633.419, rev.timestamp)
639
639
        tree = self.make_branch_and_tree('.')
640
640
        self.build_tree(['a'])
641
641
        tree.add('a')
642
 
        tree.commit('added a', rev_id='a1')
 
642
        tree.commit('added a', rev_id=b'a1')
643
643
 
644
644
        rev = tree.branch.repository.get_revision('a1')
645
645
        timestamp = rev.timestamp
658
658
        self.requireFeature(SymlinkFeature)
659
659
        tree = self.make_branch_and_tree('.')
660
660
        os.symlink('target', 'name')
661
 
        tree.add('name', 'a-file-id')
 
661
        tree.add('name', b'a-file-id')
662
662
        tree.commit('Added a symlink')
663
663
        self.assertBasisTreeKind('symlink', tree, 'name')
664
664
 
832
832
        # make_branch_and_tree ignores shared repos
833
833
        branch = controldir.ControlDir.create_branch_convenience('repo/branch')
834
834
        tree2 = branch.create_checkout('repo/tree2')
835
 
        tree2.commit('message', rev_id='rev1')
 
835
        tree2.commit('message', rev_id=b'rev1')
836
836
        self.assertTrue(tree2.branch.repository.has_revision('rev1'))
837
837
 
838
838