1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# Copyright (C) 2007 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Tests for the contract of uncommit on branches.
Note that uncommit currently is not a branch method; it should be.
"""
from bzrlib.branch import Branch
from bzrlib import errors
from bzrlib.tests.per_branch.test_branch import TestCaseWithBranch
from bzrlib.uncommit import uncommit
class TestUncommitHook(TestCaseWithBranch):
def setUp(self):
self.hook_calls = []
TestCaseWithBranch.setUp(self)
def capture_post_uncommit_hook(self, local, master, old_revno,
old_revid, new_revno, new_revid):
"""Capture post uncommit hook calls to self.hook_calls.
The call is logged, as is some state of the two branches.
"""
if local:
local_locked = local.is_locked()
local_base = local.base
else:
local_locked = None
local_base = None
self.hook_calls.append(
('post_uncommit', local_base, master.base, old_revno, old_revid,
new_revno, new_revid, local_locked, master.is_locked()))
def test_post_uncommit_to_origin(self):
tree = self.make_branch_and_memory_tree('branch')
tree.lock_write()
tree.add('')
revid = tree.commit('a revision')
tree.unlock()
Branch.hooks.install_named_hook('post_uncommit',
self.capture_post_uncommit_hook, None)
uncommit(tree.branch)
# with nothing left we should still get a notification, and
# have the branch locked at notification time.
self.assertEqual([
('post_uncommit', None, tree.branch.base, 1, revid,
0, None, None, True)
],
self.hook_calls)
def test_post_uncommit_bound(self):
master = self.make_branch('master')
tree = self.make_branch_and_memory_tree('local')
try:
tree.branch.bind(master)
except errors.UpgradeRequired:
# cant bind this format, the test is irrelevant.
return
tree.lock_write()
tree.add('')
revid = tree.commit('a revision')
tree.unlock()
Branch.hooks.install_named_hook('post_uncommit',
self.capture_post_uncommit_hook, None)
uncommit(tree.branch)
# with nothing left we should still get a notification, and
# have the branch locked at notification time.
self.assertEqual([
('post_uncommit', tree.branch.base, master.base, 1, revid,
0, None, True, True)
],
self.hook_calls)
def test_post_uncommit_not_to_origin(self):
tree = self.make_branch_and_memory_tree('branch')
tree.lock_write()
tree.add('')
revid = tree.commit('first revision')
revid2 = tree.commit('second revision')
revid3 = tree.commit('third revision')
tree.unlock()
Branch.hooks.install_named_hook('post_uncommit',
self.capture_post_uncommit_hook, None)
uncommit(tree.branch, revno=2)
# having uncommitted from up the branch, we should get the
# before and after revnos and revids correctly.
self.assertEqual([
('post_uncommit', None, tree.branch.base, 3, revid3,
1, revid, None, True)
],
self.hook_calls)
|