360
370
self.assertEqual(rev2, new_branch.tags.lookup_tag('tag-a'))
361
371
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')
364
422
class TestBranchStacked(tests.TestCaseWithTransport):
365
423
"""Tests for branch --stacked"""
496
class TestSmartServerBranching(tests.TestCaseWithTransport):
498
def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
499
self.setup_smart_server_with_call_log()
500
t = self.make_branch_and_tree('from')
501
for count in range(9):
502
t.commit(message='commit %d' % count)
503
self.reset_smart_call_log()
504
out, err = self.run_bzr(['branch', self.get_url('from'),
505
self.get_url('target')])
506
# This figure represent the amount of work to perform this use case. It
507
# is entirely ok to reduce this number if a test fails due to rpc_count
508
# being too low. If rpc_count increases, more network roundtrips have
509
# become necessary for this use case. Please do not adjust this number
510
# upwards without agreement from bzr's network support maintainers.
511
self.assertLength(2, self.hpss_connections)
512
self.assertLength(33, self.hpss_calls)
513
self.expectFailure("branching to the same branch requires VFS access",
514
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
516
def test_branch_from_trivial_branch_streaming_acceptance(self):
517
self.setup_smart_server_with_call_log()
518
t = self.make_branch_and_tree('from')
519
for count in range(9):
520
t.commit(message='commit %d' % count)
521
self.reset_smart_call_log()
522
out, err = self.run_bzr(['branch', self.get_url('from'),
524
# This figure represent the amount of work to perform this use case. It
525
# is entirely ok to reduce this number if a test fails due to rpc_count
526
# being too low. If rpc_count increases, more network roundtrips have
527
# become necessary for this use case. Please do not adjust this number
528
# upwards without agreement from bzr's network support maintainers.
529
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
530
self.assertLength(10, self.hpss_calls)
531
self.assertLength(1, self.hpss_connections)
533
def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
534
self.setup_smart_server_with_call_log()
535
t = self.make_branch_and_tree('trunk')
536
for count in range(8):
537
t.commit(message='commit %d' % count)
538
tree2 = t.branch.controldir.sprout('feature', stacked=True
540
local_tree = t.branch.controldir.sprout(
541
'local-working').open_workingtree()
542
local_tree.commit('feature change')
543
local_tree.branch.push(tree2.branch)
544
self.reset_smart_call_log()
545
out, err = self.run_bzr(['branch', self.get_url('feature'),
547
# This figure represent the amount of work to perform this use case. It
548
# is entirely ok to reduce this number if a test fails due to rpc_count
549
# being too low. If rpc_count increases, more network roundtrips have
550
# become necessary for this use case. Please do not adjust this number
551
# upwards without agreement from bzr's network support maintainers.
552
self.assertLength(15, self.hpss_calls)
553
self.assertLength(1, self.hpss_connections)
554
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
556
def test_branch_from_branch_with_tags(self):
557
self.setup_smart_server_with_call_log()
558
builder = self.make_branch_builder('source')
559
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(
561
source.get_config_stack().set('branch.fetch_tags', True)
562
source.tags.set_tag('tag-a', rev2)
563
source.tags.set_tag('tag-missing', b'missing-rev')
564
# Now source has a tag not in its ancestry. Make a branch from it.
565
self.reset_smart_call_log()
566
out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
567
# This figure represent the amount of work to perform this use case. It
568
# is entirely ok to reduce this number if a test fails due to rpc_count
569
# being too low. If rpc_count increases, more network roundtrips have
570
# become necessary for this use case. Please do not adjust this number
571
# upwards without agreement from bzr's network support maintainers.
572
self.assertLength(10, self.hpss_calls)
573
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
574
self.assertLength(1, self.hpss_connections)
576
def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
577
self.setup_smart_server_with_call_log()
578
t = self.make_branch_and_tree('from')
579
for count in range(9):
580
t.commit(message='commit %d' % count)
581
self.reset_smart_call_log()
582
out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
584
# XXX: the number of hpss calls for this case isn't deterministic yet,
585
# so we can't easily assert about the number of calls.
586
#self.assertLength(XXX, self.hpss_calls)
587
# We can assert that none of the calls were readv requests for rix
588
# files, though (demonstrating that at least get_parent_map calls are
589
# not using VFS RPCs).
590
readvs_of_rix_files = [
591
c for c in self.hpss_calls
592
if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
593
self.assertLength(1, self.hpss_connections)
594
self.assertLength(0, readvs_of_rix_files)
595
self.expectFailure("branching to stacked requires VFS access",
596
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
598
def test_branch_from_branch_with_ghosts(self):
599
self.setup_smart_server_with_call_log()
600
t = self.make_branch_and_tree('from')
601
for count in range(9):
602
t.commit(message='commit %d' % count)
603
t.set_parent_ids([t.last_revision(), b'ghost'])
604
t.commit(message='add commit with parent')
605
self.reset_smart_call_log()
606
out, err = self.run_bzr(['branch', self.get_url('from'),
608
# This figure represent the amount of work to perform this use case. It
609
# is entirely ok to reduce this number if a test fails due to rpc_count
610
# being too low. If rpc_count increases, more network roundtrips have
611
# become necessary for this use case. Please do not adjust this number
612
# upwards without agreement from bzr's network support maintainers.
613
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
614
self.assertLength(11, self.hpss_calls)
615
self.assertLength(1, self.hpss_connections)
618
554
class TestRemoteBranch(TestCaseWithSFTPServer):