27
26
revision as _mod_revision,
29
28
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
30
from bzrlib.tests.blackbox import ExternalBase
29
from bzrlib.tests import TestCaseWithTransport
31
30
from bzrlib.tests import (
36
from bzrlib.tests.blackbox import test_switch
36
37
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
38
from bzrlib.tests.script import run_script
37
39
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
38
40
from bzrlib.workingtree import WorkingTree
41
class TestBranch(ExternalBase):
43
class TestBranch(TestCaseWithTransport):
43
45
def example_branch(self, path='.'):
44
46
tree = self.make_branch_and_tree(path)
59
61
self.assertFalse(b._transport.has('branch-name'))
60
62
b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
64
def test_branch_broken_pack(self):
65
"""branching with a corrupted pack file."""
66
self.example_branch('a')
67
#now add some random corruption
68
fname = 'a/.bzr/repository/packs/' + os.listdir('a/.bzr/repository/packs')[0]
69
with open(fname, 'rb+') as f:
72
self.run_bzr_error(['Corruption while decompressing repository file'],
73
'branch a b', retcode=3)
62
75
def test_branch_switch_no_branch(self):
63
76
# No branch in the current directory:
64
77
# => new branch will be created, but switch fails
174
187
target_stat = os.stat('target/file1')
175
188
self.assertEqual(source_stat, target_stat)
190
def test_branch_files_from(self):
191
source = self.make_branch_and_tree('source')
192
self.build_tree(['source/file1'])
194
source.commit('added file')
195
out, err = self.run_bzr('branch source target --files-from source')
196
self.assertPathExists('target/file1')
198
def test_branch_files_from_hardlink(self):
199
self.requireFeature(HardlinkFeature)
200
source = self.make_branch_and_tree('source')
201
self.build_tree(['source/file1'])
203
source.commit('added file')
204
source.bzrdir.sprout('second')
205
out, err = self.run_bzr('branch source target --files-from second'
207
source_stat = os.stat('source/file1')
208
second_stat = os.stat('second/file1')
209
target_stat = os.stat('target/file1')
210
self.assertNotEqual(source_stat, target_stat)
211
self.assertEqual(second_stat, target_stat)
177
213
def test_branch_standalone(self):
178
214
shared_repo = self.make_repository('repo', shared=True)
179
215
self.example_branch('source')
186
222
def test_branch_no_tree(self):
187
223
self.example_branch('source')
188
224
self.run_bzr('branch --no-tree source target')
189
self.failIfExists('target/hello')
190
self.failIfExists('target/goodbye')
225
self.assertPathDoesNotExist('target/hello')
226
self.assertPathDoesNotExist('target/goodbye')
192
228
def test_branch_into_existing_dir(self):
193
229
self.example_branch('a')
203
239
# force operation
204
240
self.run_bzr('branch a b --use-existing-dir')
205
241
# check conflicts
206
self.failUnlessExists('b/hello.moved')
207
self.failIfExists('b/godbye.moved')
242
self.assertPathExists('b/hello.moved')
243
self.assertPathDoesNotExist('b/godbye.moved')
208
244
# we can't branch into branch
209
245
out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
210
246
self.assertEqual('', out)
247
283
self.run_bzr('checkout --lightweight a b')
248
284
self.assertLength(2, calls)
251
class TestBranchStacked(ExternalBase):
286
def test_branch_fetches_all_tags(self):
287
builder = self.make_branch_builder('source')
288
source = fixtures.build_branch_with_non_ancestral_rev(builder)
289
source.tags.set_tag('tag-a', 'rev-2')
290
source.get_config().set_user_option('branch.fetch_tags', 'True')
291
# Now source has a tag not in its ancestry. Make a branch from it.
292
self.run_bzr('branch source new-branch')
293
new_branch = branch.Branch.open('new-branch')
294
# The tag is present, and so is its revision.
295
self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
296
new_branch.repository.get_revision('rev-2')
299
class TestBranchStacked(TestCaseWithTransport):
252
300
"""Tests for branch --stacked"""
254
302
def assertRevisionInRepository(self, repo_path, revid):
391
439
# being too low. If rpc_count increases, more network roundtrips have
392
440
# become necessary for this use case. Please do not adjust this number
393
441
# upwards without agreement from bzr's network support maintainers.
394
self.assertLength(38, self.hpss_calls)
442
self.assertLength(37, self.hpss_calls)
396
444
def test_branch_from_trivial_branch_streaming_acceptance(self):
397
445
self.setup_smart_server_with_call_log()
428
476
# upwards without agreement from bzr's network support maintainers.
429
477
self.assertLength(15, self.hpss_calls)
479
def test_branch_from_branch_with_tags(self):
480
self.setup_smart_server_with_call_log()
481
builder = self.make_branch_builder('source')
482
source = fixtures.build_branch_with_non_ancestral_rev(builder)
483
source.get_config().set_user_option('branch.fetch_tags', 'True')
484
source.tags.set_tag('tag-a', 'rev-2')
485
source.tags.set_tag('tag-missing', 'missing-rev')
486
# Now source has a tag not in its ancestry. Make a branch from it.
487
self.reset_smart_call_log()
488
out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
489
# This figure represent the amount of work to perform this use case. It
490
# is entirely ok to reduce this number if a test fails due to rpc_count
491
# being too low. If rpc_count increases, more network roundtrips have
492
# become necessary for this use case. Please do not adjust this number
493
# upwards without agreement from bzr's network support maintainers.
494
self.assertLength(10, self.hpss_calls)
496
def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
497
self.setup_smart_server_with_call_log()
498
t = self.make_branch_and_tree('from')
499
for count in range(9):
500
t.commit(message='commit %d' % count)
501
self.reset_smart_call_log()
502
out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
504
# XXX: the number of hpss calls for this case isn't deterministic yet,
505
# so we can't easily assert about the number of calls.
506
#self.assertLength(XXX, self.hpss_calls)
507
# We can assert that none of the calls were readv requests for rix
508
# files, though (demonstrating that at least get_parent_map calls are
509
# not using VFS RPCs).
510
readvs_of_rix_files = [
511
c for c in self.hpss_calls
512
if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
513
self.assertLength(0, readvs_of_rix_files)
432
516
class TestRemoteBranch(TestCaseWithSFTPServer):
452
536
# Ensure that no working tree what created remotely
453
537
self.assertFalse(t.has('remote/file'))
540
class TestDeprecatedAliases(TestCaseWithTransport):
542
def test_deprecated_aliases(self):
543
"""bzr branch can be called clone or get, but those names are deprecated.
547
for command in ['clone', 'get']:
549
$ bzr %(command)s A B
550
2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
551
2>bzr: ERROR: Not a branch...
555
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
557
def _checkout_and_branch(self, option=''):
558
self.script_runner.run_script(self, '''
559
$ bzr checkout %(option)s repo/trunk checkout
561
$ bzr branch --switch ../repo/trunk ../repo/branched
562
2>Branched 0 revision(s).
563
2>Tree is up to date at revision 0.
564
2>Switched to branch:...branched...
567
bound_branch = branch.Branch.open_containing('checkout')[0]
568
master_branch = branch.Branch.open_containing('repo/branched')[0]
569
return (bound_branch, master_branch)
571
def test_branch_switch_parent_lightweight(self):
572
"""Lightweight checkout using bzr branch --switch."""
573
bb, mb = self._checkout_and_branch(option='--lightweight')
574
self.assertParent('repo/trunk', bb)
575
self.assertParent('repo/trunk', mb)
577
def test_branch_switch_parent_heavyweight(self):
578
"""Heavyweight checkout using bzr branch --switch."""
579
bb, mb = self._checkout_and_branch()
580
self.assertParent('repo/trunk', bb)
581
self.assertParent('repo/trunk', mb)