bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4988.10.5
by John Arbash Meinel
Merge bzr.dev 5021 to resolve NEWS |
1 |
# Copyright (C) 2006-2010 Canonical Ltd
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
1649.1.1
by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
1649.1.1
by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
12 |
#
|
1649.1.1
by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two |
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
|
1649.1.1
by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two |
16 |
|
17 |
"""Tests for branch.pull behaviour."""
|
|
18 |
||
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
19 |
from breezy import ( |
5010.2.17
by Vincent Ladeuil
Fix imports in per_branch/test_pull.py. |
20 |
branch, |
6472.2.2
by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places. |
21 |
controldir, |
5010.2.17
by Vincent Ladeuil
Fix imports in per_branch/test_pull.py. |
22 |
errors, |
23 |
revision, |
|
24 |
)
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
25 |
from breezy.tests import ( |
5651.5.1
by Andrew Bennetts
Make 'bzr reconfigure --unstacked' fetch tagged revisions too. (#401646) |
26 |
fixtures, |
27 |
per_branch, |
|
28 |
TestNotApplicable, |
|
29 |
)
|
|
5010.2.17
by Vincent Ladeuil
Fix imports in per_branch/test_pull.py. |
30 |
|
31 |
||
32 |
class TestPull(per_branch.TestCaseWithBranch): |
|
1649.1.1
by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two |
33 |
|
34 |
def test_pull_convergence_simple(self): |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
35 |
# when revisions are pulled, the left-most accessible parents must
|
1649.1.1
by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two |
36 |
# become the revision-history.
|
37 |
parent = self.make_branch_and_tree('parent') |
|
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
38 |
p1 = parent.commit('1st post', allow_pointless=True) |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
39 |
mine = parent.controldir.sprout('mine').open_workingtree() |
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
40 |
m1 = mine.commit('my change', allow_pointless=True) |
1979.2.1
by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree. |
41 |
parent.merge_from_branch(mine.branch) |
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
42 |
p2 = parent.commit('merge my change') |
1649.1.1
by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two |
43 |
mine.pull(parent.branch) |
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
44 |
self.assertEqual(p2, mine.branch.last_revision()) |
1649.1.1
by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two |
45 |
|
46 |
def test_pull_merged_indirect(self): |
|
47 |
# it should be possible to do a pull from one branch into another
|
|
48 |
# when the tip of the target was merged into the source branch
|
|
49 |
# via a third branch - so its buried in the ancestry and is not
|
|
50 |
# directly accessible.
|
|
51 |
parent = self.make_branch_and_tree('parent') |
|
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
52 |
p1 = parent.commit('1st post', allow_pointless=True) |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
53 |
mine = parent.controldir.sprout('mine').open_workingtree() |
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
54 |
m1 = mine.commit('my change', allow_pointless=True) |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
55 |
other = parent.controldir.sprout('other').open_workingtree() |
1979.2.1
by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree. |
56 |
other.merge_from_branch(mine.branch) |
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
57 |
o2 = other.commit('merge my change') |
1979.2.1
by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree. |
58 |
parent.merge_from_branch(other.branch) |
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
59 |
p2 = parent.commit('merge other') |
1649.1.1
by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two |
60 |
mine.pull(parent.branch) |
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
61 |
self.assertEqual(p2, mine.branch.last_revision()) |
2245.2.1
by Robert Collins
Split branch pushing out of branch pulling. |
62 |
|
63 |
def test_pull_updates_checkout_and_master(self): |
|
64 |
"""Pulling into a checkout updates the checkout and the master branch""" |
|
65 |
master_tree = self.make_branch_and_tree('master') |
|
66 |
rev1 = master_tree.commit('master') |
|
67 |
checkout = master_tree.branch.create_checkout('checkout') |
|
68 |
||
7143.15.2
by Jelmer Vernooij
Run autopep8. |
69 |
other = master_tree.branch.controldir.sprout( |
70 |
'other').open_workingtree() |
|
2245.2.1
by Robert Collins
Split branch pushing out of branch pulling. |
71 |
rev2 = other.commit('other commit') |
72 |
# now pull, which should update both checkout and master.
|
|
73 |
checkout.branch.pull(other.branch) |
|
6165.4.4
by Jelmer Vernooij
Avoid .revision_history(). |
74 |
self.assertEqual(rev2, checkout.branch.last_revision()) |
75 |
self.assertEqual(rev2, master_tree.branch.last_revision()) |
|
2245.2.1
by Robert Collins
Split branch pushing out of branch pulling. |
76 |
|
4056.6.3
by Gary van der Merwe
Add local args to pull methods, and add more tests |
77 |
def test_pull_local_updates_checkout_only(self): |
78 |
"""Pulling --local into a checkout updates the checkout and not the |
|
79 |
master branch"""
|
|
80 |
master_tree = self.make_branch_and_tree('master') |
|
81 |
rev1 = master_tree.commit('master') |
|
82 |
checkout = master_tree.branch.create_checkout('checkout') |
|
83 |
||
7143.15.2
by Jelmer Vernooij
Run autopep8. |
84 |
other = master_tree.branch.controldir.sprout( |
85 |
'other').open_workingtree() |
|
4056.6.3
by Gary van der Merwe
Add local args to pull methods, and add more tests |
86 |
rev2 = other.commit('other commit') |
4335.1.1
by Ian Clatworthy
(igc) pull --local (Gary van der Merwe) |
87 |
# now pull local, which should update checkout but not master.
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
88 |
checkout.branch.pull(other.branch, local=True) |
6165.4.4
by Jelmer Vernooij
Avoid .revision_history(). |
89 |
self.assertEqual(rev2, checkout.branch.last_revision()) |
90 |
self.assertEqual(rev1, master_tree.branch.last_revision()) |
|
4056.6.3
by Gary van der Merwe
Add local args to pull methods, and add more tests |
91 |
|
92 |
def test_pull_local_raises_LocalRequiresBoundBranch_on_unbound(self): |
|
93 |
"""Pulling --local into a branch that is not bound should fail.""" |
|
94 |
master_tree = self.make_branch_and_tree('branch') |
|
95 |
rev1 = master_tree.commit('master') |
|
96 |
||
7143.15.2
by Jelmer Vernooij
Run autopep8. |
97 |
other = master_tree.branch.controldir.sprout( |
98 |
'other').open_workingtree() |
|
4056.6.3
by Gary van der Merwe
Add local args to pull methods, and add more tests |
99 |
rev2 = other.commit('other commit') |
100 |
# now pull --local, which should raise LocalRequiresBoundBranch error.
|
|
101 |
self.assertRaises(errors.LocalRequiresBoundBranch, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
102 |
master_tree.branch.pull, other.branch, local=True) |
6165.4.4
by Jelmer Vernooij
Avoid .revision_history(). |
103 |
self.assertEqual(rev1, master_tree.branch.last_revision()) |
4056.6.3
by Gary van der Merwe
Add local args to pull methods, and add more tests |
104 |
|
3482.1.1
by John Arbash Meinel
Fix bug #238149, RemoteBranch.pull needs to return the _real_branch's pull result. |
105 |
def test_pull_returns_result(self): |
106 |
parent = self.make_branch_and_tree('parent') |
|
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
107 |
p1 = parent.commit('1st post') |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
108 |
mine = parent.controldir.sprout('mine').open_workingtree() |
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
109 |
m1 = mine.commit('my change') |
3482.1.1
by John Arbash Meinel
Fix bug #238149, RemoteBranch.pull needs to return the _real_branch's pull result. |
110 |
result = parent.branch.pull(mine.branch) |
111 |
self.assertIsNot(None, result) |
|
112 |
self.assertIs(mine.branch, result.source_branch) |
|
113 |
self.assertIs(parent.branch, result.target_branch) |
|
114 |
self.assertIs(parent.branch, result.master_branch) |
|
115 |
self.assertIs(None, result.local_branch) |
|
116 |
self.assertEqual(1, result.old_revno) |
|
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
117 |
self.assertEqual(p1, result.old_revid) |
3482.1.1
by John Arbash Meinel
Fix bug #238149, RemoteBranch.pull needs to return the _real_branch's pull result. |
118 |
self.assertEqual(2, result.new_revno) |
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
119 |
self.assertEqual(m1, result.new_revid) |
7489.4.8
by Jelmer Vernooij
Consistent return values. |
120 |
self.assertEqual([], list(result.tag_conflicts)) |
3482.1.1
by John Arbash Meinel
Fix bug #238149, RemoteBranch.pull needs to return the _real_branch's pull result. |
121 |
|
1551.10.23
by Aaron Bentley
Update test case per review |
122 |
def test_pull_overwrite(self): |
123 |
tree_a = self.make_branch_and_tree('tree_a') |
|
124 |
tree_a.commit('message 1') |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
125 |
tree_b = tree_a.controldir.sprout('tree_b').open_workingtree() |
6862.1.1
by Jelmer Vernooij
Add some uniqueness to commit messages. |
126 |
rev2a = tree_a.commit('message 2a') |
127 |
rev2b = tree_b.commit('message 2b') |
|
1551.10.23
by Aaron Bentley
Update test case per review |
128 |
self.assertRaises(errors.DivergedBranches, tree_a.pull, tree_b.branch) |
3052.5.2
by John Arbash Meinel
Use a Graph.heads() check to determine if the ancestries are compatible. |
129 |
self.assertRaises(errors.DivergedBranches, |
130 |
tree_a.branch.pull, tree_b.branch, |
|
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
131 |
overwrite=False, stop_revision=rev2b) |
3052.5.2
by John Arbash Meinel
Use a Graph.heads() check to determine if the ancestries are compatible. |
132 |
# It should not have updated the branch tip, but it should have fetched
|
6217.4.1
by Jelmer Vernooij
Add RepositoryFormat.supports_invisible_revisions. |
133 |
# the revision if the repository supports "invisible" revisions
|
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
134 |
self.assertEqual(rev2a, tree_a.branch.last_revision()) |
6217.4.2
by Jelmer Vernooij
s/invisible/unreferenced. |
135 |
if tree_a.branch.repository._format.supports_unreferenced_revisions: |
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
136 |
self.assertTrue(tree_a.branch.repository.has_revision(rev2b)) |
2975.1.1
by Robert Collins
Minor fixes for foreign format friendliness. |
137 |
tree_a.branch.pull(tree_b.branch, overwrite=True, |
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
138 |
stop_revision=rev2b) |
139 |
self.assertEqual(rev2b, tree_a.branch.last_revision()) |
|
6165.4.4
by Jelmer Vernooij
Avoid .revision_history(). |
140 |
self.assertEqual(tree_b.branch.last_revision(), |
141 |
tree_a.branch.last_revision()) |
|
1551.10.23
by Aaron Bentley
Update test case per review |
142 |
|
7142.3.2
by Jelmer Vernooij
Fix overwrite for git branches. |
143 |
def test_pull_overwrite_set(self): |
144 |
tree_a = self.make_branch_and_tree('tree_a') |
|
145 |
rev1 = tree_a.commit('message 1') |
|
146 |
||
147 |
tree_b = tree_a.controldir.sprout('tree_b').open_workingtree() |
|
148 |
rev2a = tree_a.commit('message 2a') |
|
149 |
rev2b = tree_b.commit('message 2b') |
|
150 |
self.assertRaises(errors.DivergedBranches, tree_a.pull, tree_b.branch) |
|
151 |
self.assertRaises(errors.DivergedBranches, |
|
152 |
tree_a.branch.pull, tree_b.branch, |
|
153 |
overwrite=set(), stop_revision=rev2b) |
|
154 |
# It should not have updated the branch tip, but it should have fetched
|
|
155 |
# the revision if the repository supports "invisible" revisions
|
|
156 |
self.assertEqual(rev2a, tree_a.branch.last_revision()) |
|
157 |
if tree_a.branch.repository._format.supports_unreferenced_revisions: |
|
158 |
self.assertTrue(tree_a.branch.repository.has_revision(rev2b)) |
|
159 |
tree_a.branch.pull(tree_b.branch, overwrite=set(['history']), |
|
160 |
stop_revision=rev2b) |
|
161 |
self.assertEqual(rev2b, tree_a.branch.last_revision()) |
|
162 |
self.assertEqual(tree_b.branch.last_revision(), |
|
163 |
tree_a.branch.last_revision()) |
|
164 |
tree_a.branch.pull(tree_b.branch, overwrite=set(['history', 'tags']), |
|
165 |
stop_revision=rev2b) |
|
166 |
||
167 |
def test_pull_overwrite_set_tags(self): |
|
168 |
tree_a = self.make_branch_and_tree('tree_a') |
|
169 |
if not tree_a.branch.supports_tags(): |
|
170 |
raise TestNotApplicable("branch does not support tags") |
|
171 |
rev1 = tree_a.commit('message 1') |
|
172 |
tree_a.branch.tags.set_tag('tag1', rev1) |
|
173 |
||
174 |
tree_b = tree_a.controldir.sprout('tree_b').open_workingtree() |
|
175 |
rev2b = tree_b.commit('message 2b') |
|
7190.1.1
by Jelmer Vernooij
Fix test with ghost revisions. |
176 |
tree_b.branch.tags.set_tag('tag1', rev2b) |
177 |
rev1b = tree_a.commit('message 1b') |
|
7142.3.2
by Jelmer Vernooij
Fix overwrite for git branches. |
178 |
tree_a.branch.get_config_stack().set('branch.fetch_tags', True) |
179 |
self.assertRaises(errors.DivergedBranches, tree_a.pull, tree_b.branch) |
|
180 |
self.assertRaises(errors.DivergedBranches, |
|
181 |
tree_a.branch.pull, tree_b.branch, |
|
182 |
overwrite=set(), stop_revision=rev2b) |
|
183 |
# It should not have updated the branch tip, but it should have fetched
|
|
184 |
# the revision if the repository supports "invisible" revisions
|
|
7190.1.1
by Jelmer Vernooij
Fix test with ghost revisions. |
185 |
self.assertEqual(rev1b, tree_a.branch.last_revision()) |
186 |
# It also should not have updated the tags
|
|
187 |
self.assertEqual(tree_a.branch.tags.get_tag_dict(), {'tag1': rev1}) |
|
7142.3.2
by Jelmer Vernooij
Fix overwrite for git branches. |
188 |
if tree_a.branch.repository._format.supports_unreferenced_revisions: |
189 |
self.assertTrue(tree_a.branch.repository.has_revision(rev2b)) |
|
190 |
tree_a.branch.pull(tree_b.branch, overwrite=set(['history']), |
|
191 |
stop_revision=rev2b) |
|
192 |
self.assertEqual(rev2b, tree_a.branch.last_revision()) |
|
193 |
self.assertEqual(tree_b.branch.last_revision(), |
|
194 |
tree_a.branch.last_revision()) |
|
195 |
self.assertEqual(rev1, tree_a.branch.tags.lookup_tag('tag1')) |
|
196 |
tree_a.branch.pull(tree_b.branch, overwrite=set(['history', 'tags']), |
|
197 |
stop_revision=rev2b) |
|
7190.1.1
by Jelmer Vernooij
Fix test with ghost revisions. |
198 |
self.assertEqual(rev2b, tree_a.branch.tags.lookup_tag('tag1')) |
7142.3.2
by Jelmer Vernooij
Fix overwrite for git branches. |
199 |
|
5535.3.29
by Andrew Bennetts
Add some per-branch tests. |
200 |
def test_pull_merges_and_fetches_tags(self): |
201 |
"""Tags are updated by br.pull(source), and revisions named in those |
|
202 |
tags are fetched.
|
|
203 |
"""
|
|
204 |
# Make a source, sprout a target off it
|
|
205 |
try: |
|
206 |
builder = self.make_branch_builder('source') |
|
207 |
except errors.UninitializableFormat: |
|
208 |
raise TestNotApplicable('uninitializeable format') |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
209 |
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev( |
210 |
builder) |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
211 |
target = source.controldir.sprout('target').open_branch() |
5651.5.2
by Andrew Bennetts
Simplify new fixture slightly, and other test tweaks. |
212 |
# Add a tag to the source, then pull from source
|
213 |
try: |
|
6747.3.2
by Jelmer Vernooij
Avoid more uses of revision_id. |
214 |
source.tags.set_tag('tag-a', rev2) |
5651.5.2
by Andrew Bennetts
Simplify new fixture slightly, and other test tweaks. |
215 |
except errors.TagsNotSupported: |
216 |
raise TestNotApplicable('format does not support tags.') |
|
6747.3.2
by Jelmer Vernooij
Avoid more uses of revision_id. |
217 |
source.tags.set_tag('tag-a', rev2) |
6404.1.1
by Vincent Ladeuil
Migrate branch.fetch_tags |
218 |
source.get_config_stack().set('branch.fetch_tags', True) |
5535.3.29
by Andrew Bennetts
Add some per-branch tests. |
219 |
target.pull(source) |
220 |
# The tag is present, and so is its revision.
|
|
6747.3.2
by Jelmer Vernooij
Avoid more uses of revision_id. |
221 |
self.assertEqual(rev2, target.tags.lookup_tag('tag-a')) |
222 |
target.repository.get_revision(rev2) |
|
5535.3.29
by Andrew Bennetts
Add some per-branch tests. |
223 |
|
224 |
def test_pull_stop_revision_merges_and_fetches_tags(self): |
|
225 |
"""br.pull(source, stop_revision=REV) updates and fetches tags.""" |
|
226 |
# Make a source, sprout a target off it
|
|
227 |
try: |
|
228 |
builder = self.make_branch_builder('source') |
|
229 |
except errors.UninitializableFormat: |
|
230 |
raise TestNotApplicable('uninitializeable format') |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
231 |
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev( |
232 |
builder) |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
233 |
target = source.controldir.sprout('target').open_branch() |
5535.3.29
by Andrew Bennetts
Add some per-branch tests. |
234 |
# Add a new commit to the ancestry
|
6747.2.1
by Jelmer Vernooij
Avoid setting revision_ids. |
235 |
rev_2_again = builder.build_commit(message="Rev 2 again") |
236 |
# Add a tag to the source, then pull rev_2_again from source
|
|
5651.5.2
by Andrew Bennetts
Simplify new fixture slightly, and other test tweaks. |
237 |
try: |
6747.3.2
by Jelmer Vernooij
Avoid more uses of revision_id. |
238 |
source.tags.set_tag('tag-a', rev2) |
5651.5.2
by Andrew Bennetts
Simplify new fixture slightly, and other test tweaks. |
239 |
except errors.TagsNotSupported: |
240 |
raise TestNotApplicable('format does not support tags.') |
|
6404.1.1
by Vincent Ladeuil
Migrate branch.fetch_tags |
241 |
source.get_config_stack().set('branch.fetch_tags', True) |
7029.4.2
by Jelmer Vernooij
Fix more merge tests. |
242 |
target.pull(source, stop_revision=rev_2_again) |
5535.3.29
by Andrew Bennetts
Add some per-branch tests. |
243 |
# The tag is present, and so is its revision.
|
6747.3.2
by Jelmer Vernooij
Avoid more uses of revision_id. |
244 |
self.assertEqual(rev2, target.tags.lookup_tag('tag-a')) |
245 |
target.repository.get_revision(rev2) |
|
5535.3.29
by Andrew Bennetts
Add some per-branch tests. |
246 |
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
247 |
|
5010.2.17
by Vincent Ladeuil
Fix imports in per_branch/test_pull.py. |
248 |
class TestPullHook(per_branch.TestCaseWithBranch): |
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
249 |
|
250 |
def setUp(self): |
|
251 |
self.hook_calls = [] |
|
5010.2.17
by Vincent Ladeuil
Fix imports in per_branch/test_pull.py. |
252 |
super(TestPullHook, self).setUp() |
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
253 |
|
2297.1.1
by Martin Pool
Pull now returns a PullResult rather than just an integer. |
254 |
def capture_post_pull_hook(self, result): |
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
255 |
"""Capture post pull hook calls to self.hook_calls. |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
256 |
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
257 |
The call is logged, as is some state of the two branches.
|
258 |
"""
|
|
2297.1.6
by Martin Pool
Add docs for Results, give some members cleaner names |
259 |
if result.local_branch: |
260 |
local_locked = result.local_branch.is_locked() |
|
261 |
local_base = result.local_branch.base |
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
262 |
else: |
263 |
local_locked = None |
|
264 |
local_base = None |
|
265 |
self.hook_calls.append( |
|
2297.1.6
by Martin Pool
Add docs for Results, give some members cleaner names |
266 |
('post_pull', result.source_branch, local_base, |
267 |
result.master_branch.base, result.old_revno, |
|
2297.1.1
by Martin Pool
Pull now returns a PullResult rather than just an integer. |
268 |
result.old_revid, |
2297.1.6
by Martin Pool
Add docs for Results, give some members cleaner names |
269 |
result.new_revno, result.new_revid, |
270 |
result.source_branch.is_locked(), local_locked, |
|
271 |
result.master_branch.is_locked())) |
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
272 |
|
273 |
def test_post_pull_empty_history(self): |
|
274 |
target = self.make_branch('target') |
|
275 |
source = self.make_branch('source') |
|
5010.2.17
by Vincent Ladeuil
Fix imports in per_branch/test_pull.py. |
276 |
branch.Branch.hooks.install_named_hook( |
277 |
'post_pull', self.capture_post_pull_hook, None) |
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
278 |
target.pull(source) |
279 |
# with nothing there we should still get a notification, and
|
|
280 |
# have both branches locked at the notification time.
|
|
281 |
self.assertEqual([ |
|
5010.2.17
by Vincent Ladeuil
Fix imports in per_branch/test_pull.py. |
282 |
('post_pull', source, None, target.base, 0, revision.NULL_REVISION, |
283 |
0, revision.NULL_REVISION, True, None, True) |
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
284 |
],
|
285 |
self.hook_calls) |
|
286 |
||
287 |
def test_post_pull_bound_branch(self): |
|
288 |
# pulling to a bound branch should pass in the master branch to the
|
|
289 |
# hook, allowing the correct number of emails to be sent, while still
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
290 |
# allowing hooks that want to modify the target to do so to both
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
291 |
# instances.
|
292 |
target = self.make_branch('target') |
|
293 |
local = self.make_branch('local') |
|
294 |
try: |
|
295 |
local.bind(target) |
|
296 |
except errors.UpgradeRequired: |
|
2477.1.2
by Martin Pool
Rename push/pull back to 'run_hooks' (jameinel) |
297 |
# We can't bind this format to itself- typically it is the local
|
298 |
# branch that doesn't support binding. As of May 2007
|
|
299 |
# remotebranches can't be bound. Let's instead make a new local
|
|
300 |
# branch of the default type, which does allow binding.
|
|
301 |
# See https://bugs.launchpad.net/bzr/+bug/112020
|
|
6472.2.2
by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places. |
302 |
local = controldir.ControlDir.create_branch_convenience('local2') |
2477.1.2
by Martin Pool
Rename push/pull back to 'run_hooks' (jameinel) |
303 |
local.bind(target) |
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
304 |
source = self.make_branch('source') |
5010.2.17
by Vincent Ladeuil
Fix imports in per_branch/test_pull.py. |
305 |
branch.Branch.hooks.install_named_hook( |
306 |
'post_pull', self.capture_post_pull_hook, None) |
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
307 |
local.pull(source) |
308 |
# with nothing there we should still get a notification, and
|
|
309 |
# have both branches locked at the notification time.
|
|
310 |
self.assertEqual([ |
|
5010.2.17
by Vincent Ladeuil
Fix imports in per_branch/test_pull.py. |
311 |
('post_pull', source, local.base, target.base, 0, |
312 |
revision.NULL_REVISION, 0, revision.NULL_REVISION, |
|
313 |
True, True, True) |
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
314 |
],
|
315 |
self.hook_calls) |
|
316 |
||
317 |
def test_post_pull_nonempty_history(self): |
|
318 |
target = self.make_branch_and_memory_tree('target') |
|
319 |
target.lock_write() |
|
320 |
target.add('') |
|
321 |
rev1 = target.commit('rev 1') |
|
322 |
target.unlock() |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
323 |
sourcedir = target.controldir.clone(self.get_url('source')) |
7467.4.17
by Jelmer Vernooij
Fix tests. |
324 |
source = sourcedir.open_branch().create_memorytree() |
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
325 |
rev2 = source.commit('rev 2') |
5010.2.17
by Vincent Ladeuil
Fix imports in per_branch/test_pull.py. |
326 |
branch.Branch.hooks.install_named_hook( |
327 |
'post_pull', self.capture_post_pull_hook, None) |
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
328 |
target.branch.pull(source.branch) |
329 |
# with nothing there we should still get a notification, and
|
|
330 |
# have both branches locked at the notification time.
|
|
331 |
self.assertEqual([ |
|
332 |
('post_pull', source.branch, None, target.branch.base, 1, rev1, |
|
333 |
2, rev2, True, None, True) |
|
334 |
],
|
|
335 |
self.hook_calls) |