/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/per_workingtree/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:
95
95
        tree_b.commit('delete in B')
96
96
 
97
97
        self.assertThat(
98
 
                tree_b,
99
 
                HasPathRelations(
100
 
                    tree_a, [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))
 
98
            tree_b,
 
99
            HasPathRelations(
 
100
                tree_a, [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))
101
101
 
102
102
        self.build_tree_contents([('A/a/n', b'new contents for n\n')])
103
103
        tree_a.commit('change n in A')
108
108
        self.assertEqual(3, num_conflicts)
109
109
 
110
110
        self.assertThat(
111
 
                tree_b, HasPathRelations(
112
 
                    tree_a,
113
 
                    [('', ''), ('a/', 'a/'), ('xyz/', None),
114
 
                     ('a/n.OTHER', 'a/n'), ('xyz/m', 'a/m')]))
 
111
            tree_b, HasPathRelations(
 
112
                tree_a,
 
113
                [('', ''), ('a/', 'a/'), ('xyz/', None),
 
114
                 ('a/n.OTHER', 'a/n'), ('xyz/m', 'a/m')]))
115
115
 
116
116
        osutils.rmtree('B/a')
117
117
        try:
124
124
        tree_b.commit('autoremove a, without touching xyz/m')
125
125
 
126
126
        self.assertThat(
127
 
                tree_b, HasPathRelations(
128
 
                    tree_a,
129
 
                    [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))
 
127
            tree_b, HasPathRelations(
 
128
                tree_a,
 
129
                [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))
130
130
 
131
131
    def test_commit_exclude_pending_merge_fails(self):
132
132
        """Excludes are a form of partial commit."""
138
138
        wt2.commit('change_right')
139
139
        wt.merge_from_branch(wt2.branch)
140
140
        self.assertRaises(CannotCommitSelectedFileMerge,
141
 
            wt.commit, 'test', exclude=['foo'])
 
141
                          wt.commit, 'test', exclude=['foo'])
142
142
 
143
143
    def test_commit_exclude_exclude_changed_is_pointless(self):
144
144
        tree = self.make_branch_and_tree('.')
147
147
        tree.commit('setup test')
148
148
        self.build_tree_contents([('a', b'new contents for "a"\n')])
149
149
        self.assertRaises(PointlessCommit, tree.commit, 'test',
150
 
            exclude=['a'], allow_pointless=False)
 
150
                          exclude=['a'], allow_pointless=False)
151
151
 
152
152
    def test_commit_exclude_excludes_modified_files(self):
153
153
        tree = self.make_branch_and_tree('.')
219
219
        wt.add(['a'], None, ['file'])
220
220
        a_id = wt.path2id('a')
221
221
        self.assertEqual('a', wt.id2path(a_id))
 
222
 
222
223
        def fail_message(obj):
223
224
            raise errors.BzrCommandError("empty commit message")
224
225
        self.assertRaises(errors.BzrCommandError, wt.commit,
225
 
            message_callback=fail_message)
 
226
                          message_callback=fail_message)
226
227
        self.assertEqual('a', wt.id2path(a_id))
227
228
 
228
229
    def test_local_commit_ignores_master(self):
268
269
            raise tests.TestNotApplicable(
269
270
                'format does not support ghosts')
270
271
        wt.set_parent_ids([b'non:existent@rev--ision--0--2'],
271
 
            allow_leftmost_as_ghost=True)
 
272
                          allow_leftmost_as_ghost=True)
272
273
        rev_id = wt.commit('commit against a ghost first parent.')
273
274
        rev = wt.branch.repository.get_revision(rev_id)
274
275
        self.assertEqual(rev.parent_ids, [b'non:existent@rev--ision--0--2'])
282
283
            raise tests.TestNotApplicable(
283
284
                'format does not support ghosts')
284
285
        wt.set_parent_ids([
285
 
                b'foo@azkhazan-123123-abcabc',
286
 
                b'wibble@fofof--20050401--1928390812',
 
286
            b'foo@azkhazan-123123-abcabc',
 
287
            b'wibble@fofof--20050401--1928390812',
287
288
            ],
288
289
            allow_leftmost_as_ghost=True)
289
290
        rev_id = wt.commit("commit from ghost base with one merge")
290
291
        # the revision should have been committed with two parents
291
292
        rev = wt.branch.repository.get_revision(rev_id)
292
293
        self.assertEqual([b'foo@azkhazan-123123-abcabc',
293
 
            b'wibble@fofof--20050401--1928390812'],
294
 
            rev.parent_ids)
 
294
                          b'wibble@fofof--20050401--1928390812'],
 
295
                         rev.parent_ids)
295
296
 
296
297
    def test_commit_deleted_subtree_and_files_updates_workingtree(self):
297
298
        """The working trees inventory may be adjusted by commit."""
391
392
        sub_basis.lock_read()
392
393
        self.addCleanup(sub_basis.unlock)
393
394
        self.assertEqual(
394
 
                subsubtree.last_revision(),
395
 
                sub_basis.get_reference_revision('subtree'))
 
395
            subsubtree.last_revision(),
 
396
            sub_basis.get_reference_revision('subtree'))
396
397
        # the intermediate tree has changed, so should have had a commit
397
398
        # take place.
398
399
        self.assertNotEqual(None, subtree.last_revision())
402
403
        basis.lock_read()
403
404
        self.addCleanup(basis.unlock)
404
405
        self.assertEqual(subtree.last_revision(),
405
 
            basis.get_reference_revision('subtree'))
 
406
                         basis.get_reference_revision('subtree'))
406
407
        # the outer tree must have have changed too.
407
408
        self.assertNotEqual(None, rev_id)
408
409
 
436
437
        basis.lock_read()
437
438
        self.addCleanup(basis.unlock)
438
439
        self.assertEqual(subtree.last_revision(),
439
 
            basis.get_reference_revision('subtree'))
 
440
                         basis.get_reference_revision('subtree'))
440
441
        self.assertNotEqual(rev_id, rev_id2)
441
442
 
442
443
    def test_nested_pointless_commits_are_pointless(self):
452
453
        child_revid = subtree.last_revision()
453
454
        # now do a no-op commit with allow_pointless=False
454
455
        self.assertRaises(PointlessCommit, tree.commit, '',
455
 
            allow_pointless=False)
 
456
                          allow_pointless=False)
456
457
        self.assertEqual(child_revid, subtree.last_revision())
457
458
        self.assertEqual(rev_id, tree.last_revision())
458
459
 
494
495
             ('update', 4, 5, 'Updating the working tree - Stage'),
495
496
             ('update', 5, 5, 'Running post_commit hooks - Stage')],
496
497
            factory._calls
497
 
           )
 
498
            )
498
499
 
499
500
    def test_commit_progress_shows_post_hook_names(self):
500
501
        tree = self.make_branch_and_tree('.')
502
503
        # emitted
503
504
        factory = ProgressRecordingUIFactory()
504
505
        ui.ui_factory = factory
 
506
 
505
507
        def a_hook(_, _2, _3, _4, _5, _6):
506
508
            pass
507
509
        branch.Branch.hooks.install_named_hook('post_commit', a_hook,
517
519
             ('update', 5, 5, 'Running post_commit hooks [hook name] - Stage'),
518
520
             ],
519
521
            factory._calls
520
 
           )
 
522
            )
521
523
 
522
524
    def test_commit_progress_shows_pre_hook_names(self):
523
525
        tree = self.make_branch_and_tree('.')
525
527
        # emitted
526
528
        factory = ProgressRecordingUIFactory()
527
529
        ui.ui_factory = factory
 
530
 
528
531
        def a_hook(_, _2, _3, _4, _5, _6, _7, _8):
529
532
            pass
530
533
        branch.Branch.hooks.install_named_hook('pre_commit', a_hook,
540
543
             ('update', 5, 5, 'Running post_commit hooks - Stage'),
541
544
             ],
542
545
            factory._calls
543
 
           )
 
546
            )
544
547
 
545
548
    def test_start_commit_hook(self):
546
549
        """Make sure a start commit hook can modify the tree that is
547
550
        committed."""
548
551
        def start_commit_hook_adds_file(tree):
549
 
            with open(tree.abspath("newfile"), 'w') as f: f.write("data")
 
552
            with open(tree.abspath("newfile"), 'w') as f:
 
553
                f.write("data")
550
554
            tree.add(["newfile"])
 
555
 
551
556
        def restoreDefaults():
552
557
            mutabletree.MutableTree.hooks['start_commit'] = []
553
558
        self.addCleanup(restoreDefaults)
564
569
        """Make sure a post_commit hook is called after a commit."""
565
570
        def post_commit_hook_test_params(params):
566
571
            self.assertTrue(isinstance(params,
567
 
                mutabletree.PostCommitHookParams))
 
572
                                       mutabletree.PostCommitHookParams))
568
573
            self.assertTrue(isinstance(params.mutable_tree,
569
 
                mutabletree.MutableTree))
570
 
            with open(tree.abspath("newfile"), 'w') as f: f.write("data")
 
574
                                       mutabletree.MutableTree))
 
575
            with open(tree.abspath("newfile"), 'w') as f:
 
576
                f.write("data")
571
577
            params.mutable_tree.add(["newfile"])
572
578
        tree = self.make_branch_and_tree('.')
573
579
        mutabletree.MutableTree.hooks.install_named_hook(