1
 
# Copyright (C) 2007 Canonical Ltd
 
 
1
# Copyright (C) 2007-2010 Canonical Ltd
 
3
3
# This program is free software; you can redistribute it and/or modify
 
4
4
# it under the terms of the GNU General Public License as published by
 
 
13
13
# You should have received a copy of the GNU General Public License
 
14
14
# along with this program; if not, write to the Free Software
 
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
17
"""Tests for the contract of uncommit on branches.
 
19
19
Note that uncommit currently is not a branch method; it should be.
 
22
 
from bzrlib.branch import Branch
 
23
 
from bzrlib import errors
 
24
 
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
 
25
 
from bzrlib.uncommit import uncommit
 
28
 
class TestUncommitHook(TestCaseWithBranch):
 
 
27
from bzrlib.tests import per_branch
 
 
30
class TestUncommitHook(per_branch.TestCaseWithBranch):
 
31
33
        self.hook_calls = []
 
32
 
        TestCaseWithBranch.setUp(self)
 
 
34
        super(TestUncommitHook, self).setUp()
 
34
36
    def capture_post_uncommit_hook(self, local, master, old_revno,
 
35
37
        old_revid, new_revno, new_revid):
 
36
38
        """Capture post uncommit hook calls to self.hook_calls.
 
38
40
        The call is logged, as is some state of the two branches.
 
 
54
56
        revid = tree.commit('a revision')
 
56
 
        Branch.hooks.install_named_hook('post_uncommit',
 
 
58
        branch.Branch.hooks.install_named_hook('post_uncommit',
 
57
59
            self.capture_post_uncommit_hook, None)
 
 
60
        uncommit.uncommit(tree.branch)
 
59
61
        # with nothing left we should still get a notification, and
 
60
62
        # have the branch locked at notification time.
 
 
77
79
        revid = tree.commit('a revision')
 
79
 
        Branch.hooks.install_named_hook('post_uncommit',
 
80
 
            self.capture_post_uncommit_hook, None)
 
 
81
        branch.Branch.hooks.install_named_hook(
 
 
82
            'post_uncommit', self.capture_post_uncommit_hook, None)
 
 
83
        uncommit.uncommit(tree.branch)
 
82
84
        # with nothing left we should still get a notification, and
 
83
85
        # have the branch locked at notification time.
 
 
95
97
        revid2 = tree.commit('second revision')
 
96
98
        revid3 = tree.commit('third revision')
 
98
 
        Branch.hooks.install_named_hook('post_uncommit',
 
99
 
            self.capture_post_uncommit_hook, None)
 
100
 
        uncommit(tree.branch, revno=2)
 
 
100
        branch.Branch.hooks.install_named_hook(
 
 
101
            'post_uncommit', self.capture_post_uncommit_hook, None)
 
 
102
        uncommit.uncommit(tree.branch, revno=2)
 
101
103
        # having uncommitted from up the branch, we should get the
 
102
104
        # before and after revnos and revids correctly.
 
103
105
        self.assertEqual([