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_from_name(self):
111
"""Branch from a colocated branch into a regular branch."""
113
tree = self.example_branch('b/a', format='development-colo')
114
tree.controldir.create_branch(name='somecolo')
115
out, err = self.run_bzr('branch -b somecolo %s' %
116
local_path_to_url('b/a'))
117
self.assertEqual('', out)
118
self.assertEqual('Branched 0 revisions.\n', err)
119
self.assertPathExists('a')
121
def test_branch_broken_pack(self):
122
"""branching with a corrupted pack file."""
123
self.example_branch('a')
124
# add some corruption
125
packs_dir = 'a/.bzr/repository/packs/'
126
fname = packs_dir + os.listdir(packs_dir)[0]
127
with open(fname, 'rb+') as f:
128
# Start from the end of the file to avoid choosing a place bigger
129
# than the file itself.
130
f.seek(-5, os.SEEK_END)
132
f.seek(-5, os.SEEK_END)
133
# Make sure we inject a value different than the one we just read
138
f.write(corrupt) # make sure we corrupt something
139
self.run_bzr_error(['Corruption while decompressing repository file'],
140
'branch a b', retcode=3)
142
def test_branch_switch_no_branch(self):
143
# No branch in the current directory:
144
# => new branch will be created, but switch fails
145
self.example_branch('a')
146
self.make_repository('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())
153
def test_branch_switch_no_wt(self):
154
# No working tree in the current directory:
155
# => new branch will be created, but switch fails and the current
156
# branch is unmodified
157
self.example_branch('a')
158
self.make_branch('current')
159
self.run_bzr_error(['No WorkingTree exists for'],
160
'branch --switch ../a ../b', working_dir='current')
161
a = branch.Branch.open('a')
162
b = branch.Branch.open('b')
163
self.assertEqual(a.last_revision(), b.last_revision())
164
work = branch.Branch.open('current')
165
self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
167
def test_branch_switch_no_checkout(self):
168
# Standalone branch in the current directory:
169
# => new branch will be created, but switch fails and the current
170
# branch is unmodified
171
self.example_branch('a')
172
tree = self.make_branch_and_tree('current')
173
c1 = tree.commit('some diverged change')
174
self.run_bzr_error(['Cannot switch a branch, only a checkout'],
175
'branch --switch ../a ../b', working_dir='current')
176
a = branch.Branch.open('a')
177
b = branch.Branch.open('b')
178
self.assertEqual(a.last_revision(), b.last_revision())
179
work = branch.Branch.open('current')
180
self.assertEqual(work.last_revision(), c1)
182
def test_branch_into_empty_dir(self):
183
t = self.example_branch('source')
184
self.make_controldir('target')
185
self.run_bzr("branch source target")
186
self.assertEqual(2, len(t.branch.repository.all_revision_ids()))
188
def test_branch_switch_checkout(self):
189
# Checkout in the current directory:
190
# => new branch will be created and checkout bound to the new branch
191
self.example_branch('a')
192
self.run_bzr('checkout a current')
193
out, err = self.run_bzr('branch --switch ../a ../b',
194
working_dir='current')
195
a = branch.Branch.open('a')
196
b = branch.Branch.open('b')
197
self.assertEqual(a.last_revision(), b.last_revision())
198
work = WorkingTree.open('current')
199
self.assertEndsWith(work.branch.get_bound_location(), '/b/')
200
self.assertContainsRe(err, "Switched to branch: .*/b/")
202
def test_branch_switch_lightweight_checkout(self):
203
# Lightweight checkout in the current directory:
204
# => new branch will be created and lightweight checkout pointed to
206
self.example_branch('a')
207
self.run_bzr('checkout --lightweight a current')
208
out, err = self.run_bzr('branch --switch ../a ../b',
209
working_dir='current')
210
a = branch.Branch.open('a')
211
b = branch.Branch.open('b')
212
self.assertEqual(a.last_revision(), b.last_revision())
213
work = WorkingTree.open('current')
214
self.assertEndsWith(work.branch.base, '/b/')
215
self.assertContainsRe(err, "Switched to branch: .*/b/")
217
def test_branch_only_copies_history(self):
218
# Knit branches should only push the history for the current revision.
219
format = bzrdir.BzrDirMetaFormat1()
220
format.repository_format = RepositoryFormatKnit1()
221
shared_repo = self.make_repository('repo', format=format, shared=True)
222
shared_repo.set_make_working_trees(True)
224
def make_shared_tree(path):
225
shared_repo.controldir.root_transport.mkdir(path)
226
controldir.ControlDir.create_branch_convenience('repo/' + path)
227
return WorkingTree.open('repo/' + path)
228
tree_a = make_shared_tree('a')
229
self.build_tree(['repo/a/file'])
231
tree_a.commit('commit a-1', rev_id=b'a-1')
232
with open('repo/a/file', 'ab') as f:
233
f.write(b'more stuff\n')
234
tree_a.commit('commit a-2', rev_id=b'a-2')
236
tree_b = make_shared_tree('b')
237
self.build_tree(['repo/b/file'])
239
tree_b.commit('commit b-1', rev_id=b'b-1')
241
self.assertTrue(shared_repo.has_revision(b'a-1'))
242
self.assertTrue(shared_repo.has_revision(b'a-2'))
243
self.assertTrue(shared_repo.has_revision(b'b-1'))
245
# Now that we have a repository with shared files, make sure
246
# that things aren't copied out by a 'branch'
247
self.run_bzr('branch repo/b branch-b')
248
pushed_tree = WorkingTree.open('branch-b')
249
pushed_repo = pushed_tree.branch.repository
250
self.assertFalse(pushed_repo.has_revision(b'a-1'))
251
self.assertFalse(pushed_repo.has_revision(b'a-2'))
252
self.assertTrue(pushed_repo.has_revision(b'b-1'))
254
def test_branch_hardlink(self):
255
self.requireFeature(HardlinkFeature)
256
source = self.make_branch_and_tree('source')
257
self.build_tree(['source/file1'])
259
source.commit('added file')
260
out, err = self.run_bzr(['branch', 'source', 'target', '--hardlink'])
261
source_stat = os.stat('source/file1')
262
target_stat = os.stat('target/file1')
263
self.assertEqual(source_stat, target_stat)
265
def test_branch_files_from(self):
266
source = self.make_branch_and_tree('source')
267
self.build_tree(['source/file1'])
269
source.commit('added file')
270
out, err = self.run_bzr('branch source target --files-from source')
271
self.assertPathExists('target/file1')
273
def test_branch_files_from_hardlink(self):
274
self.requireFeature(HardlinkFeature)
275
source = self.make_branch_and_tree('source')
276
self.build_tree(['source/file1'])
278
source.commit('added file')
279
source.controldir.sprout('second')
280
out, err = self.run_bzr('branch source target --files-from second'
282
source_stat = os.stat('source/file1')
283
second_stat = os.stat('second/file1')
284
target_stat = os.stat('target/file1')
285
self.assertNotEqual(source_stat, target_stat)
286
self.assertEqual(second_stat, target_stat)
288
def test_branch_standalone(self):
289
shared_repo = self.make_repository('repo', shared=True)
290
self.example_branch('source')
291
self.run_bzr('branch --standalone source repo/target')
292
b = branch.Branch.open('repo/target')
293
expected_repo_path = os.path.abspath('repo/target/.bzr/repository')
294
self.assertEqual(strip_trailing_slash(b.repository.base),
295
strip_trailing_slash(local_path_to_url(expected_repo_path)))
297
def test_branch_no_tree(self):
298
self.example_branch('source')
299
self.run_bzr('branch --no-tree source target')
300
self.assertPathDoesNotExist('target/hello')
301
self.assertPathDoesNotExist('target/goodbye')
303
def test_branch_into_existing_dir(self):
304
self.example_branch('a')
305
# existing dir with similar files but no .brz dir
306
self.build_tree_contents([('b/',)])
307
self.build_tree_contents([('b/hello', b'bar')]) # different content
308
self.build_tree_contents([('b/goodbye', b'baz')]) # same content
309
# fails without --use-existing-dir
310
out, err = self.run_bzr('branch a b', retcode=3)
311
self.assertEqual('', out)
312
self.assertEqual('brz: ERROR: Target directory "b" already exists.\n',
315
self.run_bzr('branch a b --use-existing-dir')
317
self.assertPathExists('b/hello.moved')
318
self.assertPathDoesNotExist('b/godbye.moved')
319
# we can't branch into branch
320
out, err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
321
self.assertEqual('', out)
322
self.assertEqual('brz: ERROR: Already a branch: "b".\n', err)
324
def test_branch_bind(self):
325
self.example_branch('a')
326
out, err = self.run_bzr('branch a b --bind')
327
self.assertEndsWith(err, "New branch bound to a\n")
328
b = branch.Branch.open('b')
329
self.assertEndsWith(b.get_bound_location(), '/a/')
331
def test_branch_with_post_branch_init_hook(self):
333
branch.Branch.hooks.install_named_hook('post_branch_init',
335
self.assertLength(0, calls)
336
self.example_branch('a')
337
self.assertLength(1, calls)
338
self.run_bzr('branch a b')
339
self.assertLength(2, calls)
341
def test_checkout_with_post_branch_init_hook(self):
343
branch.Branch.hooks.install_named_hook('post_branch_init',
345
self.assertLength(0, calls)
346
self.example_branch('a')
347
self.assertLength(1, calls)
348
self.run_bzr('checkout a b')
349
self.assertLength(2, calls)
351
def test_lightweight_checkout_with_post_branch_init_hook(self):
353
branch.Branch.hooks.install_named_hook('post_branch_init',
355
self.assertLength(0, calls)
356
self.example_branch('a')
357
self.assertLength(1, calls)
358
self.run_bzr('checkout --lightweight a b')
359
self.assertLength(2, calls)
361
def test_branch_fetches_all_tags(self):
362
builder = self.make_branch_builder('source')
363
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(
365
source.tags.set_tag('tag-a', rev2)
366
source.get_config_stack().set('branch.fetch_tags', True)
367
# Now source has a tag not in its ancestry. Make a branch from it.
368
self.run_bzr('branch source new-branch')
369
new_branch = branch.Branch.open('new-branch')
370
# The tag is present, and so is its revision.
371
self.assertEqual(rev2, new_branch.tags.lookup_tag('tag-a'))
372
new_branch.repository.get_revision(rev2)
374
def test_branch_with_nested_trees(self):
375
orig = self.make_branch_and_tree('source', format='development-subtree')
376
subtree = self.make_branch_and_tree('source/subtree')
377
self.build_tree(['source/subtree/a'])
379
subtree.commit('add subtree contents')
380
orig.add_reference(subtree)
381
orig.set_reference_info('subtree', subtree.branch.user_url)
382
orig.commit('add subtree')
384
self.run_bzr('branch source target')
386
target = WorkingTree.open('target')
387
target_subtree = WorkingTree.open('target/subtree')
388
self.assertTreesEqual(orig, target)
389
self.assertTreesEqual(subtree, target_subtree)
391
def test_branch_with_nested_trees_reference_unset(self):
392
orig = self.make_branch_and_tree('source', format='development-subtree')
393
subtree = self.make_branch_and_tree('source/subtree')
394
self.build_tree(['source/subtree/a'])
396
subtree.commit('add subtree contents')
397
orig.add_reference(subtree)
398
orig.commit('add subtree')
400
self.run_bzr('branch source target')
402
target = WorkingTree.open('target')
403
self.assertRaises(errors.NotBranchError, WorkingTree.open, 'target/subtree')
405
def test_branch_with_nested_trees_no_recurse(self):
406
orig = self.make_branch_and_tree('source', format='development-subtree')
407
subtree = self.make_branch_and_tree('source/subtree')
408
self.build_tree(['source/subtree/a'])
410
subtree.commit('add subtree contents')
411
orig.add_reference(subtree)
412
orig.commit('add subtree')
414
self.run_bzr('branch --no-recurse-nested source target')
416
target = WorkingTree.open('target')
417
self.addCleanup(subtree.lock_read().unlock)
418
basis = subtree.basis_tree()
419
self.addCleanup(basis.lock_read().unlock)
420
self.assertRaises(errors.NotBranchError, WorkingTree.open, 'target/subtree')
423
class TestBranchStacked(tests.TestCaseWithTransport):
424
"""Tests for branch --stacked"""
426
def assertRevisionInRepository(self, repo_path, revid):
427
"""Check that a revision is in a repo, disregarding stacking."""
428
repo = controldir.ControlDir.open(repo_path).open_repository()
429
self.assertTrue(repo.has_revision(revid))
431
def assertRevisionNotInRepository(self, repo_path, revid):
432
"""Check that a revision is not in a repo, disregarding stacking."""
433
repo = controldir.ControlDir.open(repo_path).open_repository()
434
self.assertFalse(repo.has_revision(revid))
436
def assertRevisionsInBranchRepository(self, revid_list, branch_path):
437
repo = branch.Branch.open(branch_path).repository
438
self.assertEqual(set(revid_list),
439
repo.has_revisions(revid_list))
441
def test_branch_stacked_branch_not_stacked(self):
442
"""Branching a stacked branch is not stacked by default"""
444
trunk_tree = self.make_branch_and_tree('target',
446
trunk_tree.commit('mainline')
447
# and a branch from it which is stacked
448
branch_tree = self.make_branch_and_tree('branch',
450
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
451
# with some work on it
452
work_tree = trunk_tree.branch.controldir.sprout(
453
'local').open_workingtree()
454
work_tree.commit('moar work plz')
455
work_tree.branch.push(branch_tree.branch)
456
# branching our local branch gives us a new stacked branch pointing at
458
out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
459
self.assertEqual('', out)
460
self.assertEqual('Branched 2 revisions.\n',
462
# it should have preserved the branch format, and so it should be
463
# capable of supporting stacking, but not actually have a stacked_on
465
self.assertRaises(errors.NotStacked,
466
controldir.ControlDir.open('newbranch').open_branch().get_stacked_on_url)
468
def test_branch_stacked_branch_stacked(self):
469
"""Asking to stack on a stacked branch does work"""
471
trunk_tree = self.make_branch_and_tree('target',
473
trunk_revid = trunk_tree.commit('mainline')
474
# and a branch from it which is stacked
475
branch_tree = self.make_branch_and_tree('branch',
477
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
478
# with some work on it
479
work_tree = trunk_tree.branch.controldir.sprout(
480
'local').open_workingtree()
481
branch_revid = work_tree.commit('moar work plz')
482
work_tree.branch.push(branch_tree.branch)
483
# you can chain branches on from there
484
out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
485
self.assertEqual('', out)
486
self.assertEqual('Created new stacked branch referring to %s.\n' %
487
branch_tree.branch.base, err)
488
self.assertEqual(branch_tree.branch.base,
489
branch.Branch.open('branch2').get_stacked_on_url())
490
branch2_tree = WorkingTree.open('branch2')
491
branch2_revid = work_tree.commit('work on second stacked branch')
492
work_tree.branch.push(branch2_tree.branch)
493
self.assertRevisionInRepository('branch2', branch2_revid)
494
self.assertRevisionsInBranchRepository(
495
[trunk_revid, branch_revid, branch2_revid],
498
def test_branch_stacked(self):
500
trunk_tree = self.make_branch_and_tree('mainline',
502
original_revid = trunk_tree.commit('mainline')
503
self.assertRevisionInRepository('mainline', original_revid)
504
# and a branch from it which is stacked
505
out, err = self.run_bzr(['branch', '--stacked', 'mainline',
507
self.assertEqual('', out)
508
self.assertEqual('Created new stacked branch referring to %s.\n' %
509
trunk_tree.branch.base, err)
510
self.assertRevisionNotInRepository('newbranch', original_revid)
511
new_branch = branch.Branch.open('newbranch')
512
self.assertEqual(trunk_tree.branch.base,
513
new_branch.get_stacked_on_url())
515
def test_branch_stacked_from_smart_server(self):
516
# We can branch stacking on a smart server
517
self.transport_server = test_server.SmartTCPServer_for_testing
518
trunk = self.make_branch('mainline', format='1.9')
519
out, err = self.run_bzr(
520
['branch', '--stacked', self.get_url('mainline'), 'shallow'])
522
def test_branch_stacked_from_non_stacked_format(self):
523
"""The origin format doesn't support stacking"""
524
trunk = self.make_branch('trunk', format='pack-0.92')
525
out, err = self.run_bzr(
526
['branch', '--stacked', 'trunk', 'shallow'])
527
# We should notify the user that we upgraded their format
528
self.assertEqualDiff(
529
'Source repository format does not support stacking, using format:\n'
530
' Packs 5 (adds stacking support, requires bzr 1.6)\n'
531
'Source branch format does not support stacking, using format:\n'
533
'Doing on-the-fly conversion from RepositoryFormatKnitPack1() to RepositoryFormatKnitPack5().\n'
534
'This may take some time. Upgrade the repositories to the same format for better performance.\n'
535
'Created new stacked branch referring to %s.\n' %
539
def test_branch_stacked_from_rich_root_non_stackable(self):
540
trunk = self.make_branch('trunk', format='rich-root-pack')
541
out, err = self.run_bzr(
542
['branch', '--stacked', 'trunk', 'shallow'])
543
# We should notify the user that we upgraded their format
544
self.assertEqualDiff(
545
'Source repository format does not support stacking, using format:\n'
546
' Packs 5 rich-root (adds stacking support, requires bzr 1.6.1)\n'
547
'Source branch format does not support stacking, using format:\n'
549
'Doing on-the-fly conversion from RepositoryFormatKnitPack4() to RepositoryFormatKnitPack5RichRoot().\n'
550
'This may take some time. Upgrade the repositories to the same format for better performance.\n'
551
'Created new stacked branch referring to %s.\n' % (trunk.base,),
555
class TestSmartServerBranching(tests.TestCaseWithTransport):
557
def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
558
self.setup_smart_server_with_call_log()
559
t = self.make_branch_and_tree('from')
560
for count in range(9):
561
t.commit(message='commit %d' % count)
562
self.reset_smart_call_log()
563
out, err = self.run_bzr(['branch', self.get_url('from'),
564
self.get_url('target')])
565
# This figure represent the amount of work to perform this use case. It
566
# is entirely ok to reduce this number if a test fails due to rpc_count
567
# being too low. If rpc_count increases, more network roundtrips have
568
# become necessary for this use case. Please do not adjust this number
569
# upwards without agreement from bzr's network support maintainers.
570
self.assertLength(2, self.hpss_connections)
571
self.assertLength(34, self.hpss_calls)
573
"branching to the same branch requires VFS access",
574
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
576
def test_branch_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', self.get_url('from'),
584
# This figure represent the amount of work to perform this use case. It
585
# is entirely ok to reduce this number if a test fails due to rpc_count
586
# being too low. If rpc_count increases, more network roundtrips have
587
# become necessary for this use case. Please do not adjust this number
588
# upwards without agreement from bzr's network support maintainers.
589
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
590
self.assertLength(11, self.hpss_calls)
591
self.assertLength(1, self.hpss_connections)
593
def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
594
self.setup_smart_server_with_call_log()
595
t = self.make_branch_and_tree('trunk')
596
for count in range(8):
597
t.commit(message='commit %d' % count)
598
tree2 = t.branch.controldir.sprout('feature', stacked=True
600
local_tree = t.branch.controldir.sprout(
601
'local-working').open_workingtree()
602
local_tree.commit('feature change')
603
local_tree.branch.push(tree2.branch)
604
self.reset_smart_call_log()
605
out, err = self.run_bzr(['branch', self.get_url('feature'),
607
# This figure represent the amount of work to perform this use case. It
608
# is entirely ok to reduce this number if a test fails due to rpc_count
609
# being too low. If rpc_count increases, more network roundtrips have
610
# become necessary for this use case. Please do not adjust this number
611
# upwards without agreement from bzr's network support maintainers.
612
self.assertLength(16, self.hpss_calls)
613
self.assertLength(1, self.hpss_connections)
614
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
616
def test_branch_from_branch_with_tags(self):
617
self.setup_smart_server_with_call_log()
618
builder = self.make_branch_builder('source')
619
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(
621
source.get_config_stack().set('branch.fetch_tags', True)
622
source.tags.set_tag('tag-a', rev2)
623
source.tags.set_tag('tag-missing', b'missing-rev')
624
# Now source has a tag not in its ancestry. Make a branch from it.
625
self.reset_smart_call_log()
626
out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
627
# This figure represent the amount of work to perform this use case. It
628
# is entirely ok to reduce this number if a test fails due to rpc_count
629
# being too low. If rpc_count increases, more network roundtrips have
630
# become necessary for this use case. Please do not adjust this number
631
# upwards without agreement from bzr's network support maintainers.
632
self.assertLength(11, self.hpss_calls)
633
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
634
self.assertLength(1, self.hpss_connections)
636
def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
637
self.setup_smart_server_with_call_log()
638
t = self.make_branch_and_tree('from')
639
for count in range(9):
640
t.commit(message='commit %d' % count)
641
self.reset_smart_call_log()
642
out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
644
# XXX: the number of hpss calls for this case isn't deterministic yet,
645
# so we can't easily assert about the number of calls.
646
#self.assertLength(XXX, self.hpss_calls)
647
# We can assert that none of the calls were readv requests for rix
648
# files, though (demonstrating that at least get_parent_map calls are
649
# not using VFS RPCs).
650
readvs_of_rix_files = [
651
c for c in self.hpss_calls
652
if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
653
self.assertLength(1, self.hpss_connections)
654
self.assertLength(0, readvs_of_rix_files)
655
self.expectFailure("branching to stacked requires VFS access",
656
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
658
def test_branch_from_branch_with_ghosts(self):
659
self.setup_smart_server_with_call_log()
660
t = self.make_branch_and_tree('from')
661
for count in range(9):
662
t.commit(message='commit %d' % count)
663
t.set_parent_ids([t.last_revision(), b'ghost'])
664
t.commit(message='add commit with parent')
665
self.reset_smart_call_log()
666
out, err = self.run_bzr(['branch', self.get_url('from'),
668
# This figure represent the amount of work to perform this use case. It
669
# is entirely ok to reduce this number if a test fails due to rpc_count
670
# being too low. If rpc_count increases, more network roundtrips have
671
# become necessary for this use case. Please do not adjust this number
672
# upwards without agreement from bzr's network support maintainers.
673
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
674
self.assertLength(12, self.hpss_calls)
675
self.assertLength(1, self.hpss_connections)
678
class TestRemoteBranch(TestCaseWithSFTPServer):
681
super(TestRemoteBranch, self).setUp()
682
tree = self.make_branch_and_tree('branch')
683
self.build_tree_contents([('branch/file', b'file content\n')])
685
tree.commit('file created')
687
def test_branch_local_remote(self):
688
self.run_bzr(['branch', 'branch', self.get_url('remote')])
689
t = self.get_transport()
690
# Ensure that no working tree what created remotely
691
self.assertFalse(t.has('remote/file'))
693
def test_branch_remote_remote(self):
694
# Light cheat: we access the branch remotely
695
self.run_bzr(['branch', self.get_url('branch'),
696
self.get_url('remote')])
697
t = self.get_transport()
698
# Ensure that no working tree what created remotely
699
self.assertFalse(t.has('remote/file'))
702
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
704
def _checkout_and_branch(self, option=''):
705
self.script_runner.run_script(self, '''
706
$ brz checkout %(option)s repo/trunk checkout
708
$ brz branch --switch ../repo/trunk ../repo/branched
709
2>Branched 0 revisions.
710
2>Tree is up to date at revision 0.
711
2>Switched to branch:...branched...
714
bound_branch = branch.Branch.open_containing('checkout')[0]
715
master_branch = branch.Branch.open_containing('repo/branched')[0]
716
return (bound_branch, master_branch)
718
def test_branch_switch_parent_lightweight(self):
719
"""Lightweight checkout using brz branch --switch."""
720
bb, mb = self._checkout_and_branch(option='--lightweight')
721
self.assertParent('repo/trunk', bb)
722
self.assertParent('repo/trunk', mb)
724
def test_branch_switch_parent_heavyweight(self):
725
"""Heavyweight checkout using brz branch --switch."""
726
bb, mb = self._checkout_and_branch()
727
self.assertParent('repo/trunk', bb)
728
self.assertParent('repo/trunk', mb)