~jelmer/ubuntu/maverick/bzr/2.2.5

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_commit.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2009-03-10 14:11:59 UTC
  • mfrom: (1.2.1 upstream) (3.1.68 jaunty)
  • Revision ID: james.westby@ubuntu.com-20090310141159-lwzzo5c1fwrtzgj4
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    uncommit,
31
31
    workingtree,
32
32
    )
33
 
from bzrlib.errors import (NotBranchError, NotVersionedError, 
 
33
from bzrlib.errors import (NotBranchError, NotVersionedError,
34
34
                           UnsupportedOperation)
35
35
from bzrlib.osutils import pathjoin, getcwd
36
36
from bzrlib.tests import TestCase
63
63
 
64
64
    def progress_bar(self):
65
65
        return self
66
 
    
 
66
 
67
67
    def nested_progress_bar(self):
68
68
        self.depth += 1
69
69
        return self
195
195
                          ('xyz/m', 'm-id'),
196
196
                         ], paths)
197
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
 
198
244
    def test_commit_sets_last_revision(self):
199
245
        tree = self.make_branch_and_tree('tree')
200
246
        committed_id = tree.commit('foo', rev_id='foo')
209
255
        self.assertNotEqual(None, committed_id)
210
256
 
211
257
    def test_commit_local_unbound(self):
212
 
        # using the library api to do a local commit on unbound branches is 
 
258
        # using the library api to do a local commit on unbound branches is
213
259
        # also an error
214
260
        tree = self.make_branch_and_tree('tree')
215
261
        self.assertRaises(errors.LocalRequiresBoundBranch,
253
299
                          bzrdir.BzrDir.open,
254
300
                          'master')
255
301
        tree.commit('foo', rev_id='foo', local=True)
256
 
 
 
302
 
257
303
    def test_local_commit_does_not_push_to_master(self):
258
304
        # a --local commit does not require access to the master branch
259
305
        # at all, or even for it to exist.
398
444
            basis.get_reference_revision(basis.path2id('subtree')))
399
445
        # the outer tree must have have changed too.
400
446
        self.assertNotEqual(None, rev_id)
401
 
        
 
447
 
402
448
    def test_nested_commit_second_commit_detects_changes(self):
403
449
        """Commit with a nested tree picks up the correct child revid."""
404
450
        tree = self.make_branch_and_tree('.')
448
494
 
449
495
 
450
496
class TestCommitProgress(TestCaseWithWorkingTree):
451
 
    
 
497
 
452
498
    def restoreDefaults(self):
453
499
        ui.ui_factory = self.old_ui_factory
454
500
 
455
501
    def test_commit_progress_steps(self):
456
 
        # during commit we one progress update for every entry in the 
 
502
        # during commit we one progress update for every entry in the
457
503
        # inventory, and then one for the inventory, and one for the
458
504
        # inventory, and one for the revision insertions.
459
 
        # first we need a test commit to do. Lets setup a branch with 
 
505
        # first we need a test commit to do. Lets setup a branch with
460
506
        # 3 files, and alter one in a selected-file commit. This exercises
461
 
        # a number of cases quickly. We should also test things like 
 
507
        # a number of cases quickly. We should also test things like
462
508
        # selective commits which excludes newly added files.
463
509
        tree = self.make_branch_and_tree('.')
464
510
        self.build_tree(['a', 'b', 'c'])
467
513
        f = file('b', 'wt')
468
514
        f.write('new content')
469
515
        f.close()
470
 
        # set a progress bar that captures the calls so we can see what is 
 
516
        # set a progress bar that captures the calls so we can see what is
471
517
        # emitted
472
518
        self.old_ui_factory = ui.ui_factory
473
519
        self.addCleanup(self.restoreDefaults)
490
536
 
491
537
    def test_commit_progress_shows_post_hook_names(self):
492
538
        tree = self.make_branch_and_tree('.')
493
 
        # set a progress bar that captures the calls so we can see what is 
 
539
        # set a progress bar that captures the calls so we can see what is
494
540
        # emitted
495
541
        self.old_ui_factory = ui.ui_factory
496
542
        self.addCleanup(self.restoreDefaults)
515
561
 
516
562
    def test_commit_progress_shows_pre_hook_names(self):
517
563
        tree = self.make_branch_and_tree('.')
518
 
        # set a progress bar that captures the calls so we can see what is 
 
564
        # set a progress bar that captures the calls so we can see what is
519
565
        # emitted
520
566
        self.old_ui_factory = ui.ui_factory
521
567
        self.addCleanup(self.restoreDefaults)
539
585
           )
540
586
 
541
587
    def test_start_commit_hook(self):
542
 
        """Make sure a start commit hook can modify the tree that is 
 
588
        """Make sure a start commit hook can modify the tree that is
543
589
        committed."""
544
590
        def start_commit_hook_adds_file(tree):
545
591
            open(tree.abspath("newfile"), 'w').write("data")