/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/blackbox/test_branch.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from breezy import (
23
23
    branch,
 
24
    bzrdir,
24
25
    controldir,
25
26
    errors,
26
27
    revision as _mod_revision,
27
28
    tests,
28
29
    )
29
 
from breezy.bzr import (
30
 
    bzrdir,
31
 
    )
32
 
from breezy.bzr.knitrepo import RepositoryFormatKnit1
 
30
from breezy.repofmt.knitrepo import RepositoryFormatKnit1
33
31
from breezy.tests import (
34
32
    fixtures,
35
33
    test_server,
38
36
    HardlinkFeature,
39
37
    )
40
38
from breezy.tests.blackbox import test_switch
 
39
from breezy.tests.matchers import ContainsNoVfsCalls
41
40
from breezy.tests.test_sftp_transport import TestCaseWithSFTPServer
42
41
from breezy.tests.script import run_script
43
42
from breezy.urlutils import local_path_to_url, strip_trailing_slash
48
47
 
49
48
    def example_branch(self, path='.', format=None):
50
49
        tree = self.make_branch_and_tree(path, format=format)
51
 
        self.build_tree_contents([(path + '/hello', b'foo')])
 
50
        self.build_tree_contents([(path + '/hello', 'foo')])
52
51
        tree.add('hello')
53
52
        tree.commit(message='setup')
54
 
        self.build_tree_contents([(path + '/goodbye', b'baz')])
 
53
        self.build_tree_contents([(path + '/goodbye', 'baz')])
55
54
        tree.add('goodbye')
56
55
        tree.commit(message='setup')
57
56
        return tree
64
63
        self.run_bzr('branch a c -r 1')
65
64
        # previously was erroneously created by branching
66
65
        self.assertFalse(b._transport.has('branch-name'))
67
 
        b.controldir.open_workingtree().commit(message='foo', allow_pointless=True)
 
66
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
68
67
 
69
68
    def test_branch_no_to_location(self):
70
69
        """The to_location is derived from the source branch name."""
80
79
        out, err = self.run_bzr(
81
80
            'init --format=development-colo file:b,branch=orig')
82
81
        self.assertEqual(
83
 
            """Created a standalone tree (format: development-colo)\n""",
 
82
            """Created a lightweight checkout (format: development-colo)\n""",
84
83
            out)
85
84
        self.assertEqual('', err)
86
85
        out, err = self.run_bzr(
90
89
        out, err = self.run_bzr('branches b')
91
90
        self.assertEqual("  orig\n  thiswasa\n", out)
92
91
        self.assertEqual('', err)
93
 
        out, err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
 
92
        out,err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
94
93
        self.assertEqual('', out)
95
94
        self.assertEqual(
96
95
            'brz: ERROR: Already a branch: "file:b,branch=orig".\n', err)
97
96
 
98
97
    def test_from_colocated(self):
99
98
        """Branch from a colocated branch into a regular branch."""
100
 
        os.mkdir('b')
101
 
        tree = self.example_branch('b/a', format='development-colo')
102
 
        tree.controldir.create_branch(name='somecolo')
 
99
        tree = self.example_branch('a', format='development-colo')
 
100
        tree.bzrdir.create_branch(name='somecolo')
103
101
        out, err = self.run_bzr('branch %s,branch=somecolo' %
104
 
                                local_path_to_url('b/a'))
105
 
        self.assertEqual('', out)
106
 
        self.assertEqual('Branched 0 revisions.\n', err)
107
 
        self.assertPathExists('a')
108
 
 
109
 
    def test_from_name(self):
110
 
        """Branch from a colocated branch into a regular branch."""
111
 
        os.mkdir('b')
112
 
        tree = self.example_branch('b/a', format='development-colo')
113
 
        tree.controldir.create_branch(name='somecolo')
114
 
        out, err = self.run_bzr('branch -b somecolo %s' %
115
 
                                local_path_to_url('b/a'))
116
 
        self.assertEqual('', out)
117
 
        self.assertEqual('Branched 0 revisions.\n', err)
118
 
        self.assertPathExists('a')
 
102
            local_path_to_url('a'))
 
103
        self.assertEqual('', out)
 
104
        self.assertEqual('Branched 0 revisions.\n', err)
 
105
        self.assertPathExists("somecolo")
119
106
 
120
107
    def test_branch_broken_pack(self):
121
108
        """branching with a corrupted pack file."""
130
117
            c = f.read(1)
131
118
            f.seek(-5, os.SEEK_END)
132
119
            # Make sure we inject a value different than the one we just read
133
 
            if c == b'\xFF':
134
 
                corrupt = b'\x00'
 
120
            if c == '\xFF':
 
121
                corrupt = '\x00'
135
122
            else:
136
 
                corrupt = b'\xFF'
137
 
            f.write(corrupt)  # make sure we corrupt something
 
123
                corrupt = '\xFF'
 
124
            f.write(corrupt) # make sure we corrupt something
138
125
        self.run_bzr_error(['Corruption while decompressing repository file'],
139
 
                           'branch a b', retcode=3)
 
126
                            'branch a b', retcode=3)
140
127
 
141
128
    def test_branch_switch_no_branch(self):
142
129
        # No branch in the current directory:
144
131
        self.example_branch('a')
145
132
        self.make_repository('current')
146
133
        self.run_bzr_error(['No WorkingTree exists for'],
147
 
                           'branch --switch ../a ../b', working_dir='current')
 
134
            'branch --switch ../a ../b', working_dir='current')
148
135
        a = branch.Branch.open('a')
149
136
        b = branch.Branch.open('b')
150
137
        self.assertEqual(a.last_revision(), b.last_revision())
156
143
        self.example_branch('a')
157
144
        self.make_branch('current')
158
145
        self.run_bzr_error(['No WorkingTree exists for'],
159
 
                           'branch --switch ../a ../b', working_dir='current')
 
146
            'branch --switch ../a ../b', working_dir='current')
160
147
        a = branch.Branch.open('a')
161
148
        b = branch.Branch.open('b')
162
149
        self.assertEqual(a.last_revision(), b.last_revision())
171
158
        tree = self.make_branch_and_tree('current')
172
159
        c1 = tree.commit('some diverged change')
173
160
        self.run_bzr_error(['Cannot switch a branch, only a checkout'],
174
 
                           'branch --switch ../a ../b', working_dir='current')
 
161
            'branch --switch ../a ../b', working_dir='current')
175
162
        a = branch.Branch.open('a')
176
163
        b = branch.Branch.open('b')
177
164
        self.assertEqual(a.last_revision(), b.last_revision())
180
167
 
181
168
    def test_branch_into_empty_dir(self):
182
169
        t = self.example_branch('source')
183
 
        self.make_controldir('target')
 
170
        self.make_bzrdir('target')
184
171
        self.run_bzr("branch source target")
185
172
        self.assertEqual(2, len(t.branch.repository.all_revision_ids()))
186
173
 
221
208
        shared_repo.set_make_working_trees(True)
222
209
 
223
210
        def make_shared_tree(path):
224
 
            shared_repo.controldir.root_transport.mkdir(path)
 
211
            shared_repo.bzrdir.root_transport.mkdir(path)
225
212
            controldir.ControlDir.create_branch_convenience('repo/' + path)
226
213
            return WorkingTree.open('repo/' + path)
227
214
        tree_a = make_shared_tree('a')
228
215
        self.build_tree(['repo/a/file'])
229
216
        tree_a.add('file')
230
 
        tree_a.commit('commit a-1', rev_id=b'a-1')
231
 
        with open('repo/a/file', 'ab') as f:
232
 
            f.write(b'more stuff\n')
233
 
        tree_a.commit('commit a-2', rev_id=b'a-2')
 
217
        tree_a.commit('commit a-1', rev_id='a-1')
 
218
        f = open('repo/a/file', 'ab')
 
219
        f.write('more stuff\n')
 
220
        f.close()
 
221
        tree_a.commit('commit a-2', rev_id='a-2')
234
222
 
235
223
        tree_b = make_shared_tree('b')
236
224
        self.build_tree(['repo/b/file'])
237
225
        tree_b.add('file')
238
 
        tree_b.commit('commit b-1', rev_id=b'b-1')
 
226
        tree_b.commit('commit b-1', rev_id='b-1')
239
227
 
240
 
        self.assertTrue(shared_repo.has_revision(b'a-1'))
241
 
        self.assertTrue(shared_repo.has_revision(b'a-2'))
242
 
        self.assertTrue(shared_repo.has_revision(b'b-1'))
 
228
        self.assertTrue(shared_repo.has_revision('a-1'))
 
229
        self.assertTrue(shared_repo.has_revision('a-2'))
 
230
        self.assertTrue(shared_repo.has_revision('b-1'))
243
231
 
244
232
        # Now that we have a repository with shared files, make sure
245
233
        # that things aren't copied out by a 'branch'
246
234
        self.run_bzr('branch repo/b branch-b')
247
235
        pushed_tree = WorkingTree.open('branch-b')
248
236
        pushed_repo = pushed_tree.branch.repository
249
 
        self.assertFalse(pushed_repo.has_revision(b'a-1'))
250
 
        self.assertFalse(pushed_repo.has_revision(b'a-2'))
251
 
        self.assertTrue(pushed_repo.has_revision(b'b-1'))
 
237
        self.assertFalse(pushed_repo.has_revision('a-1'))
 
238
        self.assertFalse(pushed_repo.has_revision('a-2'))
 
239
        self.assertTrue(pushed_repo.has_revision('b-1'))
252
240
 
253
241
    def test_branch_hardlink(self):
254
242
        self.requireFeature(HardlinkFeature)
275
263
        self.build_tree(['source/file1'])
276
264
        source.add('file1')
277
265
        source.commit('added file')
278
 
        source.controldir.sprout('second')
 
266
        source.bzrdir.sprout('second')
279
267
        out, err = self.run_bzr('branch source target --files-from second'
280
268
                                ' --hardlink')
281
269
        source_stat = os.stat('source/file1')
291
279
        b = branch.Branch.open('repo/target')
292
280
        expected_repo_path = os.path.abspath('repo/target/.bzr/repository')
293
281
        self.assertEqual(strip_trailing_slash(b.repository.base),
294
 
                         strip_trailing_slash(local_path_to_url(expected_repo_path)))
 
282
            strip_trailing_slash(local_path_to_url(expected_repo_path)))
295
283
 
296
284
    def test_branch_no_tree(self):
297
285
        self.example_branch('source')
303
291
        self.example_branch('a')
304
292
        # existing dir with similar files but no .brz dir
305
293
        self.build_tree_contents([('b/',)])
306
 
        self.build_tree_contents([('b/hello', b'bar')])  # different content
307
 
        self.build_tree_contents([('b/goodbye', b'baz')])  # same content
 
294
        self.build_tree_contents([('b/hello', 'bar')])  # different content
 
295
        self.build_tree_contents([('b/goodbye', 'baz')])# same content
308
296
        # fails without --use-existing-dir
309
 
        out, err = self.run_bzr('branch a b', retcode=3)
 
297
        out,err = self.run_bzr('branch a b', retcode=3)
310
298
        self.assertEqual('', out)
311
299
        self.assertEqual('brz: ERROR: Target directory "b" already exists.\n',
312
 
                         err)
 
300
            err)
313
301
        # force operation
314
302
        self.run_bzr('branch a b --use-existing-dir')
315
303
        # check conflicts
316
304
        self.assertPathExists('b/hello.moved')
317
305
        self.assertPathDoesNotExist('b/godbye.moved')
318
306
        # we can't branch into branch
319
 
        out, err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
 
307
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
320
308
        self.assertEqual('', out)
321
309
        self.assertEqual('brz: ERROR: Already a branch: "b".\n', err)
322
310
 
330
318
    def test_branch_with_post_branch_init_hook(self):
331
319
        calls = []
332
320
        branch.Branch.hooks.install_named_hook('post_branch_init',
333
 
                                               calls.append, None)
 
321
            calls.append, None)
334
322
        self.assertLength(0, calls)
335
323
        self.example_branch('a')
336
324
        self.assertLength(1, calls)
340
328
    def test_checkout_with_post_branch_init_hook(self):
341
329
        calls = []
342
330
        branch.Branch.hooks.install_named_hook('post_branch_init',
343
 
                                               calls.append, None)
 
331
            calls.append, None)
344
332
        self.assertLength(0, calls)
345
333
        self.example_branch('a')
346
334
        self.assertLength(1, calls)
350
338
    def test_lightweight_checkout_with_post_branch_init_hook(self):
351
339
        calls = []
352
340
        branch.Branch.hooks.install_named_hook('post_branch_init',
353
 
                                               calls.append, None)
 
341
            calls.append, None)
354
342
        self.assertLength(0, calls)
355
343
        self.example_branch('a')
356
344
        self.assertLength(1, calls)
359
347
 
360
348
    def test_branch_fetches_all_tags(self):
361
349
        builder = self.make_branch_builder('source')
362
 
        source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(
363
 
            builder)
364
 
        source.tags.set_tag('tag-a', rev2)
 
350
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
351
        source.tags.set_tag('tag-a', 'rev-2')
365
352
        source.get_config_stack().set('branch.fetch_tags', True)
366
353
        # Now source has a tag not in its ancestry.  Make a branch from it.
367
354
        self.run_bzr('branch source new-branch')
368
355
        new_branch = branch.Branch.open('new-branch')
369
356
        # The tag is present, and so is its revision.
370
 
        self.assertEqual(rev2, new_branch.tags.lookup_tag('tag-a'))
371
 
        new_branch.repository.get_revision(rev2)
372
 
 
373
 
    def test_branch_with_nested_trees(self):
374
 
        orig = self.make_branch_and_tree('source', format='development-subtree')
375
 
        subtree = self.make_branch_and_tree('source/subtree')
376
 
        self.build_tree(['source/subtree/a'])
377
 
        subtree.add(['a'])
378
 
        subtree.commit('add subtree contents')
379
 
        orig.add_reference(subtree)
380
 
        orig.set_reference_info('subtree', subtree.branch.user_url)
381
 
        orig.commit('add subtree')
382
 
 
383
 
        self.run_bzr('branch source target')
384
 
 
385
 
        target = WorkingTree.open('target')
386
 
        target_subtree = WorkingTree.open('target/subtree')
387
 
        self.assertTreesEqual(orig, target)
388
 
        self.assertTreesEqual(subtree, target_subtree)
389
 
 
390
 
    def test_branch_with_nested_trees_reference_unset(self):
391
 
        orig = self.make_branch_and_tree('source', format='development-subtree')
392
 
        subtree = self.make_branch_and_tree('source/subtree')
393
 
        self.build_tree(['source/subtree/a'])
394
 
        subtree.add(['a'])
395
 
        subtree.commit('add subtree contents')
396
 
        orig.add_reference(subtree)
397
 
        orig.commit('add subtree')
398
 
 
399
 
        self.run_bzr('branch source target')
400
 
 
401
 
        target = WorkingTree.open('target')
402
 
        self.assertRaises(errors.NotBranchError, WorkingTree.open, 'target/subtree')
403
 
 
404
 
    def test_branch_with_nested_trees_no_recurse(self):
405
 
        orig = self.make_branch_and_tree('source', format='development-subtree')
406
 
        subtree = self.make_branch_and_tree('source/subtree')
407
 
        self.build_tree(['source/subtree/a'])
408
 
        subtree.add(['a'])
409
 
        subtree.commit('add subtree contents')
410
 
        orig.add_reference(subtree)
411
 
        orig.commit('add subtree')
412
 
 
413
 
        self.run_bzr('branch --no-recurse-nested source target')
414
 
 
415
 
        target = WorkingTree.open('target')
416
 
        self.addCleanup(subtree.lock_read().unlock)
417
 
        basis = subtree.basis_tree()
418
 
        self.addCleanup(basis.lock_read().unlock)
419
 
        self.assertRaises(errors.NotBranchError, WorkingTree.open, 'target/subtree')
 
357
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
 
358
        new_branch.repository.get_revision('rev-2')
420
359
 
421
360
 
422
361
class TestBranchStacked(tests.TestCaseWithTransport):
435
374
    def assertRevisionsInBranchRepository(self, revid_list, branch_path):
436
375
        repo = branch.Branch.open(branch_path).repository
437
376
        self.assertEqual(set(revid_list),
438
 
                         repo.has_revisions(revid_list))
 
377
            repo.has_revisions(revid_list))
439
378
 
440
379
    def test_branch_stacked_branch_not_stacked(self):
441
380
        """Branching a stacked branch is not stacked by default"""
442
381
        # We have a mainline
443
382
        trunk_tree = self.make_branch_and_tree('target',
444
 
                                               format='1.9')
 
383
            format='1.9')
445
384
        trunk_tree.commit('mainline')
446
385
        # and a branch from it which is stacked
447
386
        branch_tree = self.make_branch_and_tree('branch',
448
 
                                                format='1.9')
 
387
            format='1.9')
449
388
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
450
389
        # with some work on it
451
 
        work_tree = trunk_tree.branch.controldir.sprout(
452
 
            'local').open_workingtree()
 
390
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
453
391
        work_tree.commit('moar work plz')
454
392
        work_tree.branch.push(branch_tree.branch)
455
393
        # branching our local branch gives us a new stacked branch pointing at
457
395
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
458
396
        self.assertEqual('', out)
459
397
        self.assertEqual('Branched 2 revisions.\n',
460
 
                         err)
 
398
            err)
461
399
        # it should have preserved the branch format, and so it should be
462
400
        # capable of supporting stacking, but not actually have a stacked_on
463
401
        # branch configured
464
402
        self.assertRaises(errors.NotStacked,
465
 
                          controldir.ControlDir.open('newbranch').open_branch().get_stacked_on_url)
 
403
            controldir.ControlDir.open('newbranch').open_branch().get_stacked_on_url)
466
404
 
467
405
    def test_branch_stacked_branch_stacked(self):
468
406
        """Asking to stack on a stacked branch does work"""
469
407
        # We have a mainline
470
408
        trunk_tree = self.make_branch_and_tree('target',
471
 
                                               format='1.9')
 
409
            format='1.9')
472
410
        trunk_revid = trunk_tree.commit('mainline')
473
411
        # and a branch from it which is stacked
474
412
        branch_tree = self.make_branch_and_tree('branch',
475
 
                                                format='1.9')
 
413
            format='1.9')
476
414
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
477
415
        # with some work on it
478
 
        work_tree = trunk_tree.branch.controldir.sprout(
479
 
            'local').open_workingtree()
 
416
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
480
417
        branch_revid = work_tree.commit('moar work plz')
481
418
        work_tree.branch.push(branch_tree.branch)
482
419
        # you can chain branches on from there
483
420
        out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
484
421
        self.assertEqual('', out)
485
422
        self.assertEqual('Created new stacked branch referring to %s.\n' %
486
 
                         branch_tree.branch.base, err)
 
423
            branch_tree.branch.base, err)
487
424
        self.assertEqual(branch_tree.branch.base,
488
 
                         branch.Branch.open('branch2').get_stacked_on_url())
 
425
            branch.Branch.open('branch2').get_stacked_on_url())
489
426
        branch2_tree = WorkingTree.open('branch2')
490
427
        branch2_revid = work_tree.commit('work on second stacked branch')
491
428
        work_tree.branch.push(branch2_tree.branch)
497
434
    def test_branch_stacked(self):
498
435
        # We have a mainline
499
436
        trunk_tree = self.make_branch_and_tree('mainline',
500
 
                                               format='1.9')
 
437
            format='1.9')
501
438
        original_revid = trunk_tree.commit('mainline')
502
439
        self.assertRevisionInRepository('mainline', original_revid)
503
440
        # and a branch from it which is stacked
504
441
        out, err = self.run_bzr(['branch', '--stacked', 'mainline',
505
 
                                 'newbranch'])
 
442
            'newbranch'])
506
443
        self.assertEqual('', out)
507
444
        self.assertEqual('Created new stacked branch referring to %s.\n' %
508
 
                         trunk_tree.branch.base, err)
 
445
            trunk_tree.branch.base, err)
509
446
        self.assertRevisionNotInRepository('newbranch', original_revid)
510
447
        new_branch = branch.Branch.open('newbranch')
511
448
        self.assertEqual(trunk_tree.branch.base,
531
468
            '  Branch format 7\n'
532
469
            'Doing on-the-fly conversion from RepositoryFormatKnitPack1() to RepositoryFormatKnitPack5().\n'
533
470
            'This may take some time. Upgrade the repositories to the same format for better performance.\n'
534
 
            'Created new stacked branch referring to %s.\n' %
535
 
            (trunk.base,),
 
471
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
536
472
            err)
537
473
 
538
474
    def test_branch_stacked_from_rich_root_non_stackable(self):
551
487
            err)
552
488
 
553
489
 
 
490
class TestSmartServerBranching(tests.TestCaseWithTransport):
 
491
 
 
492
    def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
 
493
        self.setup_smart_server_with_call_log()
 
494
        t = self.make_branch_and_tree('from')
 
495
        for count in range(9):
 
496
            t.commit(message='commit %d' % count)
 
497
        self.reset_smart_call_log()
 
498
        out, err = self.run_bzr(['branch', self.get_url('from'),
 
499
            self.get_url('target')])
 
500
        # This figure represent the amount of work to perform this use case. It
 
501
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
502
        # being too low. If rpc_count increases, more network roundtrips have
 
503
        # become necessary for this use case. Please do not adjust this number
 
504
        # upwards without agreement from bzr's network support maintainers.
 
505
        self.assertLength(2, self.hpss_connections)
 
506
        self.assertLength(33, self.hpss_calls)
 
507
        self.expectFailure("branching to the same branch requires VFS access",
 
508
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
 
509
 
 
510
    def test_branch_from_trivial_branch_streaming_acceptance(self):
 
511
        self.setup_smart_server_with_call_log()
 
512
        t = self.make_branch_and_tree('from')
 
513
        for count in range(9):
 
514
            t.commit(message='commit %d' % count)
 
515
        self.reset_smart_call_log()
 
516
        out, err = self.run_bzr(['branch', self.get_url('from'),
 
517
            'local-target'])
 
518
        # This figure represent the amount of work to perform this use case. It
 
519
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
520
        # being too low. If rpc_count increases, more network roundtrips have
 
521
        # become necessary for this use case. Please do not adjust this number
 
522
        # upwards without agreement from bzr's network support maintainers.
 
523
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
524
        self.assertLength(10, self.hpss_calls)
 
525
        self.assertLength(1, self.hpss_connections)
 
526
 
 
527
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
 
528
        self.setup_smart_server_with_call_log()
 
529
        t = self.make_branch_and_tree('trunk')
 
530
        for count in range(8):
 
531
            t.commit(message='commit %d' % count)
 
532
        tree2 = t.branch.bzrdir.sprout('feature', stacked=True
 
533
            ).open_workingtree()
 
534
        local_tree = t.branch.bzrdir.sprout('local-working').open_workingtree()
 
535
        local_tree.commit('feature change')
 
536
        local_tree.branch.push(tree2.branch)
 
537
        self.reset_smart_call_log()
 
538
        out, err = self.run_bzr(['branch', self.get_url('feature'),
 
539
            'local-target'])
 
540
        # This figure represent the amount of work to perform this use case. It
 
541
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
542
        # being too low. If rpc_count increases, more network roundtrips have
 
543
        # become necessary for this use case. Please do not adjust this number
 
544
        # upwards without agreement from bzr's network support maintainers.
 
545
        self.assertLength(15, self.hpss_calls)
 
546
        self.assertLength(1, self.hpss_connections)
 
547
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
548
 
 
549
    def test_branch_from_branch_with_tags(self):
 
550
        self.setup_smart_server_with_call_log()
 
551
        builder = self.make_branch_builder('source')
 
552
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
553
        source.get_config_stack().set('branch.fetch_tags', True)
 
554
        source.tags.set_tag('tag-a', 'rev-2')
 
555
        source.tags.set_tag('tag-missing', 'missing-rev')
 
556
        # Now source has a tag not in its ancestry.  Make a branch from it.
 
557
        self.reset_smart_call_log()
 
558
        out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
 
559
        # This figure represent the amount of work to perform this use case. It
 
560
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
561
        # being too low. If rpc_count increases, more network roundtrips have
 
562
        # become necessary for this use case. Please do not adjust this number
 
563
        # upwards without agreement from bzr's network support maintainers.
 
564
        self.assertLength(10, self.hpss_calls)
 
565
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
566
        self.assertLength(1, self.hpss_connections)
 
567
 
 
568
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
 
569
        self.setup_smart_server_with_call_log()
 
570
        t = self.make_branch_and_tree('from')
 
571
        for count in range(9):
 
572
            t.commit(message='commit %d' % count)
 
573
        self.reset_smart_call_log()
 
574
        out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
 
575
            'local-target'])
 
576
        # XXX: the number of hpss calls for this case isn't deterministic yet,
 
577
        # so we can't easily assert about the number of calls.
 
578
        #self.assertLength(XXX, self.hpss_calls)
 
579
        # We can assert that none of the calls were readv requests for rix
 
580
        # files, though (demonstrating that at least get_parent_map calls are
 
581
        # not using VFS RPCs).
 
582
        readvs_of_rix_files = [
 
583
            c for c in self.hpss_calls
 
584
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
 
585
        self.assertLength(1, self.hpss_connections)
 
586
        self.assertLength(0, readvs_of_rix_files)
 
587
        self.expectFailure("branching to stacked requires VFS access",
 
588
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
 
589
 
 
590
 
554
591
class TestRemoteBranch(TestCaseWithSFTPServer):
555
592
 
556
593
    def setUp(self):
557
594
        super(TestRemoteBranch, self).setUp()
558
595
        tree = self.make_branch_and_tree('branch')
559
 
        self.build_tree_contents([('branch/file', b'file content\n')])
 
596
        self.build_tree_contents([('branch/file', 'file content\n')])
560
597
        tree.add('file')
561
598
        tree.commit('file created')
562
599
 
575
612
        self.assertFalse(t.has('remote/file'))
576
613
 
577
614
 
 
615
class TestDeprecatedAliases(tests.TestCaseWithTransport):
 
616
 
 
617
    def test_deprecated_aliases(self):
 
618
        """brz branch can be called clone or get, but those names are
 
619
        deprecated.
 
620
 
 
621
        See bug 506265.
 
622
        """
 
623
        for command in ['clone', 'get']:
 
624
            run_script(self, """
 
625
            $ brz %(command)s A B
 
626
            2>The command 'brz %(command)s' has been deprecated in brz 2.4. Please use 'brz branch' instead.
 
627
            2>brz: ERROR: Not a branch...
 
628
            """ % locals())
 
629
 
 
630
 
578
631
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
579
632
 
580
633
    def _checkout_and_branch(self, option=''):