1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Black-box tests for brz branch."""
26
revision as _mod_revision,
29
from breezy.bzr import (
32
from breezy.bzr.knitrepo import RepositoryFormatKnit1
33
from breezy.tests import (
37
from breezy.tests.features import (
40
from breezy.tests.blackbox import test_switch
41
from breezy.tests.matchers import ContainsNoVfsCalls
42
from breezy.tests.test_sftp_transport import TestCaseWithSFTPServer
43
from breezy.tests.script import run_script
44
from breezy.urlutils import local_path_to_url, strip_trailing_slash
45
from breezy.workingtree import WorkingTree
48
class TestBranch(tests.TestCaseWithTransport):
50
def example_branch(self, path='.', format=None):
51
tree = self.make_branch_and_tree(path, format=format)
52
self.build_tree_contents([(path + '/hello', b'foo')])
54
tree.commit(message='setup')
55
self.build_tree_contents([(path + '/goodbye', b'baz')])
57
tree.commit(message='setup')
60
def test_branch(self):
61
"""Branch from one branch to another."""
62
self.example_branch('a')
63
self.run_bzr('branch a b')
64
b = branch.Branch.open('b')
65
self.run_bzr('branch a c -r 1')
66
# previously was erroneously created by branching
67
self.assertFalse(b._transport.has('branch-name'))
68
b.controldir.open_workingtree().commit(message='foo', allow_pointless=True)
70
def test_branch_no_to_location(self):
71
"""The to_location is derived from the source branch name."""
73
a = self.example_branch('something/a').branch
74
self.run_bzr('branch something/a')
75
b = branch.Branch.open('a')
76
self.assertEqual(b.last_revision_info(), a.last_revision_info())
78
def test_into_colocated(self):
79
"""Branch from a branch into a colocated branch."""
80
self.example_branch('a')
81
out, err = self.run_bzr(
82
'init --format=development-colo file:b,branch=orig')
84
"""Created a standalone tree (format: development-colo)\n""",
86
self.assertEqual('', err)
87
out, err = self.run_bzr(
88
'branch a file:b,branch=thiswasa')
89
self.assertEqual('', out)
90
self.assertEqual('Branched 2 revisions.\n', err)
91
out, err = self.run_bzr('branches b')
92
self.assertEqual(" orig\n thiswasa\n", out)
93
self.assertEqual('', err)
94
out, err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
95
self.assertEqual('', out)
97
'brz: ERROR: Already a branch: "file:b,branch=orig".\n', err)
99
def test_from_colocated(self):
100
"""Branch from a colocated branch into a regular branch."""
102
tree = self.example_branch('b/a', format='development-colo')
103
tree.controldir.create_branch(name='somecolo')
104
out, err = self.run_bzr('branch %s,branch=somecolo' %
105
local_path_to_url('b/a'))
106
self.assertEqual('', out)
107
self.assertEqual('Branched 0 revisions.\n', err)
108
self.assertPathExists('a')
110
def test_branch_broken_pack(self):
111
"""branching with a corrupted pack file."""
112
self.example_branch('a')
113
# add some corruption
114
packs_dir = 'a/.bzr/repository/packs/'
115
fname = packs_dir + os.listdir(packs_dir)[0]
116
with open(fname, 'rb+') as f:
117
# Start from the end of the file to avoid choosing a place bigger
118
# than the file itself.
119
f.seek(-5, os.SEEK_END)
121
f.seek(-5, os.SEEK_END)
122
# Make sure we inject a value different than the one we just read
127
f.write(corrupt) # make sure we corrupt something
128
self.run_bzr_error(['Corruption while decompressing repository file'],
129
'branch a b', retcode=3)
131
def test_branch_switch_no_branch(self):
132
# No branch in the current directory:
133
# => new branch will be created, but switch fails
134
self.example_branch('a')
135
self.make_repository('current')
136
self.run_bzr_error(['No WorkingTree exists for'],
137
'branch --switch ../a ../b', working_dir='current')
138
a = branch.Branch.open('a')
139
b = branch.Branch.open('b')
140
self.assertEqual(a.last_revision(), b.last_revision())
142
def test_branch_switch_no_wt(self):
143
# No working tree in the current directory:
144
# => new branch will be created, but switch fails and the current
145
# branch is unmodified
146
self.example_branch('a')
147
self.make_branch('current')
148
self.run_bzr_error(['No WorkingTree exists for'],
149
'branch --switch ../a ../b', working_dir='current')
150
a = branch.Branch.open('a')
151
b = branch.Branch.open('b')
152
self.assertEqual(a.last_revision(), b.last_revision())
153
work = branch.Branch.open('current')
154
self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
156
def test_branch_switch_no_checkout(self):
157
# Standalone branch in the current directory:
158
# => new branch will be created, but switch fails and the current
159
# branch is unmodified
160
self.example_branch('a')
161
tree = self.make_branch_and_tree('current')
162
c1 = tree.commit('some diverged change')
163
self.run_bzr_error(['Cannot switch a branch, only a checkout'],
164
'branch --switch ../a ../b', working_dir='current')
165
a = branch.Branch.open('a')
166
b = branch.Branch.open('b')
167
self.assertEqual(a.last_revision(), b.last_revision())
168
work = branch.Branch.open('current')
169
self.assertEqual(work.last_revision(), c1)
171
def test_branch_into_empty_dir(self):
172
t = self.example_branch('source')
173
self.make_controldir('target')
174
self.run_bzr("branch source target")
175
self.assertEqual(2, len(t.branch.repository.all_revision_ids()))
177
def test_branch_switch_checkout(self):
178
# Checkout in the current directory:
179
# => new branch will be created and checkout bound to the new branch
180
self.example_branch('a')
181
self.run_bzr('checkout a current')
182
out, err = self.run_bzr('branch --switch ../a ../b',
183
working_dir='current')
184
a = branch.Branch.open('a')
185
b = branch.Branch.open('b')
186
self.assertEqual(a.last_revision(), b.last_revision())
187
work = WorkingTree.open('current')
188
self.assertEndsWith(work.branch.get_bound_location(), '/b/')
189
self.assertContainsRe(err, "Switched to branch: .*/b/")
191
def test_branch_switch_lightweight_checkout(self):
192
# Lightweight checkout in the current directory:
193
# => new branch will be created and lightweight checkout pointed to
195
self.example_branch('a')
196
self.run_bzr('checkout --lightweight a current')
197
out, err = self.run_bzr('branch --switch ../a ../b',
198
working_dir='current')
199
a = branch.Branch.open('a')
200
b = branch.Branch.open('b')
201
self.assertEqual(a.last_revision(), b.last_revision())
202
work = WorkingTree.open('current')
203
self.assertEndsWith(work.branch.base, '/b/')
204
self.assertContainsRe(err, "Switched to branch: .*/b/")
206
def test_branch_only_copies_history(self):
207
# Knit branches should only push the history for the current revision.
208
format = bzrdir.BzrDirMetaFormat1()
209
format.repository_format = RepositoryFormatKnit1()
210
shared_repo = self.make_repository('repo', format=format, shared=True)
211
shared_repo.set_make_working_trees(True)
213
def make_shared_tree(path):
214
shared_repo.controldir.root_transport.mkdir(path)
215
controldir.ControlDir.create_branch_convenience('repo/' + path)
216
return WorkingTree.open('repo/' + path)
217
tree_a = make_shared_tree('a')
218
self.build_tree(['repo/a/file'])
220
tree_a.commit('commit a-1', rev_id=b'a-1')
221
with open('repo/a/file', 'ab') as f:
222
f.write(b'more stuff\n')
223
tree_a.commit('commit a-2', rev_id=b'a-2')
225
tree_b = make_shared_tree('b')
226
self.build_tree(['repo/b/file'])
228
tree_b.commit('commit b-1', rev_id=b'b-1')
230
self.assertTrue(shared_repo.has_revision(b'a-1'))
231
self.assertTrue(shared_repo.has_revision(b'a-2'))
232
self.assertTrue(shared_repo.has_revision(b'b-1'))
234
# Now that we have a repository with shared files, make sure
235
# that things aren't copied out by a 'branch'
236
self.run_bzr('branch repo/b branch-b')
237
pushed_tree = WorkingTree.open('branch-b')
238
pushed_repo = pushed_tree.branch.repository
239
self.assertFalse(pushed_repo.has_revision(b'a-1'))
240
self.assertFalse(pushed_repo.has_revision(b'a-2'))
241
self.assertTrue(pushed_repo.has_revision(b'b-1'))
243
def test_branch_hardlink(self):
244
self.requireFeature(HardlinkFeature)
245
source = self.make_branch_and_tree('source')
246
self.build_tree(['source/file1'])
248
source.commit('added file')
249
out, err = self.run_bzr(['branch', 'source', 'target', '--hardlink'])
250
source_stat = os.stat('source/file1')
251
target_stat = os.stat('target/file1')
252
self.assertEqual(source_stat, target_stat)
254
def test_branch_files_from(self):
255
source = self.make_branch_and_tree('source')
256
self.build_tree(['source/file1'])
258
source.commit('added file')
259
out, err = self.run_bzr('branch source target --files-from source')
260
self.assertPathExists('target/file1')
262
def test_branch_files_from_hardlink(self):
263
self.requireFeature(HardlinkFeature)
264
source = self.make_branch_and_tree('source')
265
self.build_tree(['source/file1'])
267
source.commit('added file')
268
source.controldir.sprout('second')
269
out, err = self.run_bzr('branch source target --files-from second'
271
source_stat = os.stat('source/file1')
272
second_stat = os.stat('second/file1')
273
target_stat = os.stat('target/file1')
274
self.assertNotEqual(source_stat, target_stat)
275
self.assertEqual(second_stat, target_stat)
277
def test_branch_standalone(self):
278
shared_repo = self.make_repository('repo', shared=True)
279
self.example_branch('source')
280
self.run_bzr('branch --standalone source repo/target')
281
b = branch.Branch.open('repo/target')
282
expected_repo_path = os.path.abspath('repo/target/.bzr/repository')
283
self.assertEqual(strip_trailing_slash(b.repository.base),
284
strip_trailing_slash(local_path_to_url(expected_repo_path)))
286
def test_branch_no_tree(self):
287
self.example_branch('source')
288
self.run_bzr('branch --no-tree source target')
289
self.assertPathDoesNotExist('target/hello')
290
self.assertPathDoesNotExist('target/goodbye')
292
def test_branch_into_existing_dir(self):
293
self.example_branch('a')
294
# existing dir with similar files but no .brz dir
295
self.build_tree_contents([('b/',)])
296
self.build_tree_contents([('b/hello', b'bar')]) # different content
297
self.build_tree_contents([('b/goodbye', b'baz')]) # same content
298
# fails without --use-existing-dir
299
out, err = self.run_bzr('branch a b', retcode=3)
300
self.assertEqual('', out)
301
self.assertEqual('brz: ERROR: Target directory "b" already exists.\n',
304
self.run_bzr('branch a b --use-existing-dir')
306
self.assertPathExists('b/hello.moved')
307
self.assertPathDoesNotExist('b/godbye.moved')
308
# we can't branch into branch
309
out, err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
310
self.assertEqual('', out)
311
self.assertEqual('brz: ERROR: Already a branch: "b".\n', err)
313
def test_branch_bind(self):
314
self.example_branch('a')
315
out, err = self.run_bzr('branch a b --bind')
316
self.assertEndsWith(err, "New branch bound to a\n")
317
b = branch.Branch.open('b')
318
self.assertEndsWith(b.get_bound_location(), '/a/')
320
def test_branch_with_post_branch_init_hook(self):
322
branch.Branch.hooks.install_named_hook('post_branch_init',
324
self.assertLength(0, calls)
325
self.example_branch('a')
326
self.assertLength(1, calls)
327
self.run_bzr('branch a b')
328
self.assertLength(2, calls)
330
def test_checkout_with_post_branch_init_hook(self):
332
branch.Branch.hooks.install_named_hook('post_branch_init',
334
self.assertLength(0, calls)
335
self.example_branch('a')
336
self.assertLength(1, calls)
337
self.run_bzr('checkout a b')
338
self.assertLength(2, calls)
340
def test_lightweight_checkout_with_post_branch_init_hook(self):
342
branch.Branch.hooks.install_named_hook('post_branch_init',
344
self.assertLength(0, calls)
345
self.example_branch('a')
346
self.assertLength(1, calls)
347
self.run_bzr('checkout --lightweight a b')
348
self.assertLength(2, calls)
350
def test_branch_fetches_all_tags(self):
351
builder = self.make_branch_builder('source')
352
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(
354
source.tags.set_tag('tag-a', rev2)
355
source.get_config_stack().set('branch.fetch_tags', True)
356
# Now source has a tag not in its ancestry. Make a branch from it.
357
self.run_bzr('branch source new-branch')
358
new_branch = branch.Branch.open('new-branch')
359
# The tag is present, and so is its revision.
360
self.assertEqual(rev2, new_branch.tags.lookup_tag('tag-a'))
361
new_branch.repository.get_revision(rev2)
364
class TestBranchStacked(tests.TestCaseWithTransport):
365
"""Tests for branch --stacked"""
367
def assertRevisionInRepository(self, repo_path, revid):
368
"""Check that a revision is in a repo, disregarding stacking."""
369
repo = controldir.ControlDir.open(repo_path).open_repository()
370
self.assertTrue(repo.has_revision(revid))
372
def assertRevisionNotInRepository(self, repo_path, revid):
373
"""Check that a revision is not in a repo, disregarding stacking."""
374
repo = controldir.ControlDir.open(repo_path).open_repository()
375
self.assertFalse(repo.has_revision(revid))
377
def assertRevisionsInBranchRepository(self, revid_list, branch_path):
378
repo = branch.Branch.open(branch_path).repository
379
self.assertEqual(set(revid_list),
380
repo.has_revisions(revid_list))
382
def test_branch_stacked_branch_not_stacked(self):
383
"""Branching a stacked branch is not stacked by default"""
385
trunk_tree = self.make_branch_and_tree('target',
387
trunk_tree.commit('mainline')
388
# and a branch from it which is stacked
389
branch_tree = self.make_branch_and_tree('branch',
391
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
392
# with some work on it
393
work_tree = trunk_tree.branch.controldir.sprout(
394
'local').open_workingtree()
395
work_tree.commit('moar work plz')
396
work_tree.branch.push(branch_tree.branch)
397
# branching our local branch gives us a new stacked branch pointing at
399
out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
400
self.assertEqual('', out)
401
self.assertEqual('Branched 2 revisions.\n',
403
# it should have preserved the branch format, and so it should be
404
# capable of supporting stacking, but not actually have a stacked_on
406
self.assertRaises(errors.NotStacked,
407
controldir.ControlDir.open('newbranch').open_branch().get_stacked_on_url)
409
def test_branch_stacked_branch_stacked(self):
410
"""Asking to stack on a stacked branch does work"""
412
trunk_tree = self.make_branch_and_tree('target',
414
trunk_revid = trunk_tree.commit('mainline')
415
# and a branch from it which is stacked
416
branch_tree = self.make_branch_and_tree('branch',
418
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
419
# with some work on it
420
work_tree = trunk_tree.branch.controldir.sprout(
421
'local').open_workingtree()
422
branch_revid = work_tree.commit('moar work plz')
423
work_tree.branch.push(branch_tree.branch)
424
# you can chain branches on from there
425
out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
426
self.assertEqual('', out)
427
self.assertEqual('Created new stacked branch referring to %s.\n' %
428
branch_tree.branch.base, err)
429
self.assertEqual(branch_tree.branch.base,
430
branch.Branch.open('branch2').get_stacked_on_url())
431
branch2_tree = WorkingTree.open('branch2')
432
branch2_revid = work_tree.commit('work on second stacked branch')
433
work_tree.branch.push(branch2_tree.branch)
434
self.assertRevisionInRepository('branch2', branch2_revid)
435
self.assertRevisionsInBranchRepository(
436
[trunk_revid, branch_revid, branch2_revid],
439
def test_branch_stacked(self):
441
trunk_tree = self.make_branch_and_tree('mainline',
443
original_revid = trunk_tree.commit('mainline')
444
self.assertRevisionInRepository('mainline', original_revid)
445
# and a branch from it which is stacked
446
out, err = self.run_bzr(['branch', '--stacked', 'mainline',
448
self.assertEqual('', out)
449
self.assertEqual('Created new stacked branch referring to %s.\n' %
450
trunk_tree.branch.base, err)
451
self.assertRevisionNotInRepository('newbranch', original_revid)
452
new_branch = branch.Branch.open('newbranch')
453
self.assertEqual(trunk_tree.branch.base,
454
new_branch.get_stacked_on_url())
456
def test_branch_stacked_from_smart_server(self):
457
# We can branch stacking on a smart server
458
self.transport_server = test_server.SmartTCPServer_for_testing
459
trunk = self.make_branch('mainline', format='1.9')
460
out, err = self.run_bzr(
461
['branch', '--stacked', self.get_url('mainline'), 'shallow'])
463
def test_branch_stacked_from_non_stacked_format(self):
464
"""The origin format doesn't support stacking"""
465
trunk = self.make_branch('trunk', format='pack-0.92')
466
out, err = self.run_bzr(
467
['branch', '--stacked', 'trunk', 'shallow'])
468
# We should notify the user that we upgraded their format
469
self.assertEqualDiff(
470
'Source repository format does not support stacking, using format:\n'
471
' Packs 5 (adds stacking support, requires bzr 1.6)\n'
472
'Source branch format does not support stacking, using format:\n'
474
'Doing on-the-fly conversion from RepositoryFormatKnitPack1() to RepositoryFormatKnitPack5().\n'
475
'This may take some time. Upgrade the repositories to the same format for better performance.\n'
476
'Created new stacked branch referring to %s.\n' %
480
def test_branch_stacked_from_rich_root_non_stackable(self):
481
trunk = self.make_branch('trunk', format='rich-root-pack')
482
out, err = self.run_bzr(
483
['branch', '--stacked', 'trunk', 'shallow'])
484
# We should notify the user that we upgraded their format
485
self.assertEqualDiff(
486
'Source repository format does not support stacking, using format:\n'
487
' Packs 5 rich-root (adds stacking support, requires bzr 1.6.1)\n'
488
'Source branch format does not support stacking, using format:\n'
490
'Doing on-the-fly conversion from RepositoryFormatKnitPack4() to RepositoryFormatKnitPack5RichRoot().\n'
491
'This may take some time. Upgrade the repositories to the same format for better performance.\n'
492
'Created new stacked branch referring to %s.\n' % (trunk.base,),
496
class TestSmartServerBranching(tests.TestCaseWithTransport):
498
def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
499
self.setup_smart_server_with_call_log()
500
t = self.make_branch_and_tree('from')
501
for count in range(9):
502
t.commit(message='commit %d' % count)
503
self.reset_smart_call_log()
504
out, err = self.run_bzr(['branch', self.get_url('from'),
505
self.get_url('target')])
506
# This figure represent the amount of work to perform this use case. It
507
# is entirely ok to reduce this number if a test fails due to rpc_count
508
# being too low. If rpc_count increases, more network roundtrips have
509
# become necessary for this use case. Please do not adjust this number
510
# upwards without agreement from bzr's network support maintainers.
511
self.assertLength(2, self.hpss_connections)
512
self.assertLength(33, self.hpss_calls)
513
self.expectFailure("branching to the same branch requires VFS access",
514
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
516
def test_branch_from_trivial_branch_streaming_acceptance(self):
517
self.setup_smart_server_with_call_log()
518
t = self.make_branch_and_tree('from')
519
for count in range(9):
520
t.commit(message='commit %d' % count)
521
self.reset_smart_call_log()
522
out, err = self.run_bzr(['branch', self.get_url('from'),
524
# This figure represent the amount of work to perform this use case. It
525
# is entirely ok to reduce this number if a test fails due to rpc_count
526
# being too low. If rpc_count increases, more network roundtrips have
527
# become necessary for this use case. Please do not adjust this number
528
# upwards without agreement from bzr's network support maintainers.
529
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
530
self.assertLength(10, self.hpss_calls)
531
self.assertLength(1, self.hpss_connections)
533
def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
534
self.setup_smart_server_with_call_log()
535
t = self.make_branch_and_tree('trunk')
536
for count in range(8):
537
t.commit(message='commit %d' % count)
538
tree2 = t.branch.controldir.sprout('feature', stacked=True
540
local_tree = t.branch.controldir.sprout(
541
'local-working').open_workingtree()
542
local_tree.commit('feature change')
543
local_tree.branch.push(tree2.branch)
544
self.reset_smart_call_log()
545
out, err = self.run_bzr(['branch', self.get_url('feature'),
547
# This figure represent the amount of work to perform this use case. It
548
# is entirely ok to reduce this number if a test fails due to rpc_count
549
# being too low. If rpc_count increases, more network roundtrips have
550
# become necessary for this use case. Please do not adjust this number
551
# upwards without agreement from bzr's network support maintainers.
552
self.assertLength(15, self.hpss_calls)
553
self.assertLength(1, self.hpss_connections)
554
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
556
def test_branch_from_branch_with_tags(self):
557
self.setup_smart_server_with_call_log()
558
builder = self.make_branch_builder('source')
559
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(
561
source.get_config_stack().set('branch.fetch_tags', True)
562
source.tags.set_tag('tag-a', rev2)
563
source.tags.set_tag('tag-missing', b'missing-rev')
564
# Now source has a tag not in its ancestry. Make a branch from it.
565
self.reset_smart_call_log()
566
out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
567
# This figure represent the amount of work to perform this use case. It
568
# is entirely ok to reduce this number if a test fails due to rpc_count
569
# being too low. If rpc_count increases, more network roundtrips have
570
# become necessary for this use case. Please do not adjust this number
571
# upwards without agreement from bzr's network support maintainers.
572
self.assertLength(10, self.hpss_calls)
573
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
574
self.assertLength(1, self.hpss_connections)
576
def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
577
self.setup_smart_server_with_call_log()
578
t = self.make_branch_and_tree('from')
579
for count in range(9):
580
t.commit(message='commit %d' % count)
581
self.reset_smart_call_log()
582
out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
584
# XXX: the number of hpss calls for this case isn't deterministic yet,
585
# so we can't easily assert about the number of calls.
586
#self.assertLength(XXX, self.hpss_calls)
587
# We can assert that none of the calls were readv requests for rix
588
# files, though (demonstrating that at least get_parent_map calls are
589
# not using VFS RPCs).
590
readvs_of_rix_files = [
591
c for c in self.hpss_calls
592
if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
593
self.assertLength(1, self.hpss_connections)
594
self.assertLength(0, readvs_of_rix_files)
595
self.expectFailure("branching to stacked requires VFS access",
596
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
598
def test_branch_from_branch_with_ghosts(self):
599
self.setup_smart_server_with_call_log()
600
t = self.make_branch_and_tree('from')
601
for count in range(9):
602
t.commit(message='commit %d' % count)
603
t.set_parent_ids([t.last_revision(), b'ghost'])
604
t.commit(message='add commit with parent')
605
self.reset_smart_call_log()
606
out, err = self.run_bzr(['branch', self.get_url('from'),
608
# This figure represent the amount of work to perform this use case. It
609
# is entirely ok to reduce this number if a test fails due to rpc_count
610
# being too low. If rpc_count increases, more network roundtrips have
611
# become necessary for this use case. Please do not adjust this number
612
# upwards without agreement from bzr's network support maintainers.
613
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
614
self.assertLength(11, self.hpss_calls)
615
self.assertLength(1, self.hpss_connections)
618
class TestRemoteBranch(TestCaseWithSFTPServer):
621
super(TestRemoteBranch, self).setUp()
622
tree = self.make_branch_and_tree('branch')
623
self.build_tree_contents([('branch/file', b'file content\n')])
625
tree.commit('file created')
627
def test_branch_local_remote(self):
628
self.run_bzr(['branch', 'branch', self.get_url('remote')])
629
t = self.get_transport()
630
# Ensure that no working tree what created remotely
631
self.assertFalse(t.has('remote/file'))
633
def test_branch_remote_remote(self):
634
# Light cheat: we access the branch remotely
635
self.run_bzr(['branch', self.get_url('branch'),
636
self.get_url('remote')])
637
t = self.get_transport()
638
# Ensure that no working tree what created remotely
639
self.assertFalse(t.has('remote/file'))
642
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
644
def _checkout_and_branch(self, option=''):
645
self.script_runner.run_script(self, '''
646
$ brz checkout %(option)s repo/trunk checkout
648
$ brz branch --switch ../repo/trunk ../repo/branched
649
2>Branched 0 revisions.
650
2>Tree is up to date at revision 0.
651
2>Switched to branch:...branched...
654
bound_branch = branch.Branch.open_containing('checkout')[0]
655
master_branch = branch.Branch.open_containing('repo/branched')[0]
656
return (bound_branch, master_branch)
658
def test_branch_switch_parent_lightweight(self):
659
"""Lightweight checkout using brz branch --switch."""
660
bb, mb = self._checkout_and_branch(option='--lightweight')
661
self.assertParent('repo/trunk', bb)
662
self.assertParent('repo/trunk', mb)
664
def test_branch_switch_parent_heavyweight(self):
665
"""Heavyweight checkout using brz branch --switch."""
666
bb, mb = self._checkout_and_branch()
667
self.assertParent('repo/trunk', bb)
668
self.assertParent('repo/trunk', mb)