30
29
from bzrlib.tests import TestCaseWithTransport
31
30
from bzrlib.tests import (
35
from bzrlib.tests.features import (
38
from bzrlib.tests.blackbox import test_switch
39
35
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
40
36
from bzrlib.tests.script import run_script
41
37
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
45
41
class TestBranch(TestCaseWithTransport):
47
def example_branch(self, path='.', format=None):
48
tree = self.make_branch_and_tree(path, format=format)
43
def example_branch(self, path='.'):
44
tree = self.make_branch_and_tree(path)
49
45
self.build_tree_contents([(path + '/hello', 'foo')])
51
47
tree.commit(message='setup')
52
48
self.build_tree_contents([(path + '/goodbye', 'baz')])
53
49
tree.add('goodbye')
54
50
tree.commit(message='setup')
57
52
def test_branch(self):
58
53
"""Branch from one branch to another."""
64
59
self.assertFalse(b._transport.has('branch-name'))
65
60
b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
67
def test_into_colocated(self):
68
"""Branch from a branch into a colocated branch."""
69
self.example_branch('a')
70
out, err = self.run_bzr(
71
'init --format=development-colo file:b,branch=orig')
73
"""Created a lightweight checkout (format: development-colo)\n""",
75
self.assertEqual('', err)
76
out, err = self.run_bzr(
77
'branch a file:b,branch=thiswasa')
78
self.assertEqual('', out)
79
self.assertEqual('Branched 2 revisions.\n', err)
80
out, err = self.run_bzr('branches b')
81
self.assertEqual(" orig\n thiswasa\n", out)
82
self.assertEqual('', err)
83
out,err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
84
self.assertEqual('', out)
85
self.assertEqual('bzr: ERROR: Already a branch: "file:b,branch=orig".\n', err)
87
def test_from_colocated(self):
88
"""Branch from a colocated branch into a regular branch."""
89
tree = self.example_branch('a', format='development-colo')
90
tree.bzrdir.create_branch(name='somecolo')
91
out, err = self.run_bzr('branch %s,branch=somecolo' %
92
local_path_to_url('a'))
93
self.assertEqual('', out)
94
self.assertEqual('Branched 0 revisions.\n', err)
95
self.assertPathExists("somecolo")
97
def test_branch_broken_pack(self):
98
"""branching with a corrupted pack file."""
99
self.example_branch('a')
100
# add some corruption
101
packs_dir = 'a/.bzr/repository/packs/'
102
fname = packs_dir + os.listdir(packs_dir)[0]
103
with open(fname, 'rb+') as f:
104
# Start from the end of the file to avoid choosing a place bigger
105
# than the file itself.
106
f.seek(-5, os.SEEK_END)
108
f.seek(-5, os.SEEK_END)
109
# Make sure we inject a value different than the one we just read
114
f.write(corrupt) # make sure we corrupt something
115
self.run_bzr_error(['Corruption while decompressing repository file'],
116
'branch a b', retcode=3)
118
62
def test_branch_switch_no_branch(self):
119
63
# No branch in the current directory:
120
64
# => new branch will be created, but switch fails
191
135
def make_shared_tree(path):
192
136
shared_repo.bzrdir.root_transport.mkdir(path)
193
controldir.ControlDir.create_branch_convenience('repo/' + path)
137
shared_repo.bzrdir.create_branch_convenience('repo/' + path)
194
138
return WorkingTree.open('repo/' + path)
195
139
tree_a = make_shared_tree('a')
196
140
self.build_tree(['repo/a/file'])
330
274
builder = self.make_branch_builder('source')
331
275
source = fixtures.build_branch_with_non_ancestral_rev(builder)
332
276
source.tags.set_tag('tag-a', 'rev-2')
333
source.get_config().set_user_option('branch.fetch_tags', 'True')
334
277
# Now source has a tag not in its ancestry. Make a branch from it.
335
278
self.run_bzr('branch source new-branch')
336
279
new_branch = branch.Branch.open('new-branch')
376
319
out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
377
320
self.assertEqual('', out)
378
self.assertEqual('Branched 2 revisions.\n',
321
self.assertEqual('Branched 2 revision(s).\n',
380
323
# it should have preserved the branch format, and so it should be
381
324
# capable of supporting stacking, but not actually have a stacked_on
482
425
# being too low. If rpc_count increases, more network roundtrips have
483
426
# become necessary for this use case. Please do not adjust this number
484
427
# upwards without agreement from bzr's network support maintainers.
485
self.assertLength(40, self.hpss_calls)
428
self.assertLength(36, self.hpss_calls)
487
430
def test_branch_from_trivial_branch_streaming_acceptance(self):
488
431
self.setup_smart_server_with_call_log()
497
440
# being too low. If rpc_count increases, more network roundtrips have
498
441
# become necessary for this use case. Please do not adjust this number
499
442
# upwards without agreement from bzr's network support maintainers.
500
self.assertLength(10, self.hpss_calls)
443
self.assertLength(9, self.hpss_calls)
502
445
def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
503
446
self.setup_smart_server_with_call_log()
517
460
# being too low. If rpc_count increases, more network roundtrips have
518
461
# become necessary for this use case. Please do not adjust this number
519
462
# upwards without agreement from bzr's network support maintainers.
520
self.assertLength(15, self.hpss_calls)
463
self.assertLength(14, self.hpss_calls)
522
465
def test_branch_from_branch_with_tags(self):
523
466
self.setup_smart_server_with_call_log()
524
467
builder = self.make_branch_builder('source')
525
468
source = fixtures.build_branch_with_non_ancestral_rev(builder)
526
source.get_config().set_user_option('branch.fetch_tags', 'True')
527
469
source.tags.set_tag('tag-a', 'rev-2')
528
470
source.tags.set_tag('tag-missing', 'missing-rev')
529
471
# Now source has a tag not in its ancestry. Make a branch from it.
534
476
# being too low. If rpc_count increases, more network roundtrips have
535
477
# become necessary for this use case. Please do not adjust this number
536
478
# upwards without agreement from bzr's network support maintainers.
537
self.assertLength(10, self.hpss_calls)
539
def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
540
self.setup_smart_server_with_call_log()
541
t = self.make_branch_and_tree('from')
542
for count in range(9):
543
t.commit(message='commit %d' % count)
544
self.reset_smart_call_log()
545
out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
547
# XXX: the number of hpss calls for this case isn't deterministic yet,
548
# so we can't easily assert about the number of calls.
549
#self.assertLength(XXX, self.hpss_calls)
550
# We can assert that none of the calls were readv requests for rix
551
# files, though (demonstrating that at least get_parent_map calls are
552
# not using VFS RPCs).
553
readvs_of_rix_files = [
554
c for c in self.hpss_calls
555
if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
556
self.assertLength(0, readvs_of_rix_files)
479
self.assertLength(9, self.hpss_calls)
559
482
class TestRemoteBranch(TestCaseWithSFTPServer):
593
516
2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
594
517
2>bzr: ERROR: Not a branch...
598
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
600
def _checkout_and_branch(self, option=''):
601
self.script_runner.run_script(self, '''
602
$ bzr checkout %(option)s repo/trunk checkout
604
$ bzr branch --switch ../repo/trunk ../repo/branched
605
2>Branched 0 revisions.
606
2>Tree is up to date at revision 0.
607
2>Switched to branch:...branched...
610
bound_branch = branch.Branch.open_containing('checkout')[0]
611
master_branch = branch.Branch.open_containing('repo/branched')[0]
612
return (bound_branch, master_branch)
614
def test_branch_switch_parent_lightweight(self):
615
"""Lightweight checkout using bzr branch --switch."""
616
bb, mb = self._checkout_and_branch(option='--lightweight')
617
self.assertParent('repo/trunk', bb)
618
self.assertParent('repo/trunk', mb)
620
def test_branch_switch_parent_heavyweight(self):
621
"""Heavyweight checkout using bzr branch --switch."""
622
bb, mb = self._checkout_and_branch()
623
self.assertParent('repo/trunk', bb)
624
self.assertParent('repo/trunk', mb)