bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
3221.11.3
by Robert Collins
Add missing test script. |
1 |
# Copyright (C) 2008 Canonical Ltd
|
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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
|
3537.3.3
by Martin Pool
Rename Branch.set_stacked_on to set_stacked_on_url |
17 |
"""Tests for Branch.get_stacked_on_url and set_stacked_on_url."""
|
|
3221.11.3
by Robert Collins
Add missing test script. |
18 |
|
|
3517.4.12
by Martin Pool
Clearer per-branch-format tests for stacking |
19 |
from bzrlib import ( |
20 |
bzrdir, |
|
21 |
errors, |
|
22 |
)
|
|
23 |
from bzrlib.revision import NULL_REVISION |
|
|
3242.3.40
by Aaron Bentley
Turn failing test into KnownFailure |
24 |
from bzrlib.tests import TestNotApplicable, KnownFailure |
|
3221.11.3
by Robert Collins
Add missing test script. |
25 |
from bzrlib.tests.branch_implementations import TestCaseWithBranch |
26 |
||
27 |
||
28 |
class TestStacking(TestCaseWithBranch): |
|
29 |
||
|
3537.3.3
by Martin Pool
Rename Branch.set_stacked_on to set_stacked_on_url |
30 |
def test_get_set_stacked_on_url(self): |
|
3221.11.3
by Robert Collins
Add missing test script. |
31 |
# branches must either:
|
32 |
# raise UnstackableBranchFormat or
|
|
33 |
# raise UnstackableRepositoryFormat or
|
|
34 |
# permit stacking to be done and then return the stacked location.
|
|
35 |
branch = self.make_branch('branch') |
|
36 |
target = self.make_branch('target') |
|
37 |
old_format_errors = ( |
|
38 |
errors.UnstackableBranchFormat, |
|
39 |
errors.UnstackableRepositoryFormat, |
|
40 |
)
|
|
41 |
try: |
|
|
3537.3.3
by Martin Pool
Rename Branch.set_stacked_on to set_stacked_on_url |
42 |
branch.set_stacked_on_url(target.base) |
|
3221.11.3
by Robert Collins
Add missing test script. |
43 |
except old_format_errors: |
44 |
# if the set failed, so must the get
|
|
|
3537.3.1
by Martin Pool
Rename branch.get_stacked_on to get_stacked_on_url |
45 |
self.assertRaises(old_format_errors, branch.get_stacked_on_url) |
|
3221.11.3
by Robert Collins
Add missing test script. |
46 |
return
|
47 |
# now we have a stacked branch:
|
|
|
3537.3.1
by Martin Pool
Rename branch.get_stacked_on to get_stacked_on_url |
48 |
self.assertEqual(target.base, branch.get_stacked_on_url()) |
|
3537.3.3
by Martin Pool
Rename Branch.set_stacked_on to set_stacked_on_url |
49 |
branch.set_stacked_on_url(None) |
|
3537.3.1
by Martin Pool
Rename branch.get_stacked_on to get_stacked_on_url |
50 |
self.assertRaises(errors.NotStacked, branch.get_stacked_on_url) |
|
3221.13.2
by Robert Collins
Add a shallow parameter to bzrdir.sprout, which involved fixing a lateny bug in pack to pack fetching with ghost discovery. |
51 |
|
|
3242.5.1
by Jonathan Lange
Allow stacked-on branch locations to be stored as relative URLs. |
52 |
def test_get_set_stacked_on_relative(self): |
53 |
# Branches can be stacked on other branches using relative paths.
|
|
54 |
branch = self.make_branch('branch') |
|
55 |
target = self.make_branch('target') |
|
56 |
old_format_errors = ( |
|
57 |
errors.UnstackableBranchFormat, |
|
58 |
errors.UnstackableRepositoryFormat, |
|
59 |
)
|
|
60 |
try: |
|
|
3537.3.5
by Martin Pool
merge trunk including stacking policy |
61 |
branch.set_stacked_on_url('../target') |
|
3242.5.1
by Jonathan Lange
Allow stacked-on branch locations to be stored as relative URLs. |
62 |
except old_format_errors: |
63 |
# if the set failed, so must the get
|
|
|
3537.3.5
by Martin Pool
merge trunk including stacking policy |
64 |
self.assertRaises(old_format_errors, branch.get_stacked_on_url) |
|
3242.5.1
by Jonathan Lange
Allow stacked-on branch locations to be stored as relative URLs. |
65 |
return
|
|
3537.3.5
by Martin Pool
merge trunk including stacking policy |
66 |
self.assertEqual('../target', branch.get_stacked_on_url()) |
|
3242.5.1
by Jonathan Lange
Allow stacked-on branch locations to be stored as relative URLs. |
67 |
|
|
3517.4.12
by Martin Pool
Clearer per-branch-format tests for stacking |
68 |
def assertRevisionInRepository(self, repo_path, revid): |
69 |
"""Check that a revision is in a repository, disregarding stacking.""" |
|
70 |
repo = bzrdir.BzrDir.open(repo_path).open_repository() |
|
71 |
self.assertTrue(repo.has_revision(revid)) |
|
72 |
||
73 |
def assertRevisionNotInRepository(self, repo_path, revid): |
|
74 |
"""Check that a revision is not in a repository, disregarding stacking.""" |
|
75 |
repo = bzrdir.BzrDir.open(repo_path).open_repository() |
|
76 |
self.assertFalse(repo.has_revision(revid)) |
|
77 |
||
78 |
def test_get_graph_stacked(self): |
|
79 |
"""A stacked repository shows the graph of its parent.""" |
|
80 |
trunk_tree = self.make_branch_and_tree('mainline') |
|
81 |
trunk_revid = trunk_tree.commit('mainline') |
|
82 |
# make a new branch, and stack on the existing one. we don't use
|
|
83 |
# sprout(stacked=True) here because if that is buggy and copies data
|
|
84 |
# it would cause a false pass of this test.
|
|
85 |
new_branch = self.make_branch('new_branch') |
|
86 |
try: |
|
|
3537.3.3
by Martin Pool
Rename Branch.set_stacked_on to set_stacked_on_url |
87 |
new_branch.set_stacked_on_url(trunk_tree.branch.base) |
|
3517.4.12
by Martin Pool
Clearer per-branch-format tests for stacking |
88 |
except (errors.UnstackableBranchFormat, |
89 |
errors.UnstackableRepositoryFormat), e: |
|
90 |
raise TestNotApplicable(e) |
|
91 |
# reading the graph from the stacked branch's repository should see
|
|
92 |
# data from the stacked-on branch
|
|
93 |
new_repo = new_branch.repository |
|
94 |
new_repo.lock_read() |
|
95 |
try: |
|
96 |
self.assertEqual(new_repo.get_parent_map([trunk_revid]), |
|
97 |
{trunk_revid: (NULL_REVISION, )}) |
|
98 |
finally: |
|
99 |
new_repo.unlock() |
|
100 |
||
101 |
def test_sprout_stacked(self): |
|
|
3221.13.2
by Robert Collins
Add a shallow parameter to bzrdir.sprout, which involved fixing a lateny bug in pack to pack fetching with ghost discovery. |
102 |
# We have a mainline
|
103 |
trunk_tree = self.make_branch_and_tree('mainline') |
|
104 |
trunk_revid = trunk_tree.commit('mainline') |
|
|
3221.18.4
by Ian Clatworthy
shallow -> stacked |
105 |
# and make branch from it which is stacked
|
|
3221.13.2
by Robert Collins
Add a shallow parameter to bzrdir.sprout, which involved fixing a lateny bug in pack to pack fetching with ghost discovery. |
106 |
try: |
|
3221.18.4
by Ian Clatworthy
shallow -> stacked |
107 |
new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True) |
108 |
except (errors.UnstackableBranchFormat, |
|
|
3517.4.12
by Martin Pool
Clearer per-branch-format tests for stacking |
109 |
errors.UnstackableRepositoryFormat), e: |
110 |
raise TestNotApplicable(e) |
|
111 |
# stacked repository
|
|
112 |
self.assertRevisionNotInRepository('newbranch', trunk_revid) |
|
|
3221.13.2
by Robert Collins
Add a shallow parameter to bzrdir.sprout, which involved fixing a lateny bug in pack to pack fetching with ghost discovery. |
113 |
new_tree = new_dir.open_workingtree() |
|
3537.3.4
by Martin Pool
Improved branch stacking tests |
114 |
new_branch_revid = new_tree.commit('something local') |
115 |
self.assertRevisionNotInRepository('mainline', new_branch_revid) |
|
116 |
self.assertRevisionInRepository('newbranch', new_branch_revid) |
|
117 |
||
118 |
def test_unstack_fetches(self): |
|
119 |
"""Removing the stacked-on branch pulls across all data""" |
|
120 |
# We have a mainline
|
|
121 |
trunk_tree = self.make_branch_and_tree('mainline') |
|
122 |
trunk_revid = trunk_tree.commit('revision on mainline') |
|
123 |
# and make branch from it which is stacked
|
|
124 |
try: |
|
125 |
new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True) |
|
126 |
except (errors.UnstackableBranchFormat, |
|
127 |
errors.UnstackableRepositoryFormat), e: |
|
128 |
raise TestNotApplicable(e) |
|
129 |
# stacked repository
|
|
130 |
self.assertRevisionNotInRepository('newbranch', trunk_revid) |
|
131 |
# now when we unstack that should implicitly fetch, to make sure that
|
|
132 |
# the branch will still work
|
|
133 |
new_branch = new_dir.open_branch() |
|
134 |
new_branch.set_stacked_on_url(None) |
|
135 |
self.assertRevisionInRepository('newbranch', trunk_revid) |
|
136 |
# of course it's still in the mainline
|
|
137 |
self.assertRevisionInRepository('mainline', trunk_revid) |
|
138 |
# and now we're no longer stacked
|
|
|
3537.3.5
by Martin Pool
merge trunk including stacking policy |
139 |
self.assertRaises(errors.NotStacked, |
140 |
new_branch.get_stacked_on_url) |
|
|
3221.13.2
by Robert Collins
Add a shallow parameter to bzrdir.sprout, which involved fixing a lateny bug in pack to pack fetching with ghost discovery. |
141 |
|
|
3242.3.40
by Aaron Bentley
Turn failing test into KnownFailure |
142 |
def prepare_for_clone(self): |
143 |
tree = self.make_branch_and_tree('stacked-on') |
|
144 |
tree.commit('Added foo') |
|
145 |
stacked_bzrdir = tree.branch.bzrdir.sprout( |
|
146 |
'stacked', tree.branch.last_revision(), stacked=True) |
|
147 |
return stacked_bzrdir |
|
148 |
||
149 |
def test_clone_from_stacked_branch_preserve_stacking(self): |
|
|
3242.3.24
by Aaron Bentley
Fix test failures |
150 |
# We can clone from the bzrdir of a stacked branch. If
|
151 |
# preserve_stacking is True, the cloned branch is stacked on the
|
|
152 |
# same branch as the original.
|
|
|
3242.3.21
by Jonathan Lange
Preserve stacking in clone |
153 |
try: |
|
3242.3.40
by Aaron Bentley
Turn failing test into KnownFailure |
154 |
stacked_bzrdir = self.prepare_for_clone() |
|
3242.3.21
by Jonathan Lange
Preserve stacking in clone |
155 |
except (errors.UnstackableBranchFormat, |
156 |
errors.UnstackableRepositoryFormat): |
|
157 |
# not a testable combination.
|
|
158 |
return
|
|
|
3242.3.24
by Aaron Bentley
Fix test failures |
159 |
cloned_bzrdir = stacked_bzrdir.clone('cloned', preserve_stacking=True) |
|
3242.3.21
by Jonathan Lange
Preserve stacking in clone |
160 |
try: |
161 |
self.assertEqual( |
|
|
3537.3.5
by Martin Pool
merge trunk including stacking policy |
162 |
stacked_bzrdir.open_branch().get_stacked_on_url(), |
163 |
cloned_bzrdir.open_branch().get_stacked_on_url()) |
|
|
3242.3.21
by Jonathan Lange
Preserve stacking in clone |
164 |
except (errors.UnstackableBranchFormat, |
165 |
errors.UnstackableRepositoryFormat): |
|
166 |
pass
|
|
|
3242.3.40
by Aaron Bentley
Turn failing test into KnownFailure |
167 |
|
168 |
def test_clone_from_stacked_branch_no_preserve_stacking(self): |
|
169 |
try: |
|
170 |
stacked_bzrdir = self.prepare_for_clone() |
|
171 |
except (errors.UnstackableBranchFormat, |
|
172 |
errors.UnstackableRepositoryFormat): |
|
173 |
# not a testable combination.
|
|
174 |
return
|
|
|
1551.19.46
by Aaron Bentley
Fix fetch from stacked respositories (#248506) |
175 |
cloned_unstacked_bzrdir = stacked_bzrdir.clone('cloned-unstacked', |
176 |
preserve_stacking=False) |
|
|
3242.3.24
by Aaron Bentley
Fix test failures |
177 |
unstacked_branch = cloned_unstacked_bzrdir.open_branch() |
|
3242.3.37
by Aaron Bentley
Updates from reviews |
178 |
self.assertRaises((errors.NotStacked, errors.UnstackableBranchFormat), |
|
3537.3.5
by Martin Pool
merge trunk including stacking policy |
179 |
unstacked_branch.get_stacked_on_url) |
|
3242.3.37
by Aaron Bentley
Updates from reviews |
180 |
|
181 |
def test_no_op_preserve_stacking(self): |
|
182 |
"""With no stacking, preserve_stacking should be a no-op.""" |
|
183 |
branch = self.make_branch('source') |
|
184 |
cloned_bzrdir = branch.bzrdir.clone('cloned', preserve_stacking=True) |
|
185 |
self.assertRaises((errors.NotStacked, errors.UnstackableBranchFormat), |
|
|
3537.3.5
by Martin Pool
merge trunk including stacking policy |
186 |
cloned_bzrdir.open_branch().get_stacked_on_url) |
|
3242.3.37
by Aaron Bentley
Updates from reviews |
187 |
|
188 |
def test_sprout_stacking_policy_handling(self): |
|
189 |
"""Obey policy where possible, ignore otherwise.""" |
|
190 |
stack_on = self.make_branch('stack-on') |
|
191 |
parent_bzrdir = self.make_bzrdir('.', format='default') |
|
192 |
parent_bzrdir.get_config().set_default_stack_on('stack-on') |
|
193 |
source = self.make_branch('source') |
|
194 |
target = source.bzrdir.sprout('target').open_branch() |
|
|
3242.3.38
by Aaron Bentley
Enhance tests |
195 |
try: |
|
3537.3.5
by Martin Pool
merge trunk including stacking policy |
196 |
self.assertEqual('../stack-on', target.get_stacked_on_url()) |
|
3242.3.38
by Aaron Bentley
Enhance tests |
197 |
except errors.UnstackableBranchFormat: |
198 |
pass
|
|
199 |
||
200 |
def test_clone_stacking_policy_handling(self): |
|
201 |
"""Obey policy where possible, ignore otherwise.""" |
|
202 |
stack_on = self.make_branch('stack-on') |
|
203 |
parent_bzrdir = self.make_bzrdir('.', format='default') |
|
204 |
parent_bzrdir.get_config().set_default_stack_on('stack-on') |
|
205 |
source = self.make_branch('source') |
|
206 |
target = source.bzrdir.clone('target').open_branch() |
|
207 |
try: |
|
|
3537.3.5
by Martin Pool
merge trunk including stacking policy |
208 |
self.assertEqual('../stack-on', target.get_stacked_on_url()) |
|
3242.3.38
by Aaron Bentley
Enhance tests |
209 |
except errors.UnstackableBranchFormat: |
210 |
pass
|
|
|
1551.19.46
by Aaron Bentley
Fix fetch from stacked respositories (#248506) |
211 |
|
|
1551.19.47
by Aaron Bentley
Add test per JAM |
212 |
def prepare_stacked_on_fetch(self): |
|
1551.19.46
by Aaron Bentley
Fix fetch from stacked respositories (#248506) |
213 |
stack_on = self.make_branch_and_tree('stack-on') |
214 |
stack_on.commit('first commit', rev_id='rev1') |
|
215 |
try: |
|
216 |
stacked_dir = stack_on.bzrdir.sprout('stacked', stacked=True) |
|
217 |
except (errors.UnstackableRepositoryFormat, |
|
218 |
errors.UnstackableBranchFormat): |
|
219 |
raise TestNotApplicable('Format does not support stacking.') |
|
220 |
unstacked = self.make_repository('unstacked') |
|
|
1551.19.47
by Aaron Bentley
Add test per JAM |
221 |
return stacked_dir.open_workingtree(), unstacked |
222 |
||
223 |
def test_fetch_copies_from_stacked_on(self): |
|
224 |
stacked, unstacked = self.prepare_stacked_on_fetch() |
|
225 |
unstacked.fetch(stacked.branch.repository, 'rev1') |
|
226 |
unstacked.get_revision('rev1') |
|
227 |
||
228 |
def test_fetch_copies_from_stacked_on_and_stacked(self): |
|
229 |
stacked, unstacked = self.prepare_stacked_on_fetch() |
|
230 |
stacked.commit('second commit', rev_id='rev2') |
|
231 |
unstacked.fetch(stacked.branch.repository, 'rev2') |
|
232 |
unstacked.get_revision('rev1') |
|
233 |
unstacked.get_revision('rev2') |