4988.10.5
by John Arbash Meinel
Merge bzr.dev 5021 to resolve NEWS |
1 |
# Copyright (C) 2007-2010 Canonical Ltd
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
2 |
#
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
16 |
|
17 |
"""Tests for the contract of uncommit on branches.
|
|
18 |
||
19 |
Note that uncommit currently is not a branch method; it should be.
|
|
20 |
"""
|
|
21 |
||
5010.2.21
by Vincent Ladeuil
Fix imports in per_branch/test_uncommit.py. |
22 |
from bzrlib import ( |
23 |
branch, |
|
24 |
errors, |
|
25 |
uncommit, |
|
26 |
)
|
|
27 |
from bzrlib.tests import per_branch |
|
28 |
||
29 |
||
30 |
class TestUncommitHook(per_branch.TestCaseWithBranch): |
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
31 |
|
32 |
def setUp(self): |
|
33 |
self.hook_calls = [] |
|
5010.2.21
by Vincent Ladeuil
Fix imports in per_branch/test_uncommit.py. |
34 |
super(TestUncommitHook, self).setUp() |
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
35 |
|
36 |
def capture_post_uncommit_hook(self, local, master, old_revno, |
|
37 |
old_revid, new_revno, new_revid): |
|
38 |
"""Capture post uncommit hook calls to self.hook_calls.
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
39 |
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
40 |
The call is logged, as is some state of the two branches.
|
41 |
"""
|
|
42 |
if local: |
|
43 |
local_locked = local.is_locked() |
|
44 |
local_base = local.base |
|
45 |
else: |
|
46 |
local_locked = None |
|
47 |
local_base = None |
|
48 |
self.hook_calls.append( |
|
49 |
('post_uncommit', local_base, master.base, old_revno, old_revid, |
|
50 |
new_revno, new_revid, local_locked, master.is_locked())) |
|
51 |
||
52 |
def test_post_uncommit_to_origin(self): |
|
53 |
tree = self.make_branch_and_memory_tree('branch') |
|
54 |
tree.lock_write() |
|
55 |
tree.add('') |
|
56 |
revid = tree.commit('a revision') |
|
57 |
tree.unlock() |
|
5010.2.21
by Vincent Ladeuil
Fix imports in per_branch/test_uncommit.py. |
58 |
branch.Branch.hooks.install_named_hook('post_uncommit', |
3256.2.16
by Daniel Watkins
Updated uses of Hooks.install_hook to Hooks.install_named_hook in tests.branch_implementation.test_uncommit. |
59 |
self.capture_post_uncommit_hook, None) |
5010.2.21
by Vincent Ladeuil
Fix imports in per_branch/test_uncommit.py. |
60 |
uncommit.uncommit(tree.branch) |
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
61 |
# with nothing left we should still get a notification, and
|
62 |
# have the branch locked at notification time.
|
|
63 |
self.assertEqual([ |
|
64 |
('post_uncommit', None, tree.branch.base, 1, revid, |
|
65 |
0, None, None, True) |
|
66 |
],
|
|
67 |
self.hook_calls) |
|
68 |
||
69 |
def test_post_uncommit_bound(self): |
|
70 |
master = self.make_branch('master') |
|
71 |
tree = self.make_branch_and_memory_tree('local') |
|
72 |
try: |
|
73 |
tree.branch.bind(master) |
|
74 |
except errors.UpgradeRequired: |
|
75 |
# cant bind this format, the test is irrelevant.
|
|
76 |
return
|
|
77 |
tree.lock_write() |
|
78 |
tree.add('') |
|
79 |
revid = tree.commit('a revision') |
|
80 |
tree.unlock() |
|
5010.2.21
by Vincent Ladeuil
Fix imports in per_branch/test_uncommit.py. |
81 |
branch.Branch.hooks.install_named_hook( |
82 |
'post_uncommit', self.capture_post_uncommit_hook, None) |
|
83 |
uncommit.uncommit(tree.branch) |
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
84 |
# with nothing left we should still get a notification, and
|
85 |
# have the branch locked at notification time.
|
|
86 |
self.assertEqual([ |
|
87 |
('post_uncommit', tree.branch.base, master.base, 1, revid, |
|
88 |
0, None, True, True) |
|
89 |
],
|
|
90 |
self.hook_calls) |
|
91 |
||
92 |
def test_post_uncommit_not_to_origin(self): |
|
93 |
tree = self.make_branch_and_memory_tree('branch') |
|
94 |
tree.lock_write() |
|
95 |
tree.add('') |
|
96 |
revid = tree.commit('first revision') |
|
97 |
revid2 = tree.commit('second revision') |
|
98 |
revid3 = tree.commit('third revision') |
|
99 |
tree.unlock() |
|
5010.2.21
by Vincent Ladeuil
Fix imports in per_branch/test_uncommit.py. |
100 |
branch.Branch.hooks.install_named_hook( |
101 |
'post_uncommit', self.capture_post_uncommit_hook, None) |
|
102 |
uncommit.uncommit(tree.branch, revno=2) |
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
103 |
# having uncommitted from up the branch, we should get the
|
104 |
# before and after revnos and revids correctly.
|
|
105 |
self.assertEqual([ |
|
106 |
('post_uncommit', None, tree.branch.base, 3, revid3, |
|
107 |
1, revid, None, True) |
|
108 |
],
|
|
109 |
self.hook_calls) |