/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/per_workingtree/test_commit.py

  • Committer: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
18
from cStringIO import StringIO
19
19
import os
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
37
 
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
 
37
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
38
38
from bzrlib.trace import mutter
39
39
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
40
40
                                WorkingTree)
49
49
        self.depth = 0
50
50
 
51
51
    def clear(self):
52
 
        """See progress.ProgressBar.clear()."""
 
52
        """See progress.ProgressTask.clear()."""
53
53
 
54
54
    def clear_term(self):
55
 
        """See progress.ProgressBar.clear_term()."""
 
55
        """See progress.ProgressTask.clear_term()."""
56
56
 
57
57
    def finished(self):
58
 
        """See progress.ProgressBar.finished()."""
 
58
        """See progress.ProgressTask.finished()."""
59
59
        self.depth -= 1
60
60
 
61
61
    def note(self, fmt_string, *args, **kwargs):
62
 
        """See progress.ProgressBar.note()."""
 
62
        """See progress.ProgressTask.note()."""
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
70
70
 
71
71
    def update(self, message, count=None, total=None):
72
 
        """See progress.ProgressBar.update()."""
 
72
        """See progress.ProgressTask.update()."""
73
73
        if self.depth == 1:
74
74
            self._calls.append(("update", count, total, message))
75
75
 
168
168
        tree_a.commit('change n in A')
169
169
 
170
170
        # Merging from A should introduce conflicts because 'n' was modified
171
 
        # and removed, so 'a' needs to be restored.
 
171
        # (in A) and removed (in B), so 'a' needs to be restored.
172
172
        num_conflicts = tree_b.merge_from_branch(tree_a.branch)
173
173
        self.assertEqual(3, num_conflicts)
174
174
        paths = [(path, ie.file_id)
255
255
        self.assertNotEqual(None, committed_id)
256
256
 
257
257
    def test_commit_local_unbound(self):
258
 
        # 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
259
259
        # also an error
260
260
        tree = self.make_branch_and_tree('tree')
261
261
        self.assertRaises(errors.LocalRequiresBoundBranch,
280
280
        wt2.merge_from_branch(wt.branch)
281
281
        wt2.commit('merged kind change')
282
282
 
 
283
    def test_commit_aborted_does_not_apply_automatic_changes_bug_282402(self):
 
284
        wt = self.make_branch_and_tree('.')
 
285
        wt.add(['a'], ['a-id'], ['file'])
 
286
        def fail_message(obj):
 
287
            raise errors.BzrCommandError("empty commit message")
 
288
        self.assertRaises(errors.BzrCommandError, wt.commit,
 
289
            message_callback=fail_message)
 
290
        self.assertEqual('a', wt.id2path('a-id'))
 
291
 
283
292
    def test_local_commit_ignores_master(self):
284
293
        # a --local commit does not require access to the master branch
285
294
        # at all, or even for it to exist.
299
308
                          bzrdir.BzrDir.open,
300
309
                          'master')
301
310
        tree.commit('foo', rev_id='foo', local=True)
302
 
 
 
311
 
303
312
    def test_local_commit_does_not_push_to_master(self):
304
313
        # a --local commit does not require access to the master branch
305
314
        # at all, or even for it to exist.
444
453
            basis.get_reference_revision(basis.path2id('subtree')))
445
454
        # the outer tree must have have changed too.
446
455
        self.assertNotEqual(None, rev_id)
447
 
        
 
456
 
448
457
    def test_nested_commit_second_commit_detects_changes(self):
449
458
        """Commit with a nested tree picks up the correct child revid."""
450
459
        tree = self.make_branch_and_tree('.')
456
465
        self.build_tree(['subtree/file'])
457
466
        subtree.add(['file'], ['file-id'])
458
467
        rev_id = tree.commit('added reference', allow_pointless=False)
 
468
        tree.get_reference_revision(tree.path2id('subtree'))
459
469
        child_revid = subtree.last_revision()
460
470
        # now change the child tree
461
471
        self.build_tree_contents([('subtree/file', 'new-content')])
494
504
 
495
505
 
496
506
class TestCommitProgress(TestCaseWithWorkingTree):
497
 
    
498
 
    def restoreDefaults(self):
499
 
        ui.ui_factory = self.old_ui_factory
 
507
 
 
508
    def setUp(self):
 
509
        super(TestCommitProgress, self).setUp()
 
510
        ui.ui_factory = CapturingUIFactory()
500
511
 
501
512
    def test_commit_progress_steps(self):
502
 
        # during commit we one progress update for every entry in the 
 
513
        # during commit we one progress update for every entry in the
503
514
        # inventory, and then one for the inventory, and one for the
504
515
        # inventory, and one for the revision insertions.
505
 
        # first we need a test commit to do. Lets setup a branch with 
 
516
        # first we need a test commit to do. Lets setup a branch with
506
517
        # 3 files, and alter one in a selected-file commit. This exercises
507
 
        # a number of cases quickly. We should also test things like 
 
518
        # a number of cases quickly. We should also test things like
508
519
        # selective commits which excludes newly added files.
509
520
        tree = self.make_branch_and_tree('.')
510
521
        self.build_tree(['a', 'b', 'c'])
513
524
        f = file('b', 'wt')
514
525
        f.write('new content')
515
526
        f.close()
516
 
        # set a progress bar that captures the calls so we can see what is 
 
527
        # set a progress bar that captures the calls so we can see what is
517
528
        # emitted
518
 
        self.old_ui_factory = ui.ui_factory
519
 
        self.addCleanup(self.restoreDefaults)
520
529
        factory = CapturingUIFactory()
521
530
        ui.ui_factory = factory
522
531
        # TODO RBC 20060421 it would be nice to merge the reporter output
525
534
        tree.commit('second post', specific_files=['b'])
526
535
        # 5 steps, the first of which is reported 2 times, once per dir
527
536
        self.assertEqual(
528
 
            [('update', 1, 5, 'Collecting changes [Directory 0] - Stage'),
529
 
             ('update', 1, 5, 'Collecting changes [Directory 1] - Stage'),
 
537
            [('update', 1, 5, 'Collecting changes [0] - Stage'),
 
538
             ('update', 1, 5, 'Collecting changes [1] - Stage'),
530
539
             ('update', 2, 5, 'Saving data locally - Stage'),
531
540
             ('update', 3, 5, 'Running pre_commit hooks - Stage'),
532
541
             ('update', 4, 5, 'Updating the working tree - Stage'),
536
545
 
537
546
    def test_commit_progress_shows_post_hook_names(self):
538
547
        tree = self.make_branch_and_tree('.')
539
 
        # set a progress bar that captures the calls so we can see what is 
 
548
        # set a progress bar that captures the calls so we can see what is
540
549
        # emitted
541
 
        self.old_ui_factory = ui.ui_factory
542
 
        self.addCleanup(self.restoreDefaults)
543
550
        factory = CapturingUIFactory()
544
551
        ui.ui_factory = factory
545
552
        def a_hook(_, _2, _3, _4, _5, _6):
548
555
                                               'hook name')
549
556
        tree.commit('first post')
550
557
        self.assertEqual(
551
 
            [('update', 1, 5, 'Collecting changes [Directory 0] - Stage'),
552
 
             ('update', 1, 5, 'Collecting changes [Directory 1] - Stage'),
 
558
            [('update', 1, 5, 'Collecting changes [0] - Stage'),
 
559
             ('update', 1, 5, 'Collecting changes [1] - Stage'),
553
560
             ('update', 2, 5, 'Saving data locally - Stage'),
554
561
             ('update', 3, 5, 'Running pre_commit hooks - Stage'),
555
562
             ('update', 4, 5, 'Updating the working tree - Stage'),
561
568
 
562
569
    def test_commit_progress_shows_pre_hook_names(self):
563
570
        tree = self.make_branch_and_tree('.')
564
 
        # set a progress bar that captures the calls so we can see what is 
 
571
        # set a progress bar that captures the calls so we can see what is
565
572
        # emitted
566
 
        self.old_ui_factory = ui.ui_factory
567
 
        self.addCleanup(self.restoreDefaults)
568
573
        factory = CapturingUIFactory()
569
574
        ui.ui_factory = factory
570
575
        def a_hook(_, _2, _3, _4, _5, _6, _7, _8):
573
578
                                               'hook name')
574
579
        tree.commit('first post')
575
580
        self.assertEqual(
576
 
            [('update', 1, 5, 'Collecting changes [Directory 0] - Stage'),
577
 
             ('update', 1, 5, 'Collecting changes [Directory 1] - Stage'),
 
581
            [('update', 1, 5, 'Collecting changes [0] - Stage'),
 
582
             ('update', 1, 5, 'Collecting changes [1] - Stage'),
578
583
             ('update', 2, 5, 'Saving data locally - Stage'),
579
584
             ('update', 3, 5, 'Running pre_commit hooks - Stage'),
580
585
             ('update', 3, 5, 'Running pre_commit hooks [hook name] - Stage'),
585
590
           )
586
591
 
587
592
    def test_start_commit_hook(self):
588
 
        """Make sure a start commit hook can modify the tree that is 
 
593
        """Make sure a start commit hook can modify the tree that is
589
594
        committed."""
590
595
        def start_commit_hook_adds_file(tree):
591
596
            open(tree.abspath("newfile"), 'w').write("data")
601
606
        revid = tree.commit('first post')
602
607
        committed_tree = tree.basis_tree()
603
608
        self.assertTrue(committed_tree.has_filename("newfile"))
 
609
 
 
610
    def test_post_commit_hook(self):
 
611
        """Make sure a post_commit hook is called after a commit."""
 
612
        def post_commit_hook_test_params(params):
 
613
            self.assertTrue(isinstance(params,
 
614
                mutabletree.PostCommitHookParams))
 
615
            self.assertTrue(isinstance(params.mutable_tree,
 
616
                mutabletree.MutableTree))
 
617
            open(tree.abspath("newfile"), 'w').write("data")
 
618
            params.mutable_tree.add(["newfile"])
 
619
        tree = self.make_branch_and_tree('.')
 
620
        mutabletree.MutableTree.hooks.install_named_hook(
 
621
            'post_commit',
 
622
            post_commit_hook_test_params,
 
623
            None)
 
624
        self.assertFalse(tree.has_filename("newfile"))
 
625
        revid = tree.commit('first post')
 
626
        self.assertTrue(tree.has_filename("newfile"))
 
627
        committed_tree = tree.basis_tree()
 
628
        self.assertFalse(committed_tree.has_filename("newfile"))