19
19
from bzrlib import (
24
25
from bzrlib.revision import NULL_REVISION
25
26
from bzrlib.smart import server
26
27
from bzrlib.tests import TestNotApplicable, KnownFailure, transport_util
27
from bzrlib.tests.branch_implementations import TestCaseWithBranch
28
from bzrlib.tests.per_branch import TestCaseWithBranch
28
29
from bzrlib.transport import get_transport
149
150
raise TestNotApplicable(e)
150
151
# stacked repository
151
152
self.assertRevisionNotInRepository('newbranch', trunk_revid)
152
new_tree = new_dir.open_workingtree()
153
new_branch_revid = new_tree.commit('something local')
153
tree = new_dir.open_branch().create_checkout('local')
154
new_branch_revid = tree.commit('something local')
154
155
self.assertRevisionNotInRepository('mainline', new_branch_revid)
155
156
self.assertRevisionInRepository('newbranch', new_branch_revid)
172
173
new_dir = remote_bzrdir.sprout('newbranch', stacked=True)
173
174
# stacked repository
174
175
self.assertRevisionNotInRepository('newbranch', trunk_revid)
175
new_tree = new_dir.open_workingtree()
176
new_branch_revid = new_tree.commit('something local')
176
tree = new_dir.open_branch().create_checkout('local')
177
new_branch_revid = tree.commit('something local')
177
178
self.assertRevisionNotInRepository('mainline', new_branch_revid)
178
179
self.assertRevisionInRepository('newbranch', new_branch_revid)
184
185
trunk_revid = trunk_tree.commit('revision on mainline')
185
186
# and make branch from it which is stacked
187
new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
188
new_dir = trunk_tree.bzrdir.sprout(self.get_url('newbranch'),
188
190
except unstackable_format_errors, e:
189
191
raise TestNotApplicable(e)
190
192
# stacked repository
191
193
self.assertRevisionNotInRepository('newbranch', trunk_revid)
194
# TODO: we'd like to commit in the stacked repository; that requires
195
# some care (maybe a BranchBuilder) if it's remote and has no
197
##newbranch_revid = new_dir.open_workingtree().commit('revision in '
192
199
# now when we unstack that should implicitly fetch, to make sure that
193
200
# the branch will still work
194
201
new_branch = new_dir.open_branch()
267
274
self.assertRaises((errors.NotStacked, errors.UnstackableBranchFormat),
268
275
cloned_bzrdir.open_branch().get_stacked_on_url)
277
def make_stacked_on_matching(self, source):
278
if source.repository.supports_rich_root():
279
if source.repository._format.supports_chks:
282
format = "1.9-rich-root"
285
return self.make_branch('stack-on', format)
270
287
def test_sprout_stacking_policy_handling(self):
271
288
"""Obey policy where possible, ignore otherwise."""
272
stack_on = self.make_branch('stack-on')
289
if isinstance(self.branch_format, branch.BzrBranchFormat4):
290
raise TestNotApplicable('Branch format 4 does not autoupgrade.')
291
source = self.make_branch('source')
292
stack_on = self.make_stacked_on_matching(source)
273
293
parent_bzrdir = self.make_bzrdir('.', format='default')
274
294
parent_bzrdir.get_config().set_default_stack_on('stack-on')
275
source = self.make_branch('source')
276
295
target = source.bzrdir.sprout('target').open_branch()
277
if self.branch_format.supports_stacking():
296
# When we sprout we upgrade the branch when there is a default stack_on
297
# set by a config *and* the targeted branch supports stacking.
298
if stack_on._format.supports_stacking():
278
299
self.assertEqual('../stack-on', target.get_stacked_on_url())
280
301
self.assertRaises(
283
304
def test_clone_stacking_policy_handling(self):
284
305
"""Obey policy where possible, ignore otherwise."""
285
stack_on = self.make_branch('stack-on')
306
if isinstance(self.branch_format, branch.BzrBranchFormat4):
307
raise TestNotApplicable('Branch format 4 does not autoupgrade.')
308
source = self.make_branch('source')
309
stack_on = self.make_stacked_on_matching(source)
286
310
parent_bzrdir = self.make_bzrdir('.', format='default')
287
311
parent_bzrdir.get_config().set_default_stack_on('stack-on')
288
source = self.make_branch('source')
289
312
target = source.bzrdir.clone('target').open_branch()
290
if self.branch_format.supports_stacking():
313
# When we clone we upgrade the branch when there is a default stack_on
314
# set by a config *and* the targeted branch supports stacking.
315
if stack_on._format.supports_stacking():
291
316
self.assertEqual('../stack-on', target.get_stacked_on_url())
293
318
self.assertRaises(
297
322
"""Obey policy where possible, ignore otherwise."""
298
323
if isinstance(self.branch_format, branch.BzrBranchFormat4):
299
324
raise TestNotApplicable('Branch format 4 is not usable via HPSS.')
300
stack_on = self.make_branch('stack-on')
325
source = self.make_branch('source')
326
stack_on = self.make_stacked_on_matching(source)
301
327
parent_bzrdir = self.make_bzrdir('.', format='default')
302
328
parent_bzrdir.get_config().set_default_stack_on('stack-on')
303
source = self.make_branch('source')
304
329
url = self.make_smart_server('target').base
305
330
target = source.bzrdir.sprout(url).open_branch()
306
if self.branch_format.supports_stacking():
331
# When we sprout we upgrade the branch when there is a default stack_on
332
# set by a config *and* the targeted branch supports stacking.
333
if stack_on._format.supports_stacking():
307
334
self.assertEqual('../stack-on', target.get_stacked_on_url())
309
336
self.assertRaises(
327
354
def test_fetch_copies_from_stacked_on_and_stacked(self):
328
355
stacked, unstacked = self.prepare_stacked_on_fetch()
329
stacked.commit('second commit', rev_id='rev2')
356
tree = stacked.branch.create_checkout('local')
357
tree.commit('second commit', rev_id='rev2')
330
358
unstacked.fetch(stacked.branch.repository, 'rev2')
331
359
unstacked.get_revision('rev1')
332
360
unstacked.get_revision('rev2')
339
367
# repository boundaries. however, i didn't actually get this test to
340
368
# fail on that code. -- mbp
341
369
# see https://bugs.launchpad.net/bzr/+bug/252821
342
if not self.branch_format.supports_stacking():
370
stack_on = self.make_branch_and_tree('stack-on')
371
if not stack_on.branch._format.supports_stacking():
343
372
raise TestNotApplicable("%r does not support stacking"
344
373
% self.branch_format)
345
stack_on = self.make_branch_and_tree('stack-on')
346
374
text_lines = ['line %d blah blah blah\n' % i for i in range(20)]
347
375
self.build_tree_contents([('stack-on/a', ''.join(text_lines))])
348
376
stack_on.add('a')
349
377
stack_on.commit('base commit')
350
378
stacked_dir = stack_on.bzrdir.sprout('stacked', stacked=True)
351
stacked_tree = stacked_dir.open_workingtree()
379
stacked_branch = stacked_dir.open_branch()
380
local_tree = stack_on.bzrdir.sprout('local').open_workingtree()
352
381
for i in range(20):
353
382
text_lines[0] = 'changed in %d\n' % i
354
self.build_tree_contents([('stacked/a', ''.join(text_lines))])
355
stacked_tree.commit('commit %d' % i)
356
stacked_tree.branch.repository.pack()
357
stacked_tree.branch.check()
383
self.build_tree_contents([('local/a', ''.join(text_lines))])
384
local_tree.commit('commit %d' % i)
385
local_tree.branch.push(stacked_branch)
386
stacked_branch.repository.pack()
387
check.check_dwim(stacked_branch.base, False, True, True)
359
389
def test_pull_delta_when_stacked(self):
360
390
if not self.branch_format.supports_stacking():
378
408
# bug 252821 caused a RevisionNotPresent here...
379
409
stacked_tree.pull(other_tree.branch)
380
410
stacked_tree.branch.repository.pack()
381
stacked_tree.branch.check()
411
check.check_dwim(stacked_tree.branch.base, False, True, True)
382
412
self.check_lines_added_or_present(stacked_tree.branch, stacked_revid)
384
414
def test_fetch_revisions_with_file_changes(self):
463
493
except errors.NoWorkingTree:
464
494
stacked = stacked_dir.open_branch().create_checkout(
465
495
'stacked-checkout', lightweight=True)
466
stacked.commit('second commit', rev_id='rev2')
496
tree = stacked.branch.create_checkout('local')
497
tree.commit('second commit', rev_id='rev2')
467
498
# Sanity check: stacked's repo should not contain rev1, otherwise this
468
499
# test isn't testing what it's supposed to.
469
500
repo = stacked.branch.repository.bzrdir.open_repository()