98
99
def test_from_colocated(self):
99
100
"""Branch from a colocated branch into a regular branch."""
101
tree = self.example_branch('b/a', format='development-colo')
101
tree = self.example_branch('a', format='development-colo')
102
102
tree.controldir.create_branch(name='somecolo')
103
103
out, err = self.run_bzr('branch %s,branch=somecolo' %
104
local_path_to_url('b/a'))
105
self.assertEqual('', out)
106
self.assertEqual('Branched 0 revisions.\n', err)
107
self.assertPathExists('a')
109
def test_from_name(self):
110
"""Branch from a colocated branch into a regular branch."""
112
tree = self.example_branch('b/a', format='development-colo')
113
tree.controldir.create_branch(name='somecolo')
114
out, err = self.run_bzr('branch -b somecolo %s' %
115
local_path_to_url('b/a'))
116
self.assertEqual('', out)
117
self.assertEqual('Branched 0 revisions.\n', err)
118
self.assertPathExists('a')
104
local_path_to_url('a'))
105
self.assertEqual('', out)
106
self.assertEqual('Branched 0 revisions.\n', err)
107
self.assertPathExists("somecolo")
120
109
def test_branch_broken_pack(self):
121
110
"""branching with a corrupted pack file."""
227
216
tree_a = make_shared_tree('a')
228
217
self.build_tree(['repo/a/file'])
229
218
tree_a.add('file')
230
tree_a.commit('commit a-1', rev_id=b'a-1')
231
with open('repo/a/file', 'ab') as f:
232
f.write(b'more stuff\n')
233
tree_a.commit('commit a-2', rev_id=b'a-2')
219
tree_a.commit('commit a-1', rev_id='a-1')
220
f = open('repo/a/file', 'ab')
221
f.write('more stuff\n')
223
tree_a.commit('commit a-2', rev_id='a-2')
235
225
tree_b = make_shared_tree('b')
236
226
self.build_tree(['repo/b/file'])
237
227
tree_b.add('file')
238
tree_b.commit('commit b-1', rev_id=b'b-1')
228
tree_b.commit('commit b-1', rev_id='b-1')
240
self.assertTrue(shared_repo.has_revision(b'a-1'))
241
self.assertTrue(shared_repo.has_revision(b'a-2'))
242
self.assertTrue(shared_repo.has_revision(b'b-1'))
230
self.assertTrue(shared_repo.has_revision('a-1'))
231
self.assertTrue(shared_repo.has_revision('a-2'))
232
self.assertTrue(shared_repo.has_revision('b-1'))
244
234
# Now that we have a repository with shared files, make sure
245
235
# that things aren't copied out by a 'branch'
246
236
self.run_bzr('branch repo/b branch-b')
247
237
pushed_tree = WorkingTree.open('branch-b')
248
238
pushed_repo = pushed_tree.branch.repository
249
self.assertFalse(pushed_repo.has_revision(b'a-1'))
250
self.assertFalse(pushed_repo.has_revision(b'a-2'))
251
self.assertTrue(pushed_repo.has_revision(b'b-1'))
239
self.assertFalse(pushed_repo.has_revision('a-1'))
240
self.assertFalse(pushed_repo.has_revision('a-2'))
241
self.assertTrue(pushed_repo.has_revision('b-1'))
253
243
def test_branch_hardlink(self):
254
244
self.requireFeature(HardlinkFeature)
370
359
self.assertEqual(rev2, new_branch.tags.lookup_tag('tag-a'))
371
360
new_branch.repository.get_revision(rev2)
373
def test_branch_with_nested_trees(self):
374
orig = self.make_branch_and_tree('source', format='development-subtree')
375
subtree = self.make_branch_and_tree('source/subtree')
376
self.build_tree(['source/subtree/a'])
378
subtree.commit('add subtree contents')
379
orig.add_reference(subtree)
380
orig.set_reference_info('subtree', subtree.branch.user_url)
381
orig.commit('add subtree')
383
self.run_bzr('branch source target')
385
target = WorkingTree.open('target')
386
target_subtree = WorkingTree.open('target/subtree')
387
self.assertTreesEqual(orig, target)
388
self.assertTreesEqual(subtree, target_subtree)
390
def test_branch_with_nested_trees_reference_unset(self):
391
orig = self.make_branch_and_tree('source', format='development-subtree')
392
subtree = self.make_branch_and_tree('source/subtree')
393
self.build_tree(['source/subtree/a'])
395
subtree.commit('add subtree contents')
396
orig.add_reference(subtree)
397
orig.commit('add subtree')
399
self.run_bzr('branch source target')
401
target = WorkingTree.open('target')
402
self.assertRaises(errors.NotBranchError, WorkingTree.open, 'target/subtree')
404
def test_branch_with_nested_trees_no_recurse(self):
405
orig = self.make_branch_and_tree('source', format='development-subtree')
406
subtree = self.make_branch_and_tree('source/subtree')
407
self.build_tree(['source/subtree/a'])
409
subtree.commit('add subtree contents')
410
orig.add_reference(subtree)
411
orig.commit('add subtree')
413
self.run_bzr('branch --no-recurse-nested source target')
415
target = WorkingTree.open('target')
416
self.addCleanup(subtree.lock_read().unlock)
417
basis = subtree.basis_tree()
418
self.addCleanup(basis.lock_read().unlock)
419
self.assertRaises(errors.NotBranchError, WorkingTree.open, 'target/subtree')
422
363
class TestBranchStacked(tests.TestCaseWithTransport):
423
364
"""Tests for branch --stacked"""
435
376
def assertRevisionsInBranchRepository(self, revid_list, branch_path):
436
377
repo = branch.Branch.open(branch_path).repository
437
378
self.assertEqual(set(revid_list),
438
repo.has_revisions(revid_list))
379
repo.has_revisions(revid_list))
440
381
def test_branch_stacked_branch_not_stacked(self):
441
382
"""Branching a stacked branch is not stacked by default"""
442
383
# We have a mainline
443
384
trunk_tree = self.make_branch_and_tree('target',
445
386
trunk_tree.commit('mainline')
446
387
# and a branch from it which is stacked
447
388
branch_tree = self.make_branch_and_tree('branch',
449
390
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
450
391
# with some work on it
451
work_tree = trunk_tree.branch.controldir.sprout(
452
'local').open_workingtree()
392
work_tree = trunk_tree.branch.controldir.sprout('local').open_workingtree()
453
393
work_tree.commit('moar work plz')
454
394
work_tree.branch.push(branch_tree.branch)
455
395
# branching our local branch gives us a new stacked branch pointing at
457
397
out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
458
398
self.assertEqual('', out)
459
399
self.assertEqual('Branched 2 revisions.\n',
461
401
# it should have preserved the branch format, and so it should be
462
402
# capable of supporting stacking, but not actually have a stacked_on
463
403
# branch configured
464
404
self.assertRaises(errors.NotStacked,
465
controldir.ControlDir.open('newbranch').open_branch().get_stacked_on_url)
405
controldir.ControlDir.open('newbranch').open_branch().get_stacked_on_url)
467
407
def test_branch_stacked_branch_stacked(self):
468
408
"""Asking to stack on a stacked branch does work"""
469
409
# We have a mainline
470
410
trunk_tree = self.make_branch_and_tree('target',
472
412
trunk_revid = trunk_tree.commit('mainline')
473
413
# and a branch from it which is stacked
474
414
branch_tree = self.make_branch_and_tree('branch',
476
416
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
477
417
# with some work on it
478
work_tree = trunk_tree.branch.controldir.sprout(
479
'local').open_workingtree()
418
work_tree = trunk_tree.branch.controldir.sprout('local').open_workingtree()
480
419
branch_revid = work_tree.commit('moar work plz')
481
420
work_tree.branch.push(branch_tree.branch)
482
421
# you can chain branches on from there
483
422
out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
484
423
self.assertEqual('', out)
485
424
self.assertEqual('Created new stacked branch referring to %s.\n' %
486
branch_tree.branch.base, err)
425
branch_tree.branch.base, err)
487
426
self.assertEqual(branch_tree.branch.base,
488
branch.Branch.open('branch2').get_stacked_on_url())
427
branch.Branch.open('branch2').get_stacked_on_url())
489
428
branch2_tree = WorkingTree.open('branch2')
490
429
branch2_revid = work_tree.commit('work on second stacked branch')
491
430
work_tree.branch.push(branch2_tree.branch)
492
class TestSmartServerBranching(tests.TestCaseWithTransport):
494
def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
495
self.setup_smart_server_with_call_log()
496
t = self.make_branch_and_tree('from')
497
for count in range(9):
498
t.commit(message='commit %d' % count)
499
self.reset_smart_call_log()
500
out, err = self.run_bzr(['branch', self.get_url('from'),
501
self.get_url('target')])
502
# This figure represent the amount of work to perform this use case. It
503
# is entirely ok to reduce this number if a test fails due to rpc_count
504
# being too low. If rpc_count increases, more network roundtrips have
505
# become necessary for this use case. Please do not adjust this number
506
# upwards without agreement from bzr's network support maintainers.
507
self.assertLength(2, self.hpss_connections)
508
self.assertLength(33, self.hpss_calls)
509
self.expectFailure("branching to the same branch requires VFS access",
510
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
512
def test_branch_from_trivial_branch_streaming_acceptance(self):
513
self.setup_smart_server_with_call_log()
514
t = self.make_branch_and_tree('from')
515
for count in range(9):
516
t.commit(message='commit %d' % count)
517
self.reset_smart_call_log()
518
out, err = self.run_bzr(['branch', self.get_url('from'),
520
# This figure represent the amount of work to perform this use case. It
521
# is entirely ok to reduce this number if a test fails due to rpc_count
522
# being too low. If rpc_count increases, more network roundtrips have
523
# become necessary for this use case. Please do not adjust this number
524
# upwards without agreement from bzr's network support maintainers.
525
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
526
self.assertLength(10, self.hpss_calls)
527
self.assertLength(1, self.hpss_connections)
529
def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
530
self.setup_smart_server_with_call_log()
531
t = self.make_branch_and_tree('trunk')
532
for count in range(8):
533
t.commit(message='commit %d' % count)
534
tree2 = t.branch.controldir.sprout('feature', stacked=True
536
local_tree = t.branch.controldir.sprout('local-working').open_workingtree()
537
local_tree.commit('feature change')
538
local_tree.branch.push(tree2.branch)
539
self.reset_smart_call_log()
540
out, err = self.run_bzr(['branch', self.get_url('feature'),
542
# This figure represent the amount of work to perform this use case. It
543
# is entirely ok to reduce this number if a test fails due to rpc_count
544
# being too low. If rpc_count increases, more network roundtrips have
545
# become necessary for this use case. Please do not adjust this number
546
# upwards without agreement from bzr's network support maintainers.
547
self.assertLength(15, self.hpss_calls)
548
self.assertLength(1, self.hpss_connections)
549
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
551
def test_branch_from_branch_with_tags(self):
552
self.setup_smart_server_with_call_log()
553
builder = self.make_branch_builder('source')
554
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(builder)
555
source.get_config_stack().set('branch.fetch_tags', True)
556
source.tags.set_tag('tag-a', rev2)
557
source.tags.set_tag('tag-missing', 'missing-rev')
558
# Now source has a tag not in its ancestry. Make a branch from it.
559
self.reset_smart_call_log()
560
out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
561
# This figure represent the amount of work to perform this use case. It
562
# is entirely ok to reduce this number if a test fails due to rpc_count
563
# being too low. If rpc_count increases, more network roundtrips have
564
# become necessary for this use case. Please do not adjust this number
565
# upwards without agreement from bzr's network support maintainers.
566
self.assertLength(10, self.hpss_calls)
567
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
568
self.assertLength(1, self.hpss_connections)
570
def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
571
self.setup_smart_server_with_call_log()
572
t = self.make_branch_and_tree('from')
573
for count in range(9):
574
t.commit(message='commit %d' % count)
575
self.reset_smart_call_log()
576
out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
578
# XXX: the number of hpss calls for this case isn't deterministic yet,
579
# so we can't easily assert about the number of calls.
580
#self.assertLength(XXX, self.hpss_calls)
581
# We can assert that none of the calls were readv requests for rix
582
# files, though (demonstrating that at least get_parent_map calls are
583
# not using VFS RPCs).
584
readvs_of_rix_files = [
585
c for c in self.hpss_calls
586
if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
587
self.assertLength(1, self.hpss_connections)
588
self.assertLength(0, readvs_of_rix_files)
589
self.expectFailure("branching to stacked requires VFS access",
590
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
554
593
class TestRemoteBranch(TestCaseWithSFTPServer):
557
596
super(TestRemoteBranch, self).setUp()
558
597
tree = self.make_branch_and_tree('branch')
559
self.build_tree_contents([('branch/file', b'file content\n')])
598
self.build_tree_contents([('branch/file', 'file content\n')])
561
600
tree.commit('file created')