/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-11-06 01:18:08 UTC
  • mfrom: (7143 work)
  • mto: This revision was merged to the branch mainline in revision 7151.
  • Revision ID: jelmer@jelmer.uk-20181106011808-y870f4vq0ork3ahu
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
class MustSignConfig(config.MemoryStack):
53
53
 
54
54
    def __init__(self):
55
 
        super(MustSignConfig, self).__init__('''
 
55
        super(MustSignConfig, self).__init__(b'''
56
56
create_signatures=always
57
57
''')
58
58
 
102
102
        tree1.lock_read()
103
103
        text = tree1.get_file_text('hello')
104
104
        tree1.unlock()
105
 
        self.assertEqual('hello world', text)
 
105
        self.assertEqual(b'hello world', text)
106
106
 
107
107
        tree2 = b.repository.revision_tree(rev2)
108
108
        tree2.lock_read()
109
109
        text = tree2.get_file_text('hello')
110
110
        tree2.unlock()
111
 
        self.assertEqual('version 2', text)
 
111
        self.assertEqual(b'version 2', text)
112
112
 
113
113
    def test_commit_lossy_native(self):
114
114
        """Attempt a lossy commit to a native branch."""
117
117
        with open('hello', 'w') as f: f.write('hello world')
118
118
        wt.add('hello')
119
119
        revid = wt.commit(message='add hello', rev_id=b'revid', lossy=True)
120
 
        self.assertEqual('revid', revid)
 
120
        self.assertEqual(b'revid', revid)
121
121
 
122
122
    def test_commit_lossy_foreign(self):
123
123
        """Attempt a lossy commit to a foreign branch."""
129
129
        wt.add('hello')
130
130
        revid = wt.commit(message='add hello', lossy=True,
131
131
            timestamp=1302659388, timezone=0)
132
 
        self.assertEqual('dummy-v1:1302659388.0-0-UNKNOWN', revid)
 
132
        self.assertEqual(b'dummy-v1:1302659388-0-UNKNOWN', revid)
133
133
 
134
134
    def test_commit_bound_lossy_foreign(self):
135
135
        """Attempt a lossy commit to a bzr branch bound to a foreign branch."""
142
142
        wt.add('hello')
143
143
        revid = wt.commit(message='add hello', lossy=True,
144
144
            timestamp=1302659388, timezone=0)
145
 
        self.assertEqual('dummy-v1:1302659388.0-0-0', revid)
146
 
        self.assertEqual('dummy-v1:1302659388.0-0-0',
 
145
        self.assertEqual(b'dummy-v1:1302659388-0-0', revid)
 
146
        self.assertEqual(b'dummy-v1:1302659388-0-0',
147
147
            foreign_branch.last_revision())
148
 
        self.assertEqual('dummy-v1:1302659388.0-0-0',
 
148
        self.assertEqual(b'dummy-v1:1302659388-0-0',
149
149
            wt.branch.last_revision())
150
150
 
151
151
    def test_missing_commit(self):
163
163
            [('missing', u'hello'), ('deleted', u'hello')],
164
164
            reporter.calls)
165
165
 
166
 
        tree = b.repository.revision_tree('rev2')
 
166
        tree = b.repository.revision_tree(b'rev2')
167
167
        self.assertFalse(tree.has_id(b'hello-id'))
168
168
 
169
169
    def test_partial_commit_move(self):
219
219
        with open('hello', 'w') as f: f.write('hello')
220
220
        with open('buongia', 'w') as f: f.write('buongia')
221
221
        wt.add(['hello', 'buongia'],
222
 
              ['hello-id', 'buongia-id'])
 
222
              [b'hello-id', b'buongia-id'])
223
223
        wt.commit(message='add files',
224
224
                 rev_id=b'test@rev-1')
225
225
 
238
238
        eq = self.assertEqual
239
239
        eq(b.revno(), 3)
240
240
 
241
 
        tree2 = b.repository.revision_tree('test@rev-2')
 
241
        tree2 = b.repository.revision_tree(b'test@rev-2')
242
242
        tree2.lock_read()
243
243
        self.addCleanup(tree2.unlock)
244
244
        self.assertTrue(tree2.has_filename('hello'))
245
 
        self.assertEqual(tree2.get_file_text('hello'), 'hello')
246
 
        self.assertEqual(tree2.get_file_text('buongia'), 'new text')
 
245
        self.assertEqual(tree2.get_file_text('hello'), b'hello')
 
246
        self.assertEqual(tree2.get_file_text('buongia'), b'new text')
247
247
 
248
 
        tree3 = b.repository.revision_tree('test@rev-3')
 
248
        tree3 = b.repository.revision_tree(b'test@rev-3')
249
249
        tree3.lock_read()
250
250
        self.addCleanup(tree3.unlock)
251
251
        self.assertFalse(tree3.has_filename('hello'))
252
 
        self.assertEqual(tree3.get_file_text('buongia'), 'new text')
 
252
        self.assertEqual(tree3.get_file_text('buongia'), b'new text')
253
253
 
254
254
    def test_commit_rename(self):
255
255
        """Test commit of a revision where a file is renamed."""
267
267
        tree1.lock_read()
268
268
        self.addCleanup(tree1.unlock)
269
269
        eq(tree1.id2path(b'hello-id'), 'hello')
270
 
        eq(tree1.get_file_text('hello'), 'contents of hello\n')
 
270
        eq(tree1.get_file_text('hello'), b'contents of hello\n')
271
271
        self.assertFalse(tree1.has_filename('fruity'))
272
272
        self.check_tree_shape(tree1, ['hello'])
273
273
        eq(tree1.get_file_revision('hello'), b'test@rev-1')
276
276
        tree2.lock_read()
277
277
        self.addCleanup(tree2.unlock)
278
278
        eq(tree2.id2path(b'hello-id'), 'fruity')
279
 
        eq(tree2.get_file_text('fruity'), 'contents of hello\n')
 
279
        eq(tree2.get_file_text('fruity'), b'contents of hello\n')
280
280
        self.check_tree_shape(tree2, ['fruity'])
281
281
        eq(tree2.get_file_revision('fruity'), b'test@rev-2')
282
282
 
345
345
        wt.remove('hello')
346
346
        wt.commit('removed hello', rev_id=b'rev2')
347
347
 
348
 
        tree = b.repository.revision_tree('rev2')
349
 
        self.assertFalse(tree.has_id('hello-id'))
 
348
        tree = b.repository.revision_tree(b'rev2')
 
349
        self.assertFalse(tree.has_id(b'hello-id'))
350
350
 
351
351
    def test_committed_ancestry(self):
352
352
        """Test commit appends revisions to ancestry."""
357
357
            with open('hello', 'w') as f: f.write((str(i) * 4) + '\n')
358
358
            if i == 0:
359
359
                wt.add(['hello'], [b'hello-id'])
360
 
            rev_id = 'test@rev-%d' % (i+1)
 
360
            rev_id = b'test@rev-%d' % (i+1)
361
361
            rev_ids.append(rev_id)
362
362
            wt.commit(message='rev %d' % (i+1),
363
363
                     rev_id=rev_id)
370
370
        b = wt.branch
371
371
        self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
372
372
        wt.add(['dir', 'dir/file1', 'dir/file2'],
373
 
              ['dirid', 'file1id', 'file2id'])
 
373
              [b'dirid', b'file1id', b'file2id'])
374
374
        wt.commit('dir/file1', specific_files=['dir/file1'], rev_id=b'1')
375
 
        inv = b.repository.get_inventory('1')
376
 
        self.assertEqual('1', inv.get_entry('dirid').revision)
377
 
        self.assertEqual('1', inv.get_entry('file1id').revision)
 
375
        inv = b.repository.get_inventory(b'1')
 
376
        self.assertEqual(b'1', inv.get_entry(b'dirid').revision)
 
377
        self.assertEqual(b'1', inv.get_entry(b'file1id').revision)
378
378
        # FIXME: This should raise a KeyError I think, rbc20051006
379
 
        self.assertRaises(BzrError, inv.get_entry, 'file2id')
 
379
        self.assertRaises(BzrError, inv.get_entry, b'file2id')
380
380
 
381
381
    def test_strict_commit(self):
382
382
        """Try and commit with unknown files and strict = True, should fail."""
423
423
        wt = self.make_branch_and_tree('.')
424
424
        branch = wt.branch
425
425
        wt.commit("base", allow_pointless=True, rev_id=b'A')
426
 
        self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
 
426
        self.assertFalse(branch.repository.has_signature_for_revision_id(b'A'))
427
427
        try:
428
428
            from ..testament import Testament
429
429
            # monkey patch gpg signing mechanism
430
430
            breezy.gpg.GPGStrategy = breezy.gpg.LoopbackGPGStrategy
431
 
            conf = config.MemoryStack('''
 
431
            conf = config.MemoryStack(b'''
432
432
create_signatures=always
433
433
''')
434
434
            commit.Commit(config_stack=conf).commit(
438
438
                return breezy.gpg.LoopbackGPGStrategy(None).sign(
439
439
                        text, breezy.gpg.MODE_CLEAR)
440
440
            self.assertEqual(sign(Testament.from_revision(branch.repository,
441
 
                                                          'B').as_short_text()),
442
 
                             branch.repository.get_signature_text('B'))
 
441
                                                          b'B').as_short_text()),
 
442
                             branch.repository.get_signature_text(b'B'))
443
443
        finally:
444
444
            breezy.gpg.GPGStrategy = oldstrategy
445
445
 
450
450
        wt = self.make_branch_and_tree('.')
451
451
        branch = wt.branch
452
452
        wt.commit("base", allow_pointless=True, rev_id=b'A')
453
 
        self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
 
453
        self.assertFalse(branch.repository.has_signature_for_revision_id(b'A'))
454
454
        try:
455
455
            # monkey patch gpg signing mechanism
456
456
            breezy.gpg.GPGStrategy = breezy.gpg.DisabledGPGStrategy
457
 
            conf = config.MemoryStack('''
 
457
            conf = config.MemoryStack(b'''
458
458
create_signatures=always
459
459
''')
460
460
            self.assertRaises(breezy.gpg.SigningFailed,
464
464
                              rev_id=b'B',
465
465
                              working_tree=wt)
466
466
            branch = Branch.open(self.get_url('.'))
467
 
            self.assertEqual(branch.last_revision(), 'A')
468
 
            self.assertFalse(branch.repository.has_revision('B'))
 
467
            self.assertEqual(branch.last_revision(), b'A')
 
468
            self.assertFalse(branch.repository.has_revision(b'B'))
469
469
        finally:
470
470
            breezy.gpg.GPGStrategy = oldstrategy
471
471
 
478
478
            calls.append('called')
479
479
        breezy.ahook = called
480
480
        try:
481
 
            conf = config.MemoryStack('post_commit=breezy.ahook breezy.ahook')
 
481
            conf = config.MemoryStack(b'post_commit=breezy.ahook breezy.ahook')
482
482
            commit.Commit(config_stack=conf).commit(
483
483
                message = "base", allow_pointless=True, rev_id=b'A',
484
484
                working_tree = wt)
628
628
        tree.commit('added a', timestamp=1153248633.4186721, timezone=0,
629
629
                    rev_id=b'a1')
630
630
 
631
 
        rev = tree.branch.repository.get_revision('a1')
 
631
        rev = tree.branch.repository.get_revision(b'a1')
632
632
        self.assertEqual(1153248633.419, rev.timestamp)
633
633
 
634
634
    def test_commit_has_1ms_resolution(self):
638
638
        tree.add('a')
639
639
        tree.commit('added a', rev_id=b'a1')
640
640
 
641
 
        rev = tree.branch.repository.get_revision('a1')
 
641
        rev = tree.branch.repository.get_revision(b'a1')
642
642
        timestamp = rev.timestamp
643
643
        timestamp_1ms = round(timestamp, 3)
644
644
        self.assertEqual(timestamp_1ms, timestamp)
758
758
        tree = self.make_branch_and_tree('foo')
759
759
        # pending merge would turn into a left parent
760
760
        tree.commit('commit 1')
761
 
        tree.add_parent_tree_id('example')
 
761
        tree.add_parent_tree_id(b'example')
762
762
        self.build_tree(['foo/bar', 'foo/baz'])
763
763
        tree.add(['bar', 'baz'])
764
764
        err = self.assertRaises(CannotCommitSelectedFileMerge,
830
830
        branch = controldir.ControlDir.create_branch_convenience('repo/branch')
831
831
        tree2 = branch.create_checkout('repo/tree2')
832
832
        tree2.commit('message', rev_id=b'rev1')
833
 
        self.assertTrue(tree2.branch.repository.has_revision('rev1'))
 
833
        self.assertTrue(tree2.branch.repository.has_revision(b'rev1'))
834
834
 
835
835
 
836
836
class FilterExcludedTests(TestCase):