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."""
101
tree = self.example_branch('a', format='development-colo')
102
tree.controldir.create_branch(name='somecolo')
103
out, err = self.run_bzr('branch %s,branch=somecolo' %
104
local_path_to_url('a'))
105
self.assertEqual('', out)
106
self.assertEqual('Branched 0 revisions.\n', err)
107
self.assertPathExists("somecolo")
109
def test_branch_broken_pack(self):
110
"""branching with a corrupted pack file."""
111
self.example_branch('a')
112
# add some corruption
113
packs_dir = 'a/.bzr/repository/packs/'
114
fname = packs_dir + os.listdir(packs_dir)[0]
115
with open(fname, 'rb+') as f:
116
# Start from the end of the file to avoid choosing a place bigger
117
# than the file itself.
118
f.seek(-5, os.SEEK_END)
120
f.seek(-5, os.SEEK_END)
121
# Make sure we inject a value different than the one we just read
126
f.write(corrupt) # make sure we corrupt something
127
self.run_bzr_error(['Corruption while decompressing repository file'],
128
'branch a b', retcode=3)
130
def test_branch_switch_no_branch(self):
131
# No branch in the current directory:
132
# => new branch will be created, but switch fails
133
self.example_branch('a')
134
self.make_repository('current')
135
self.run_bzr_error(['No WorkingTree exists for'],
136
'branch --switch ../a ../b', working_dir='current')
137
a = branch.Branch.open('a')
138
b = branch.Branch.open('b')
139
self.assertEqual(a.last_revision(), b.last_revision())
141
def test_branch_switch_no_wt(self):
142
# No working tree in the current directory:
143
# => new branch will be created, but switch fails and the current
144
# branch is unmodified
145
self.example_branch('a')
146
self.make_branch('current')
147
self.run_bzr_error(['No WorkingTree exists for'],
148
'branch --switch ../a ../b', working_dir='current')
149
a = branch.Branch.open('a')
150
b = branch.Branch.open('b')
151
self.assertEqual(a.last_revision(), b.last_revision())
152
work = branch.Branch.open('current')
153
self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
155
def test_branch_switch_no_checkout(self):
156
# Standalone branch in the current directory:
157
# => new branch will be created, but switch fails and the current
158
# branch is unmodified
159
self.example_branch('a')
160
tree = self.make_branch_and_tree('current')
161
c1 = tree.commit('some diverged change')
162
self.run_bzr_error(['Cannot switch a branch, only a checkout'],
163
'branch --switch ../a ../b', working_dir='current')
164
a = branch.Branch.open('a')
165
b = branch.Branch.open('b')
166
self.assertEqual(a.last_revision(), b.last_revision())
167
work = branch.Branch.open('current')
168
self.assertEqual(work.last_revision(), c1)
170
def test_branch_into_empty_dir(self):
171
t = self.example_branch('source')
172
self.make_controldir('target')
173
self.run_bzr("branch source target")
174
self.assertEqual(2, len(t.branch.repository.all_revision_ids()))
176
def test_branch_switch_checkout(self):
177
# Checkout in the current directory:
178
# => new branch will be created and checkout bound to the new branch
179
self.example_branch('a')
180
self.run_bzr('checkout a current')
181
out, err = self.run_bzr('branch --switch ../a ../b',
182
working_dir='current')
183
a = branch.Branch.open('a')
184
b = branch.Branch.open('b')
185
self.assertEqual(a.last_revision(), b.last_revision())
186
work = WorkingTree.open('current')
187
self.assertEndsWith(work.branch.get_bound_location(), '/b/')
188
self.assertContainsRe(err, "Switched to branch: .*/b/")
190
def test_branch_switch_lightweight_checkout(self):
191
# Lightweight checkout in the current directory:
192
# => new branch will be created and lightweight checkout pointed to
194
self.example_branch('a')
195
self.run_bzr('checkout --lightweight a current')
196
out, err = self.run_bzr('branch --switch ../a ../b',
197
working_dir='current')
198
a = branch.Branch.open('a')
199
b = branch.Branch.open('b')
200
self.assertEqual(a.last_revision(), b.last_revision())
201
work = WorkingTree.open('current')
202
self.assertEndsWith(work.branch.base, '/b/')
203
self.assertContainsRe(err, "Switched to branch: .*/b/")
205
def test_branch_only_copies_history(self):
206
# Knit branches should only push the history for the current revision.
207
format = bzrdir.BzrDirMetaFormat1()
208
format.repository_format = RepositoryFormatKnit1()
209
shared_repo = self.make_repository('repo', format=format, shared=True)
210
shared_repo.set_make_working_trees(True)
212
def make_shared_tree(path):
213
shared_repo.controldir.root_transport.mkdir(path)
214
controldir.ControlDir.create_branch_convenience('repo/' + path)
215
return WorkingTree.open('repo/' + path)
216
tree_a = make_shared_tree('a')
217
self.build_tree(['repo/a/file'])
219
tree_a.commit('commit a-1', rev_id=b'a-1')
220
with open('repo/a/file', 'ab') as f:
221
f.write(b'more stuff\n')
222
tree_a.commit('commit a-2', rev_id=b'a-2')
224
tree_b = make_shared_tree('b')
225
self.build_tree(['repo/b/file'])
227
tree_b.commit('commit b-1', rev_id=b'b-1')
229
self.assertTrue(shared_repo.has_revision(b'a-1'))
230
self.assertTrue(shared_repo.has_revision(b'a-2'))
231
self.assertTrue(shared_repo.has_revision(b'b-1'))
233
# Now that we have a repository with shared files, make sure
234
# that things aren't copied out by a 'branch'
235
self.run_bzr('branch repo/b branch-b')
236
pushed_tree = WorkingTree.open('branch-b')
237
pushed_repo = pushed_tree.branch.repository
238
self.assertFalse(pushed_repo.has_revision(b'a-1'))
239
self.assertFalse(pushed_repo.has_revision(b'a-2'))
240
self.assertTrue(pushed_repo.has_revision(b'b-1'))
242
def test_branch_hardlink(self):
243
self.requireFeature(HardlinkFeature)
244
source = self.make_branch_and_tree('source')
245
self.build_tree(['source/file1'])
247
source.commit('added file')
248
out, err = self.run_bzr(['branch', 'source', 'target', '--hardlink'])
249
source_stat = os.stat('source/file1')
250
target_stat = os.stat('target/file1')
251
self.assertEqual(source_stat, target_stat)
253
def test_branch_files_from(self):
254
source = self.make_branch_and_tree('source')
255
self.build_tree(['source/file1'])
257
source.commit('added file')
258
out, err = self.run_bzr('branch source target --files-from source')
259
self.assertPathExists('target/file1')
261
def test_branch_files_from_hardlink(self):
262
self.requireFeature(HardlinkFeature)
263
source = self.make_branch_and_tree('source')
264
self.build_tree(['source/file1'])
266
source.commit('added file')
267
source.controldir.sprout('second')
268
out, err = self.run_bzr('branch source target --files-from second'
270
source_stat = os.stat('source/file1')
271
second_stat = os.stat('second/file1')
272
target_stat = os.stat('target/file1')
273
self.assertNotEqual(source_stat, target_stat)
274
self.assertEqual(second_stat, target_stat)
276
def test_branch_standalone(self):
277
shared_repo = self.make_repository('repo', shared=True)
278
self.example_branch('source')
279
self.run_bzr('branch --standalone source repo/target')
280
b = branch.Branch.open('repo/target')
281
expected_repo_path = os.path.abspath('repo/target/.bzr/repository')
282
self.assertEqual(strip_trailing_slash(b.repository.base),
283
strip_trailing_slash(local_path_to_url(expected_repo_path)))
285
def test_branch_no_tree(self):
286
self.example_branch('source')
287
self.run_bzr('branch --no-tree source target')
288
self.assertPathDoesNotExist('target/hello')
289
self.assertPathDoesNotExist('target/goodbye')
291
def test_branch_into_existing_dir(self):
292
self.example_branch('a')
293
# existing dir with similar files but no .brz dir
294
self.build_tree_contents([('b/',)])
295
self.build_tree_contents([('b/hello', b'bar')]) # different content
296
self.build_tree_contents([('b/goodbye', b'baz')])# same content
297
# fails without --use-existing-dir
298
out, err = self.run_bzr('branch a b', retcode=3)
299
self.assertEqual('', out)
300
self.assertEqual('brz: ERROR: Target directory "b" already exists.\n',
303
self.run_bzr('branch a b --use-existing-dir')
305
self.assertPathExists('b/hello.moved')
306
self.assertPathDoesNotExist('b/godbye.moved')
307
# we can't branch into branch
308
out, err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
309
self.assertEqual('', out)
310
self.assertEqual('brz: ERROR: Already a branch: "b".\n', err)
312
def test_branch_bind(self):
313
self.example_branch('a')
314
out, err = self.run_bzr('branch a b --bind')
315
self.assertEndsWith(err, "New branch bound to a\n")
316
b = branch.Branch.open('b')
317
self.assertEndsWith(b.get_bound_location(), '/a/')
319
def test_branch_with_post_branch_init_hook(self):
321
branch.Branch.hooks.install_named_hook('post_branch_init',
323
self.assertLength(0, calls)
324
self.example_branch('a')
325
self.assertLength(1, calls)
326
self.run_bzr('branch a b')
327
self.assertLength(2, calls)
329
def test_checkout_with_post_branch_init_hook(self):
331
branch.Branch.hooks.install_named_hook('post_branch_init',
333
self.assertLength(0, calls)
334
self.example_branch('a')
335
self.assertLength(1, calls)
336
self.run_bzr('checkout a b')
337
self.assertLength(2, calls)
339
def test_lightweight_checkout_with_post_branch_init_hook(self):
341
branch.Branch.hooks.install_named_hook('post_branch_init',
343
self.assertLength(0, calls)
344
self.example_branch('a')
345
self.assertLength(1, calls)
346
self.run_bzr('checkout --lightweight a b')
347
self.assertLength(2, calls)
349
def test_branch_fetches_all_tags(self):
350
builder = self.make_branch_builder('source')
351
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(builder)
352
source.tags.set_tag('tag-a', rev2)
353
source.get_config_stack().set('branch.fetch_tags', True)
354
# Now source has a tag not in its ancestry. Make a branch from it.
355
self.run_bzr('branch source new-branch')
356
new_branch = branch.Branch.open('new-branch')
357
# The tag is present, and so is its revision.
358
self.assertEqual(rev2, new_branch.tags.lookup_tag('tag-a'))
359
new_branch.repository.get_revision(rev2)
362
class TestBranchStacked(tests.TestCaseWithTransport):
363
"""Tests for branch --stacked"""
365
def assertRevisionInRepository(self, repo_path, revid):
366
"""Check that a revision is in a repo, disregarding stacking."""
367
repo = controldir.ControlDir.open(repo_path).open_repository()
368
self.assertTrue(repo.has_revision(revid))
370
def assertRevisionNotInRepository(self, repo_path, revid):
371
"""Check that a revision is not in a repo, disregarding stacking."""
372
repo = controldir.ControlDir.open(repo_path).open_repository()
373
self.assertFalse(repo.has_revision(revid))
375
def assertRevisionsInBranchRepository(self, revid_list, branch_path):
376
repo = branch.Branch.open(branch_path).repository
377
self.assertEqual(set(revid_list),
378
repo.has_revisions(revid_list))
380
def test_branch_stacked_branch_not_stacked(self):
381
"""Branching a stacked branch is not stacked by default"""
383
trunk_tree = self.make_branch_and_tree('target',
385
trunk_tree.commit('mainline')
386
# and a branch from it which is stacked
387
branch_tree = self.make_branch_and_tree('branch',
389
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
390
# with some work on it
391
work_tree = trunk_tree.branch.controldir.sprout('local').open_workingtree()
392
work_tree.commit('moar work plz')
393
work_tree.branch.push(branch_tree.branch)
394
# branching our local branch gives us a new stacked branch pointing at
396
out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
397
self.assertEqual('', out)
398
self.assertEqual('Branched 2 revisions.\n',
400
# it should have preserved the branch format, and so it should be
401
# capable of supporting stacking, but not actually have a stacked_on
403
self.assertRaises(errors.NotStacked,
404
controldir.ControlDir.open('newbranch').open_branch().get_stacked_on_url)
406
def test_branch_stacked_branch_stacked(self):
407
"""Asking to stack on a stacked branch does work"""
409
trunk_tree = self.make_branch_and_tree('target',
411
trunk_revid = trunk_tree.commit('mainline')
412
# and a branch from it which is stacked
413
branch_tree = self.make_branch_and_tree('branch',
415
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
416
# with some work on it
417
work_tree = trunk_tree.branch.controldir.sprout('local').open_workingtree()
418
branch_revid = work_tree.commit('moar work plz')
419
work_tree.branch.push(branch_tree.branch)
420
# you can chain branches on from there
421
out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
422
self.assertEqual('', out)
423
self.assertEqual('Created new stacked branch referring to %s.\n' %
424
branch_tree.branch.base, err)
425
self.assertEqual(branch_tree.branch.base,
426
branch.Branch.open('branch2').get_stacked_on_url())
427
branch2_tree = WorkingTree.open('branch2')
428
branch2_revid = work_tree.commit('work on second stacked branch')
429
work_tree.branch.push(branch2_tree.branch)
430
self.assertRevisionInRepository('branch2', branch2_revid)
431
self.assertRevisionsInBranchRepository(
432
[trunk_revid, branch_revid, branch2_revid],
435
def test_branch_stacked(self):
437
trunk_tree = self.make_branch_and_tree('mainline',
439
original_revid = trunk_tree.commit('mainline')
440
self.assertRevisionInRepository('mainline', original_revid)
441
# and a branch from it which is stacked
442
out, err = self.run_bzr(['branch', '--stacked', 'mainline',
444
self.assertEqual('', out)
445
self.assertEqual('Created new stacked branch referring to %s.\n' %
446
trunk_tree.branch.base, err)
447
self.assertRevisionNotInRepository('newbranch', original_revid)
448
new_branch = branch.Branch.open('newbranch')
449
self.assertEqual(trunk_tree.branch.base,
450
new_branch.get_stacked_on_url())
452
def test_branch_stacked_from_smart_server(self):
453
# We can branch stacking on a smart server
454
self.transport_server = test_server.SmartTCPServer_for_testing
455
trunk = self.make_branch('mainline', format='1.9')
456
out, err = self.run_bzr(
457
['branch', '--stacked', self.get_url('mainline'), 'shallow'])
459
def test_branch_stacked_from_non_stacked_format(self):
460
"""The origin format doesn't support stacking"""
461
trunk = self.make_branch('trunk', format='pack-0.92')
462
out, err = self.run_bzr(
463
['branch', '--stacked', 'trunk', 'shallow'])
464
# We should notify the user that we upgraded their format
465
self.assertEqualDiff(
466
'Source repository format does not support stacking, using format:\n'
467
' Packs 5 (adds stacking support, requires bzr 1.6)\n'
468
'Source branch format does not support stacking, using format:\n'
470
'Doing on-the-fly conversion from RepositoryFormatKnitPack1() to RepositoryFormatKnitPack5().\n'
471
'This may take some time. Upgrade the repositories to the same format for better performance.\n'
472
'Created new stacked branch referring to %s.\n' %
476
def test_branch_stacked_from_rich_root_non_stackable(self):
477
trunk = self.make_branch('trunk', format='rich-root-pack')
478
out, err = self.run_bzr(
479
['branch', '--stacked', 'trunk', 'shallow'])
480
# We should notify the user that we upgraded their format
481
self.assertEqualDiff(
482
'Source repository format does not support stacking, using format:\n'
483
' Packs 5 rich-root (adds stacking support, requires bzr 1.6.1)\n'
484
'Source branch format does not support stacking, using format:\n'
486
'Doing on-the-fly conversion from RepositoryFormatKnitPack4() to RepositoryFormatKnitPack5RichRoot().\n'
487
'This may take some time. Upgrade the repositories to the same format for better performance.\n'
488
'Created new stacked branch referring to %s.\n' % (trunk.base,),
492
class TestSmartServerBranching(tests.TestCaseWithTransport):
494
def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
495
self.setup_smart_server_with_call_log()
496
t = self.make_branch_and_tree('from')
497
for count in range(9):
498
t.commit(message='commit %d' % count)
499
self.reset_smart_call_log()
500
out, err = self.run_bzr(['branch', self.get_url('from'),
501
self.get_url('target')])
502
# This figure represent the amount of work to perform this use case. It
503
# is entirely ok to reduce this number if a test fails due to rpc_count
504
# being too low. If rpc_count increases, more network roundtrips have
505
# become necessary for this use case. Please do not adjust this number
506
# upwards without agreement from bzr's network support maintainers.
507
self.assertLength(2, self.hpss_connections)
508
self.assertLength(33, self.hpss_calls)
509
self.expectFailure("branching to the same branch requires VFS access",
510
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
512
def test_branch_from_trivial_branch_streaming_acceptance(self):
513
self.setup_smart_server_with_call_log()
514
t = self.make_branch_and_tree('from')
515
for count in range(9):
516
t.commit(message='commit %d' % count)
517
self.reset_smart_call_log()
518
out, err = self.run_bzr(['branch', self.get_url('from'),
520
# This figure represent the amount of work to perform this use case. It
521
# is entirely ok to reduce this number if a test fails due to rpc_count
522
# being too low. If rpc_count increases, more network roundtrips have
523
# become necessary for this use case. Please do not adjust this number
524
# upwards without agreement from bzr's network support maintainers.
525
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
526
self.assertLength(10, self.hpss_calls)
527
self.assertLength(1, self.hpss_connections)
529
def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
530
self.setup_smart_server_with_call_log()
531
t = self.make_branch_and_tree('trunk')
532
for count in range(8):
533
t.commit(message='commit %d' % count)
534
tree2 = t.branch.controldir.sprout('feature', stacked=True
536
local_tree = t.branch.controldir.sprout('local-working').open_workingtree()
537
local_tree.commit('feature change')
538
local_tree.branch.push(tree2.branch)
539
self.reset_smart_call_log()
540
out, err = self.run_bzr(['branch', self.get_url('feature'),
542
# This figure represent the amount of work to perform this use case. It
543
# is entirely ok to reduce this number if a test fails due to rpc_count
544
# being too low. If rpc_count increases, more network roundtrips have
545
# become necessary for this use case. Please do not adjust this number
546
# upwards without agreement from bzr's network support maintainers.
547
self.assertLength(15, self.hpss_calls)
548
self.assertLength(1, self.hpss_connections)
549
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
551
def test_branch_from_branch_with_tags(self):
552
self.setup_smart_server_with_call_log()
553
builder = self.make_branch_builder('source')
554
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(builder)
555
source.get_config_stack().set('branch.fetch_tags', True)
556
source.tags.set_tag('tag-a', rev2)
557
source.tags.set_tag('tag-missing', b'missing-rev')
558
# Now source has a tag not in its ancestry. Make a branch from it.
559
self.reset_smart_call_log()
560
out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
561
# This figure represent the amount of work to perform this use case. It
562
# is entirely ok to reduce this number if a test fails due to rpc_count
563
# being too low. If rpc_count increases, more network roundtrips have
564
# become necessary for this use case. Please do not adjust this number
565
# upwards without agreement from bzr's network support maintainers.
566
self.assertLength(10, self.hpss_calls)
567
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
568
self.assertLength(1, self.hpss_connections)
570
def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
571
self.setup_smart_server_with_call_log()
572
t = self.make_branch_and_tree('from')
573
for count in range(9):
574
t.commit(message='commit %d' % count)
575
self.reset_smart_call_log()
576
out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
578
# XXX: the number of hpss calls for this case isn't deterministic yet,
579
# so we can't easily assert about the number of calls.
580
#self.assertLength(XXX, self.hpss_calls)
581
# We can assert that none of the calls were readv requests for rix
582
# files, though (demonstrating that at least get_parent_map calls are
583
# not using VFS RPCs).
584
readvs_of_rix_files = [
585
c for c in self.hpss_calls
586
if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
587
self.assertLength(1, self.hpss_connections)
588
self.assertLength(0, readvs_of_rix_files)
589
self.expectFailure("branching to stacked requires VFS access",
590
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
592
def test_branch_from_branch_with_ghosts(self):
593
self.setup_smart_server_with_call_log()
594
t = self.make_branch_and_tree('from')
595
for count in range(9):
596
t.commit(message='commit %d' % count)
597
t.set_parent_ids([t.last_revision(), b'ghost'])
598
t.commit(message='add commit with parent')
599
self.reset_smart_call_log()
600
out, err = self.run_bzr(['branch', self.get_url('from'),
602
# This figure represent the amount of work to perform this use case. It
603
# is entirely ok to reduce this number if a test fails due to rpc_count
604
# being too low. If rpc_count increases, more network roundtrips have
605
# become necessary for this use case. Please do not adjust this number
606
# upwards without agreement from bzr's network support maintainers.
607
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
608
self.assertLength(11, self.hpss_calls)
609
self.assertLength(1, self.hpss_connections)
612
class TestRemoteBranch(TestCaseWithSFTPServer):
615
super(TestRemoteBranch, self).setUp()
616
tree = self.make_branch_and_tree('branch')
617
self.build_tree_contents([('branch/file', b'file content\n')])
619
tree.commit('file created')
621
def test_branch_local_remote(self):
622
self.run_bzr(['branch', 'branch', self.get_url('remote')])
623
t = self.get_transport()
624
# Ensure that no working tree what created remotely
625
self.assertFalse(t.has('remote/file'))
627
def test_branch_remote_remote(self):
628
# Light cheat: we access the branch remotely
629
self.run_bzr(['branch', self.get_url('branch'),
630
self.get_url('remote')])
631
t = self.get_transport()
632
# Ensure that no working tree what created remotely
633
self.assertFalse(t.has('remote/file'))
636
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
638
def _checkout_and_branch(self, option=''):
639
self.script_runner.run_script(self, '''
640
$ brz checkout %(option)s repo/trunk checkout
642
$ brz branch --switch ../repo/trunk ../repo/branched
643
2>Branched 0 revisions.
644
2>Tree is up to date at revision 0.
645
2>Switched to branch:...branched...
648
bound_branch = branch.Branch.open_containing('checkout')[0]
649
master_branch = branch.Branch.open_containing('repo/branched')[0]
650
return (bound_branch, master_branch)
652
def test_branch_switch_parent_lightweight(self):
653
"""Lightweight checkout using brz branch --switch."""
654
bb, mb = self._checkout_and_branch(option='--lightweight')
655
self.assertParent('repo/trunk', bb)
656
self.assertParent('repo/trunk', mb)
658
def test_branch_switch_parent_heavyweight(self):
659
"""Heavyweight checkout using brz branch --switch."""
660
bb, mb = self._checkout_and_branch()
661
self.assertParent('repo/trunk', bb)
662
self.assertParent('repo/trunk', mb)