/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 bzrlib/tests/workingtree_implementations/test_commit.py

  • Committer: Andrew Bennetts
  • Date: 2008-09-08 12:59:00 UTC
  • mfrom: (3695 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080908125900-8ywtsr7jqyyatjz0
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    bzrdir,
24
24
    conflicts,
25
25
    errors,
 
26
    mutabletree,
26
27
    osutils,
27
28
    revision as _mod_revision,
28
29
    ui,
194
195
                          ('xyz/m', 'm-id'),
195
196
                         ], paths)
196
197
 
 
198
    def test_commit_exclude_pending_merge_fails(self):
 
199
        """Excludes are a form of partial commit."""
 
200
        wt = self.make_branch_and_tree('.')
 
201
        self.build_tree(['foo'])
 
202
        wt.add('foo')
 
203
        wt.commit('commit one')
 
204
        wt2 = wt.bzrdir.sprout('to').open_workingtree()
 
205
        wt2.commit('change_right')
 
206
        wt.merge_from_branch(wt2.branch)
 
207
        self.assertRaises(errors.CannotCommitSelectedFileMerge,
 
208
            wt.commit, 'test', exclude=['foo'])
 
209
 
 
210
    def test_commit_exclude_exclude_changed_is_pointless(self):
 
211
        tree = self.make_branch_and_tree('.')
 
212
        self.build_tree(['a'])
 
213
        tree.smart_add(['.'])
 
214
        tree.commit('setup test')
 
215
        self.build_tree_contents([('a', 'new contents for "a"\n')])
 
216
        self.assertRaises(errors.PointlessCommit, tree.commit, 'test',
 
217
            exclude=['a'], allow_pointless=False)
 
218
 
 
219
    def test_commit_exclude_excludes_modified_files(self):
 
220
        tree = self.make_branch_and_tree('.')
 
221
        self.build_tree(['a', 'b', 'c'])
 
222
        tree.smart_add(['.'])
 
223
        tree.commit('test', exclude=['b', 'c'])
 
224
        # If b was excluded it will still be 'added' in status.
 
225
        tree.lock_read()
 
226
        self.addCleanup(tree.unlock)
 
227
        changes = list(tree.iter_changes(tree.basis_tree()))
 
228
        self.assertEqual(2, len(changes))
 
229
        self.assertEqual((None, 'b'), changes[0][1])
 
230
        self.assertEqual((None, 'c'), changes[1][1])
 
231
 
 
232
    def test_commit_exclude_subtree_of_selected(self):
 
233
        tree = self.make_branch_and_tree('.')
 
234
        self.build_tree(['a/', 'a/b'])
 
235
        tree.smart_add(['.'])
 
236
        tree.commit('test', specific_files=['a'], exclude=['a/b'])
 
237
        # If a/b was excluded it will still be 'added' in status.
 
238
        tree.lock_read()
 
239
        self.addCleanup(tree.unlock)
 
240
        changes = list(tree.iter_changes(tree.basis_tree()))
 
241
        self.assertEqual(1, len(changes))
 
242
        self.assertEqual((None, 'a/b'), changes[0][1])
 
243
 
197
244
    def test_commit_sets_last_revision(self):
198
245
        tree = self.make_branch_and_tree('tree')
199
246
        committed_id = tree.commit('foo', rev_id='foo')
497
544
        ui.ui_factory = factory
498
545
        def a_hook(_, _2, _3, _4, _5, _6):
499
546
            pass
500
 
        branch.Branch.hooks.install_hook('post_commit', a_hook)
501
 
        branch.Branch.hooks.name_hook(a_hook, 'hook name')
 
547
        branch.Branch.hooks.install_named_hook('post_commit', a_hook,
 
548
                                               'hook name')
502
549
        tree.commit('first post')
503
550
        self.assertEqual(
504
551
            [('update', 1, 5, 'Collecting changes [Directory 0] - Stage'),
522
569
        ui.ui_factory = factory
523
570
        def a_hook(_, _2, _3, _4, _5, _6, _7, _8):
524
571
            pass
525
 
        branch.Branch.hooks.install_hook('pre_commit', a_hook)
526
 
        branch.Branch.hooks.name_hook(a_hook, 'hook name')
 
572
        branch.Branch.hooks.install_named_hook('pre_commit', a_hook,
 
573
                                               'hook name')
527
574
        tree.commit('first post')
528
575
        self.assertEqual(
529
576
            [('update', 1, 5, 'Collecting changes [Directory 0] - Stage'),
536
583
             ],
537
584
            factory._calls
538
585
           )
 
586
 
 
587
    def test_start_commit_hook(self):
 
588
        """Make sure a start commit hook can modify the tree that is 
 
589
        committed."""
 
590
        def start_commit_hook_adds_file(tree):
 
591
            open(tree.abspath("newfile"), 'w').write("data")
 
592
            tree.add(["newfile"])
 
593
        def restoreDefaults():
 
594
            mutabletree.MutableTree.hooks['start_commit'] = []
 
595
        self.addCleanup(restoreDefaults)
 
596
        tree = self.make_branch_and_tree('.')
 
597
        mutabletree.MutableTree.hooks.install_named_hook(
 
598
            'start_commit',
 
599
            start_commit_hook_adds_file,
 
600
            None)
 
601
        revid = tree.commit('first post')
 
602
        committed_tree = tree.basis_tree()
 
603
        self.assertTrue(committed_tree.has_filename("newfile"))