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)
174
176
target_stat = os.stat('target/file1')
175
177
self.assertEqual(source_stat, target_stat)
179
def test_branch_files_from(self):
180
source = self.make_branch_and_tree('source')
181
self.build_tree(['source/file1'])
183
source.commit('added file')
184
out, err = self.run_bzr('branch source target --files-from source')
185
self.assertPathExists('target/file1')
187
def test_branch_files_from_hardlink(self):
188
self.requireFeature(HardlinkFeature)
189
source = self.make_branch_and_tree('source')
190
self.build_tree(['source/file1'])
192
source.commit('added file')
193
source.bzrdir.sprout('second')
194
out, err = self.run_bzr('branch source target --files-from second'
196
source_stat = os.stat('source/file1')
197
second_stat = os.stat('second/file1')
198
target_stat = os.stat('target/file1')
199
self.assertNotEqual(source_stat, target_stat)
200
self.assertEqual(second_stat, target_stat)
177
202
def test_branch_standalone(self):
178
203
shared_repo = self.make_repository('repo', shared=True)
179
204
self.example_branch('source')
186
211
def test_branch_no_tree(self):
187
212
self.example_branch('source')
188
213
self.run_bzr('branch --no-tree source target')
189
self.failIfExists('target/hello')
190
self.failIfExists('target/goodbye')
214
self.assertPathDoesNotExist('target/hello')
215
self.assertPathDoesNotExist('target/goodbye')
192
217
def test_branch_into_existing_dir(self):
193
218
self.example_branch('a')
203
228
# force operation
204
229
self.run_bzr('branch a b --use-existing-dir')
205
230
# check conflicts
206
self.failUnlessExists('b/hello.moved')
207
self.failIfExists('b/godbye.moved')
231
self.assertPathExists('b/hello.moved')
232
self.assertPathDoesNotExist('b/godbye.moved')
208
233
# we can't branch into branch
209
234
out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
210
235
self.assertEqual('', out)
217
242
b = branch.Branch.open('b')
218
243
self.assertEndsWith(b.get_bound_location(), '/a/')
221
class TestBranchStacked(ExternalBase):
245
def test_branch_with_post_branch_init_hook(self):
247
branch.Branch.hooks.install_named_hook('post_branch_init',
249
self.assertLength(0, calls)
250
self.example_branch('a')
251
self.assertLength(1, calls)
252
self.run_bzr('branch a b')
253
self.assertLength(2, calls)
255
def test_checkout_with_post_branch_init_hook(self):
257
branch.Branch.hooks.install_named_hook('post_branch_init',
259
self.assertLength(0, calls)
260
self.example_branch('a')
261
self.assertLength(1, calls)
262
self.run_bzr('checkout a b')
263
self.assertLength(2, calls)
265
def test_lightweight_checkout_with_post_branch_init_hook(self):
267
branch.Branch.hooks.install_named_hook('post_branch_init',
269
self.assertLength(0, calls)
270
self.example_branch('a')
271
self.assertLength(1, calls)
272
self.run_bzr('checkout --lightweight a b')
273
self.assertLength(2, calls)
275
def test_branch_fetches_all_tags(self):
276
builder = self.make_branch_builder('source')
277
source = fixtures.build_branch_with_non_ancestral_rev(builder)
278
source.tags.set_tag('tag-a', 'rev-2')
279
# Now source has a tag not in its ancestry. Make a branch from it.
280
self.run_bzr('branch source new-branch')
281
new_branch = branch.Branch.open('new-branch')
282
# The tag is present, and so is its revision.
283
self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
284
new_branch.repository.get_revision('rev-2')
287
class TestBranchStacked(TestCaseWithTransport):
222
288
"""Tests for branch --stacked"""
224
290
def assertRevisionInRepository(self, repo_path, revid):
361
427
# being too low. If rpc_count increases, more network roundtrips have
362
428
# become necessary for this use case. Please do not adjust this number
363
429
# upwards without agreement from bzr's network support maintainers.
364
self.assertLength(38, self.hpss_calls)
430
self.assertLength(36, self.hpss_calls)
366
432
def test_branch_from_trivial_branch_streaming_acceptance(self):
367
433
self.setup_smart_server_with_call_log()
376
442
# being too low. If rpc_count increases, more network roundtrips have
377
443
# become necessary for this use case. Please do not adjust this number
378
444
# upwards without agreement from bzr's network support maintainers.
379
self.assertLength(10, self.hpss_calls)
445
self.assertLength(9, self.hpss_calls)
381
447
def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
382
448
self.setup_smart_server_with_call_log()
396
462
# being too low. If rpc_count increases, more network roundtrips have
397
463
# become necessary for this use case. Please do not adjust this number
398
464
# upwards without agreement from bzr's network support maintainers.
399
self.assertLength(15, self.hpss_calls)
465
self.assertLength(14, self.hpss_calls)
467
def test_branch_from_branch_with_tags(self):
468
self.setup_smart_server_with_call_log()
469
builder = self.make_branch_builder('source')
470
source = fixtures.build_branch_with_non_ancestral_rev(builder)
471
source.tags.set_tag('tag-a', 'rev-2')
472
source.tags.set_tag('tag-missing', 'missing-rev')
473
# Now source has a tag not in its ancestry. Make a branch from it.
474
self.reset_smart_call_log()
475
out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
476
# This figure represent the amount of work to perform this use case. It
477
# is entirely ok to reduce this number if a test fails due to rpc_count
478
# being too low. If rpc_count increases, more network roundtrips have
479
# become necessary for this use case. Please do not adjust this number
480
# upwards without agreement from bzr's network support maintainers.
481
self.assertLength(9, self.hpss_calls)
483
def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
484
self.setup_smart_server_with_call_log()
485
t = self.make_branch_and_tree('from')
486
for count in range(9):
487
t.commit(message='commit %d' % count)
488
self.reset_smart_call_log()
489
out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
491
# XXX: the number of hpss calls for this case isn't deterministic yet,
492
# so we can't easily assert about the number of calls.
493
#self.assertLength(XXX, self.hpss_calls)
494
# We can assert that none of the calls were readv requests for rix
495
# files, though (demonstrating that at least get_parent_map calls are
496
# not using VFS RPCs).
497
readvs_of_rix_files = [
498
c for c in self.hpss_calls
499
if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
500
self.assertLength(0, readvs_of_rix_files)
402
503
class TestRemoteBranch(TestCaseWithSFTPServer):
422
523
# Ensure that no working tree what created remotely
423
524
self.assertFalse(t.has('remote/file'))
527
class TestDeprecatedAliases(TestCaseWithTransport):
529
def test_deprecated_aliases(self):
530
"""bzr branch can be called clone or get, but those names are deprecated.
534
for command in ['clone', 'get']:
536
$ bzr %(command)s A B
537
2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
538
2>bzr: ERROR: Not a branch...
542
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
544
def _checkout_and_branch(self, option=''):
545
self.script_runner.run_script(self, '''
546
$ bzr checkout %(option)s repo/trunk checkout
548
$ bzr branch --switch ../repo/trunk ../repo/branched
549
2>Branched 0 revision(s).
550
2>Tree is up to date at revision 0.
551
2>Switched to branch:...branched...
554
bound_branch = branch.Branch.open_containing('checkout')[0]
555
master_branch = branch.Branch.open_containing('repo/branched')[0]
556
return (bound_branch, master_branch)
558
def test_branch_switch_parent_lightweight(self):
559
"""Lightweight checkout using bzr branch --switch."""
560
bb, mb = self._checkout_and_branch(option='--lightweight')
561
self.assertParent('repo/trunk', bb)
562
self.assertParent('repo/trunk', mb)
564
def test_branch_switch_parent_heavyweight(self):
565
"""Heavyweight checkout using bzr branch --switch."""
566
bb, mb = self._checkout_and_branch()
567
self.assertParent('repo/trunk', bb)
568
self.assertParent('repo/trunk', mb)