24
24
from bzrlib.revision import NULL_REVISION
25
25
from bzrlib.smart import server
26
from bzrlib.tests import TestNotApplicable, KnownFailure
26
from bzrlib.tests import TestNotApplicable, KnownFailure, transport_util
27
27
from bzrlib.tests.branch_implementations import TestCaseWithBranch
28
28
from bzrlib.transport import get_transport
31
unstackable_format_errors = (
32
errors.UnstackableBranchFormat,
33
errors.UnstackableRepositoryFormat,
31
37
class TestStacking(TestCaseWithBranch):
33
39
def check_lines_added_or_present(self, stacked_branch, revid):
47
53
# permit stacking to be done and then return the stacked location.
48
54
branch = self.make_branch('branch')
49
55
target = self.make_branch('target')
51
errors.UnstackableBranchFormat,
52
errors.UnstackableRepositoryFormat,
55
57
branch.set_stacked_on_url(target.base)
56
except old_format_errors:
58
except unstackable_format_errors:
57
59
# if the set failed, so must the get
58
self.assertRaises(old_format_errors, branch.get_stacked_on_url)
60
self.assertRaises(unstackable_format_errors, branch.get_stacked_on_url)
60
62
# now we have a stacked branch:
61
63
self.assertEqual(target.base, branch.get_stacked_on_url())
66
68
# Branches can be stacked on other branches using relative paths.
67
69
branch = self.make_branch('branch')
68
70
target = self.make_branch('target')
70
errors.UnstackableBranchFormat,
71
errors.UnstackableRepositoryFormat,
74
72
branch.set_stacked_on_url('../target')
75
except old_format_errors:
73
except unstackable_format_errors:
76
74
# if the set failed, so must the get
77
self.assertRaises(old_format_errors, branch.get_stacked_on_url)
75
self.assertRaises(unstackable_format_errors, branch.get_stacked_on_url)
79
77
self.assertEqual('../target', branch.get_stacked_on_url())
98
96
new_branch = self.make_branch('new_branch')
100
98
new_branch.set_stacked_on_url(trunk_tree.branch.base)
101
except (errors.UnstackableBranchFormat,
102
errors.UnstackableRepositoryFormat), e:
99
except unstackable_format_errors, e:
103
100
raise TestNotApplicable(e)
104
101
# reading the graph from the stacked branch's repository should see
105
102
# data from the stacked-on branch
118
115
# and make branch from it which is stacked
120
117
new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
121
except (errors.UnstackableBranchFormat,
122
errors.UnstackableRepositoryFormat), e:
118
except unstackable_format_errors, e:
123
119
raise TestNotApplicable(e)
124
120
# stacked repository
125
121
self.assertRevisionNotInRepository('newbranch', trunk_revid)
145
141
# Make sure that we can make a stacked branch from it
147
143
trunk_tree.bzrdir.sprout('testbranch', stacked=True)
148
except (errors.UnstackableBranchFormat,
149
errors.UnstackableRepositoryFormat), e:
144
except unstackable_format_errors, e:
150
145
raise TestNotApplicable(e)
151
146
# Now serve the original mainline from a smart server
152
147
remote_transport = self.make_smart_server('mainline')
168
163
# and make branch from it which is stacked
170
165
new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
171
except (errors.UnstackableBranchFormat,
172
errors.UnstackableRepositoryFormat), e:
166
except unstackable_format_errors, e:
173
167
raise TestNotApplicable(e)
174
168
# stacked repository
175
169
self.assertRevisionNotInRepository('newbranch', trunk_revid)
208
202
# same branch as the original.
210
204
stacked_bzrdir = self.make_stacked_bzrdir()
211
except (errors.UnstackableBranchFormat,
212
errors.UnstackableRepositoryFormat), e:
213
# not a testable combination.
205
except unstackable_format_errors, e:
214
206
raise TestNotApplicable(e)
215
207
cloned_bzrdir = stacked_bzrdir.clone('cloned', preserve_stacking=True)
217
209
self.assertEqual(
218
210
stacked_bzrdir.open_branch().get_stacked_on_url(),
219
211
cloned_bzrdir.open_branch().get_stacked_on_url())
220
except (errors.UnstackableBranchFormat,
221
errors.UnstackableRepositoryFormat):
212
except unstackable_format_errors, e:
224
215
def test_clone_from_branch_stacked_on_relative_url_preserve_stacking(self):
227
218
# on an appropriately adjusted relative url.
229
220
stacked_bzrdir = self.make_stacked_bzrdir(in_directory='dir')
230
except (errors.UnstackableBranchFormat,
231
errors.UnstackableRepositoryFormat), e:
232
# not a testable combination.
221
except unstackable_format_errors, e:
233
222
raise TestNotApplicable(e)
234
223
stacked_bzrdir.open_branch().set_stacked_on_url('../stacked-on')
235
224
cloned_bzrdir = stacked_bzrdir.clone('cloned', preserve_stacking=True)
240
229
def test_clone_from_stacked_branch_no_preserve_stacking(self):
242
231
stacked_bzrdir = self.make_stacked_bzrdir()
243
except (errors.UnstackableBranchFormat,
244
errors.UnstackableRepositoryFormat), e:
232
except unstackable_format_errors, e:
245
233
# not a testable combination.
246
234
raise TestNotApplicable(e)
247
235
cloned_unstacked_bzrdir = stacked_bzrdir.clone('cloned-unstacked',
286
274
stack_on.commit('first commit', rev_id='rev1')
288
276
stacked_dir = stack_on.bzrdir.sprout('stacked', stacked=True)
289
except (errors.UnstackableRepositoryFormat,
290
errors.UnstackableBranchFormat):
277
except unstackable_format_errors, e:
291
278
raise TestNotApplicable('Format does not support stacking.')
292
279
unstacked = self.make_repository('unstacked')
293
280
return stacked_dir.open_workingtree(), unstacked
370
357
target = self.make_branch('target')
372
359
target.set_stacked_on_url('../stacked-on')
373
except (errors.UnstackableRepositoryFormat,
374
errors.UnstackableBranchFormat):
360
except unstackable_format_errors, e:
375
361
raise TestNotApplicable('Format does not support stacking.')
377
363
# Change the source branch.
393
379
stacked = self.make_branch('stacked')
395
381
stacked.set_stacked_on_url('../stack-on')
396
except (errors.UnstackableRepositoryFormat,
397
errors.UnstackableBranchFormat):
382
except unstackable_format_errors, e:
398
383
raise TestNotApplicable('Format does not support stacking.')
399
384
self.get_transport().rename('stack-on', 'new-stack-on')
423
408
b.bzrdir.clone_on_transport(transport, stacked_on=b.base)
424
409
# Ensure that opening the branch doesn't raise.
425
410
branch.Branch.open(transport.base)
413
class TestStackingConnections(
414
transport_util.TestCaseWithConnectionHookedTransport):
417
super(TestStackingConnections, self).setUp()
419
base_tree = self.make_branch_and_tree('base',
420
format=self.bzrdir_format)
421
except errors.UninitializableFormat, e:
422
raise TestNotApplicable(e)
423
stacked = self.make_branch('stacked', format=self.bzrdir_format)
425
stacked.set_stacked_on_url(base_tree.branch.base)
426
except unstackable_format_errors, e:
427
raise TestNotApplicable(e)
428
base_tree.commit('first', rev_id='rev-base')
429
stacked.set_last_revision_info(1, 'rev-base')
430
stacked_relative = self.make_branch('stacked_relative',
431
format=self.bzrdir_format)
432
stacked_relative.set_stacked_on_url('../base')
433
stacked.set_last_revision_info(1, 'rev-base')
434
self.start_logging_connections()
436
def test_open_stacked(self):
437
b = branch.Branch.open(self.get_url('stacked'))
438
rev = b.repository.get_revision('rev-base')
439
self.assertEqual(1, len(self.connections))
441
def test_open_stacked_relative(self):
442
b = branch.Branch.open(self.get_url('stacked_relative'))
443
rev = b.repository.get_revision('rev-base')
444
self.assertEqual(1, len(self.connections))