22
22
from bzrlib import (
27
27
revision as _mod_revision,
29
29
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
30
30
from bzrlib.tests import TestCaseWithTransport
31
31
from bzrlib.tests import (
36
from bzrlib.tests.features import (
39
from bzrlib.tests.blackbox import test_switch
40
36
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
41
from bzrlib.tests.script import run_script
42
37
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
43
38
from bzrlib.workingtree import WorkingTree
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 standalone tree (format: development-colo)\n""",
75
self.assertEqual('', err)
76
out, err = self.run_bzr(
77
'branch --use-existing-dir 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)
84
def test_branch_broken_pack(self):
85
"""branching with a corrupted pack file."""
86
self.example_branch('a')
88
packs_dir = 'a/.bzr/repository/packs/'
89
fname = packs_dir + os.listdir(packs_dir)[0]
90
with open(fname, 'rb+') as f:
91
# Start from the end of the file to avoid choosing a place bigger
92
# than the file itself.
93
f.seek(-5, os.SEEK_END)
95
f.seek(-5, os.SEEK_END)
96
# Make sure we inject a value different than the one we just read
101
f.write(corrupt) # make sure we corrupt something
102
self.run_bzr_error(['Corruption while decompressing repository file'],
103
'branch a b', retcode=3)
105
62
def test_branch_switch_no_branch(self):
106
63
# No branch in the current directory:
107
64
# => new branch will be created, but switch fails
178
135
def make_shared_tree(path):
179
136
shared_repo.bzrdir.root_transport.mkdir(path)
180
controldir.ControlDir.create_branch_convenience('repo/' + path)
137
shared_repo.bzrdir.create_branch_convenience('repo/' + path)
181
138
return WorkingTree.open('repo/' + path)
182
139
tree_a = make_shared_tree('a')
183
140
self.build_tree(['repo/a/file'])
223
180
source.add('file1')
224
181
source.commit('added file')
225
182
out, err = self.run_bzr('branch source target --files-from source')
226
self.assertPathExists('target/file1')
183
self.failUnlessExists('target/file1')
228
185
def test_branch_files_from_hardlink(self):
229
186
self.requireFeature(HardlinkFeature)
252
209
def test_branch_no_tree(self):
253
210
self.example_branch('source')
254
211
self.run_bzr('branch --no-tree source target')
255
self.assertPathDoesNotExist('target/hello')
256
self.assertPathDoesNotExist('target/goodbye')
212
self.failIfExists('target/hello')
213
self.failIfExists('target/goodbye')
258
215
def test_branch_into_existing_dir(self):
259
216
self.example_branch('a')
269
226
# force operation
270
227
self.run_bzr('branch a b --use-existing-dir')
271
228
# check conflicts
272
self.assertPathExists('b/hello.moved')
273
self.assertPathDoesNotExist('b/godbye.moved')
229
self.failUnlessExists('b/hello.moved')
230
self.failIfExists('b/godbye.moved')
274
231
# we can't branch into branch
275
232
out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
276
233
self.assertEqual('', out)
313
270
self.run_bzr('checkout --lightweight a b')
314
271
self.assertLength(2, calls)
316
def test_branch_fetches_all_tags(self):
317
builder = self.make_branch_builder('source')
318
source = fixtures.build_branch_with_non_ancestral_rev(builder)
319
source.tags.set_tag('tag-a', 'rev-2')
320
source.get_config().set_user_option('branch.fetch_tags', 'True')
321
# Now source has a tag not in its ancestry. Make a branch from it.
322
self.run_bzr('branch source new-branch')
323
new_branch = branch.Branch.open('new-branch')
324
# The tag is present, and so is its revision.
325
self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
326
new_branch.repository.get_revision('rev-2')
329
274
class TestBranchStacked(TestCaseWithTransport):
330
275
"""Tests for branch --stacked"""
363
308
out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
364
309
self.assertEqual('', out)
365
self.assertEqual('Branched 2 revisions.\n',
310
self.assertEqual('Branched 2 revision(s).\n',
367
312
# it should have preserved the branch format, and so it should be
368
313
# capable of supporting stacking, but not actually have a stacked_on
469
414
# being too low. If rpc_count increases, more network roundtrips have
470
415
# become necessary for this use case. Please do not adjust this number
471
416
# upwards without agreement from bzr's network support maintainers.
472
self.assertLength(39, self.hpss_calls)
417
self.assertLength(38, self.hpss_calls)
474
419
def test_branch_from_trivial_branch_streaming_acceptance(self):
475
420
self.setup_smart_server_with_call_log()
506
451
# upwards without agreement from bzr's network support maintainers.
507
452
self.assertLength(15, self.hpss_calls)
509
def test_branch_from_branch_with_tags(self):
510
self.setup_smart_server_with_call_log()
511
builder = self.make_branch_builder('source')
512
source = fixtures.build_branch_with_non_ancestral_rev(builder)
513
source.get_config().set_user_option('branch.fetch_tags', 'True')
514
source.tags.set_tag('tag-a', 'rev-2')
515
source.tags.set_tag('tag-missing', 'missing-rev')
516
# Now source has a tag not in its ancestry. Make a branch from it.
517
self.reset_smart_call_log()
518
out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
519
# This figure represent the amount of work to perform this use case. It
520
# is entirely ok to reduce this number if a test fails due to rpc_count
521
# being too low. If rpc_count increases, more network roundtrips have
522
# become necessary for this use case. Please do not adjust this number
523
# upwards without agreement from bzr's network support maintainers.
524
self.assertLength(10, self.hpss_calls)
526
def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
527
self.setup_smart_server_with_call_log()
528
t = self.make_branch_and_tree('from')
529
for count in range(9):
530
t.commit(message='commit %d' % count)
531
self.reset_smart_call_log()
532
out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
534
# XXX: the number of hpss calls for this case isn't deterministic yet,
535
# so we can't easily assert about the number of calls.
536
#self.assertLength(XXX, self.hpss_calls)
537
# We can assert that none of the calls were readv requests for rix
538
# files, though (demonstrating that at least get_parent_map calls are
539
# not using VFS RPCs).
540
readvs_of_rix_files = [
541
c for c in self.hpss_calls
542
if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
543
self.assertLength(0, readvs_of_rix_files)
546
455
class TestRemoteBranch(TestCaseWithSFTPServer):
566
475
# Ensure that no working tree what created remotely
567
476
self.assertFalse(t.has('remote/file'))
570
class TestDeprecatedAliases(TestCaseWithTransport):
572
def test_deprecated_aliases(self):
573
"""bzr branch can be called clone or get, but those names are deprecated.
577
for command in ['clone', 'get']:
579
$ bzr %(command)s A B
580
2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
581
2>bzr: ERROR: Not a branch...
585
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
587
def _checkout_and_branch(self, option=''):
588
self.script_runner.run_script(self, '''
589
$ bzr checkout %(option)s repo/trunk checkout
591
$ bzr branch --switch ../repo/trunk ../repo/branched
592
2>Branched 0 revisions.
593
2>Tree is up to date at revision 0.
594
2>Switched to branch:...branched...
597
bound_branch = branch.Branch.open_containing('checkout')[0]
598
master_branch = branch.Branch.open_containing('repo/branched')[0]
599
return (bound_branch, master_branch)
601
def test_branch_switch_parent_lightweight(self):
602
"""Lightweight checkout using bzr branch --switch."""
603
bb, mb = self._checkout_and_branch(option='--lightweight')
604
self.assertParent('repo/trunk', bb)
605
self.assertParent('repo/trunk', mb)
607
def test_branch_switch_parent_heavyweight(self):
608
"""Heavyweight checkout using bzr branch --switch."""
609
bb, mb = self._checkout_and_branch()
610
self.assertParent('repo/trunk', bb)
611
self.assertParent('repo/trunk', mb)