29
30
from bzrlib.tests import TestCaseWithTransport
30
31
from bzrlib.tests import (
35
35
from bzrlib.tests.features import (
38
38
from bzrlib.tests.blackbox import test_switch
39
from bzrlib.tests.matchers import ContainsNoVfsCalls
39
40
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
40
41
from bzrlib.tests.script import run_script
41
42
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
45
46
class TestBranch(TestCaseWithTransport):
47
def example_branch(self, path='.'):
48
tree = self.make_branch_and_tree(path)
48
def example_branch(self, path='.', format=None):
49
tree = self.make_branch_and_tree(path, format=format)
49
50
self.build_tree_contents([(path + '/hello', 'foo')])
51
52
tree.commit(message='setup')
52
53
self.build_tree_contents([(path + '/goodbye', 'baz')])
53
54
tree.add('goodbye')
54
55
tree.commit(message='setup')
56
58
def test_branch(self):
57
59
"""Branch from one branch to another."""
63
65
self.assertFalse(b._transport.has('branch-name'))
64
66
b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
68
def test_into_colocated(self):
69
"""Branch from a branch into a colocated branch."""
70
self.example_branch('a')
71
out, err = self.run_bzr(
72
'init --format=development-colo file:b,branch=orig')
74
"""Created a lightweight checkout (format: development-colo)\n""",
76
self.assertEqual('', err)
77
out, err = self.run_bzr(
78
'branch a file:b,branch=thiswasa')
79
self.assertEqual('', out)
80
self.assertEqual('Branched 2 revisions.\n', err)
81
out, err = self.run_bzr('branches b')
82
self.assertEqual(" orig\n thiswasa\n", out)
83
self.assertEqual('', err)
84
out,err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
85
self.assertEqual('', out)
86
self.assertEqual('bzr: ERROR: Already a branch: "file:b,branch=orig".\n', err)
88
def test_from_colocated(self):
89
"""Branch from a colocated branch into a regular branch."""
90
tree = self.example_branch('a', format='development-colo')
91
tree.bzrdir.create_branch(name='somecolo')
92
out, err = self.run_bzr('branch %s,branch=somecolo' %
93
local_path_to_url('a'))
94
self.assertEqual('', out)
95
self.assertEqual('Branched 0 revisions.\n', err)
96
self.assertPathExists("somecolo")
66
98
def test_branch_broken_pack(self):
67
99
"""branching with a corrupted pack file."""
68
100
self.example_branch('a')
69
#now add some random corruption
70
fname = 'a/.bzr/repository/packs/' + os.listdir('a/.bzr/repository/packs')[0]
101
# add some corruption
102
packs_dir = 'a/.bzr/repository/packs/'
103
fname = packs_dir + os.listdir(packs_dir)[0]
71
104
with open(fname, 'rb+') as f:
105
# Start from the end of the file to avoid choosing a place bigger
106
# than the file itself.
107
f.seek(-5, os.SEEK_END)
109
f.seek(-5, os.SEEK_END)
110
# Make sure we inject a value different than the one we just read
115
f.write(corrupt) # make sure we corrupt something
74
116
self.run_bzr_error(['Corruption while decompressing repository file'],
75
117
'branch a b', retcode=3)
150
192
def make_shared_tree(path):
151
193
shared_repo.bzrdir.root_transport.mkdir(path)
152
shared_repo.bzrdir.create_branch_convenience('repo/' + path)
194
controldir.ControlDir.create_branch_convenience('repo/' + path)
153
195
return WorkingTree.open('repo/' + path)
154
196
tree_a = make_shared_tree('a')
155
197
self.build_tree(['repo/a/file'])
289
331
builder = self.make_branch_builder('source')
290
332
source = fixtures.build_branch_with_non_ancestral_rev(builder)
291
333
source.tags.set_tag('tag-a', 'rev-2')
292
source.get_config().set_user_option('branch.fetch_tags', 'True')
334
source.get_config_stack().set('branch.fetch_tags', True)
293
335
# Now source has a tag not in its ancestry. Make a branch from it.
294
336
self.run_bzr('branch source new-branch')
295
337
new_branch = branch.Branch.open('new-branch')
335
377
out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
336
378
self.assertEqual('', out)
337
self.assertEqual('Branched 2 revision(s).\n',
379
self.assertEqual('Branched 2 revisions.\n',
339
381
# it should have preserved the branch format, and so it should be
340
382
# capable of supporting stacking, but not actually have a stacked_on
441
483
# being too low. If rpc_count increases, more network roundtrips have
442
484
# become necessary for this use case. Please do not adjust this number
443
485
# upwards without agreement from bzr's network support maintainers.
444
self.assertLength(37, self.hpss_calls)
486
self.assertLength(2, self.hpss_connections)
487
self.assertLength(33, self.hpss_calls)
488
self.expectFailure("branching to the same branch requires VFS access",
489
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
446
491
def test_branch_from_trivial_branch_streaming_acceptance(self):
447
492
self.setup_smart_server_with_call_log()
456
501
# being too low. If rpc_count increases, more network roundtrips have
457
502
# become necessary for this use case. Please do not adjust this number
458
503
# upwards without agreement from bzr's network support maintainers.
504
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
459
505
self.assertLength(10, self.hpss_calls)
506
self.assertLength(1, self.hpss_connections)
461
508
def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
462
509
self.setup_smart_server_with_call_log()
477
524
# become necessary for this use case. Please do not adjust this number
478
525
# upwards without agreement from bzr's network support maintainers.
479
526
self.assertLength(15, self.hpss_calls)
527
self.assertLength(1, self.hpss_connections)
528
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
481
530
def test_branch_from_branch_with_tags(self):
482
531
self.setup_smart_server_with_call_log()
483
532
builder = self.make_branch_builder('source')
484
533
source = fixtures.build_branch_with_non_ancestral_rev(builder)
485
source.get_config().set_user_option('branch.fetch_tags', 'True')
534
source.get_config_stack().set('branch.fetch_tags', True)
486
535
source.tags.set_tag('tag-a', 'rev-2')
487
536
source.tags.set_tag('tag-missing', 'missing-rev')
488
537
# Now source has a tag not in its ancestry. Make a branch from it.
494
543
# become necessary for this use case. Please do not adjust this number
495
544
# upwards without agreement from bzr's network support maintainers.
496
545
self.assertLength(10, self.hpss_calls)
546
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
547
self.assertLength(1, self.hpss_connections)
498
549
def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
499
550
self.setup_smart_server_with_call_log()
512
563
readvs_of_rix_files = [
513
564
c for c in self.hpss_calls
514
565
if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
566
self.assertLength(1, self.hpss_connections)
515
567
self.assertLength(0, readvs_of_rix_files)
568
self.expectFailure("branching to stacked requires VFS access",
569
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
518
572
class TestRemoteBranch(TestCaseWithSFTPServer):