1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
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
17
"""Tests for the contract of uncommit on branches.
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):
32
TestCaseWithBranch.setUp(self)
34
def capture_post_uncommit_hook(self, local, master, old_revno,
35
old_revid, new_revno, new_revid):
36
"""Capture post uncommit hook calls to self.hook_calls.
38
The call is logged, as is some state of the two branches.
41
local_locked = local.is_locked()
42
local_base = local.base
46
self.hook_calls.append(
47
('post_uncommit', local_base, master.base, old_revno, old_revid,
48
new_revno, new_revid, local_locked, master.is_locked()))
50
def test_post_uncommit_to_origin(self):
51
tree = self.make_branch_and_memory_tree('branch')
54
revid = tree.commit('a revision')
56
Branch.hooks.install_hook('post_uncommit',
57
self.capture_post_uncommit_hook)
59
# with nothing left we should still get a notification, and
60
# have the branch locked at notification time.
62
('post_uncommit', None, tree.branch.base, 1, revid,
67
def test_post_uncommit_bound(self):
68
master = self.make_branch('master')
69
tree = self.make_branch_and_memory_tree('local')
71
tree.branch.bind(master)
72
except errors.UpgradeRequired:
73
# cant bind this format, the test is irrelevant.
77
revid = tree.commit('a revision')
79
Branch.hooks.install_hook('post_uncommit',
80
self.capture_post_uncommit_hook)
82
# with nothing left we should still get a notification, and
83
# have the branch locked at notification time.
85
('post_uncommit', tree.branch.base, master.base, 1, revid,
90
def test_post_uncommit_not_to_origin(self):
91
tree = self.make_branch_and_memory_tree('branch')
94
revid = tree.commit('first revision')
95
revid2 = tree.commit('second revision')
96
revid3 = tree.commit('third revision')
98
Branch.hooks.install_hook('post_uncommit',
99
self.capture_post_uncommit_hook)
100
uncommit(tree.branch, revno=2)
101
# having uncommitted from up the branch, we should get the
102
# before and after revnos and revids correctly.
104
('post_uncommit', None, tree.branch.base, 3, revid3,
105
1, revid, None, True)