/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 brzlib/tests/blackbox/test_branch.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
"""Black-box tests for brz branch."""
 
18
"""Black-box tests for bzr branch."""
19
19
 
20
20
import os
21
21
 
22
 
from breezy import (
 
22
from brzlib 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
33
 
from breezy.tests import (
 
30
from brzlib.repofmt.knitrepo import RepositoryFormatKnit1
 
31
from brzlib.tests import (
34
32
    fixtures,
35
33
    test_server,
36
34
    )
37
 
from breezy.tests.features import (
 
35
from brzlib.tests.features import (
38
36
    HardlinkFeature,
39
37
    )
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
 
38
from brzlib.tests.blackbox import test_switch
 
39
from brzlib.tests.matchers import ContainsNoVfsCalls
 
40
from brzlib.tests.test_sftp_transport import TestCaseWithSFTPServer
 
41
from brzlib.tests.script import run_script
 
42
from brzlib.urlutils import local_path_to_url, strip_trailing_slash
 
43
from brzlib.workingtree import WorkingTree
46
44
 
47
45
 
48
46
class TestBranch(tests.TestCaseWithTransport):
49
47
 
50
48
    def example_branch(self, path='.', format=None):
51
49
        tree = self.make_branch_and_tree(path, format=format)
52
 
        self.build_tree_contents([(path + '/hello', b'foo')])
 
50
        self.build_tree_contents([(path + '/hello', 'foo')])
53
51
        tree.add('hello')
54
52
        tree.commit(message='setup')
55
 
        self.build_tree_contents([(path + '/goodbye', b'baz')])
 
53
        self.build_tree_contents([(path + '/goodbye', 'baz')])
56
54
        tree.add('goodbye')
57
55
        tree.commit(message='setup')
58
56
        return tree
65
63
        self.run_bzr('branch a c -r 1')
66
64
        # previously was erroneously created by branching
67
65
        self.assertFalse(b._transport.has('branch-name'))
68
 
        b.controldir.open_workingtree().commit(message='foo', allow_pointless=True)
 
66
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
69
67
 
70
68
    def test_branch_no_to_location(self):
71
69
        """The to_location is derived from the source branch name."""
81
79
        out, err = self.run_bzr(
82
80
            'init --format=development-colo file:b,branch=orig')
83
81
        self.assertEqual(
84
 
            """Created a standalone tree (format: development-colo)\n""",
 
82
            """Created a lightweight checkout (format: development-colo)\n""",
85
83
            out)
86
84
        self.assertEqual('', err)
87
85
        out, err = self.run_bzr(
91
89
        out, err = self.run_bzr('branches b')
92
90
        self.assertEqual("  orig\n  thiswasa\n", out)
93
91
        self.assertEqual('', err)
94
 
        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)
95
93
        self.assertEqual('', out)
96
94
        self.assertEqual(
97
 
            'brz: ERROR: Already a branch: "file:b,branch=orig".\n', err)
 
95
            'bzr: ERROR: Already a branch: "file:b,branch=orig".\n', err)
98
96
 
99
97
    def test_from_colocated(self):
100
98
        """Branch from a colocated branch into a regular branch."""
101
 
        os.mkdir('b')
102
 
        tree = self.example_branch('b/a', format='development-colo')
103
 
        tree.controldir.create_branch(name='somecolo')
 
99
        tree = self.example_branch('a', format='development-colo')
 
100
        tree.bzrdir.create_branch(name='somecolo')
104
101
        out, err = self.run_bzr('branch %s,branch=somecolo' %
105
 
                                local_path_to_url('b/a'))
 
102
            local_path_to_url('a'))
106
103
        self.assertEqual('', out)
107
104
        self.assertEqual('Branched 0 revisions.\n', err)
108
 
        self.assertPathExists('a')
 
105
        self.assertPathExists("somecolo")
109
106
 
110
107
    def test_branch_broken_pack(self):
111
108
        """branching with a corrupted pack file."""
120
117
            c = f.read(1)
121
118
            f.seek(-5, os.SEEK_END)
122
119
            # Make sure we inject a value different than the one we just read
123
 
            if c == b'\xFF':
124
 
                corrupt = b'\x00'
 
120
            if c == '\xFF':
 
121
                corrupt = '\x00'
125
122
            else:
126
 
                corrupt = b'\xFF'
127
 
            f.write(corrupt)  # make sure we corrupt something
 
123
                corrupt = '\xFF'
 
124
            f.write(corrupt) # make sure we corrupt something
128
125
        self.run_bzr_error(['Corruption while decompressing repository file'],
129
 
                           'branch a b', retcode=3)
 
126
                            'branch a b', retcode=3)
130
127
 
131
128
    def test_branch_switch_no_branch(self):
132
129
        # No branch in the current directory:
134
131
        self.example_branch('a')
135
132
        self.make_repository('current')
136
133
        self.run_bzr_error(['No WorkingTree exists for'],
137
 
                           'branch --switch ../a ../b', working_dir='current')
 
134
            'branch --switch ../a ../b', working_dir='current')
138
135
        a = branch.Branch.open('a')
139
136
        b = branch.Branch.open('b')
140
137
        self.assertEqual(a.last_revision(), b.last_revision())
146
143
        self.example_branch('a')
147
144
        self.make_branch('current')
148
145
        self.run_bzr_error(['No WorkingTree exists for'],
149
 
                           'branch --switch ../a ../b', working_dir='current')
 
146
            'branch --switch ../a ../b', working_dir='current')
150
147
        a = branch.Branch.open('a')
151
148
        b = branch.Branch.open('b')
152
149
        self.assertEqual(a.last_revision(), b.last_revision())
161
158
        tree = self.make_branch_and_tree('current')
162
159
        c1 = tree.commit('some diverged change')
163
160
        self.run_bzr_error(['Cannot switch a branch, only a checkout'],
164
 
                           'branch --switch ../a ../b', working_dir='current')
 
161
            'branch --switch ../a ../b', working_dir='current')
165
162
        a = branch.Branch.open('a')
166
163
        b = branch.Branch.open('b')
167
164
        self.assertEqual(a.last_revision(), b.last_revision())
170
167
 
171
168
    def test_branch_into_empty_dir(self):
172
169
        t = self.example_branch('source')
173
 
        self.make_controldir('target')
 
170
        self.make_bzrdir('target')
174
171
        self.run_bzr("branch source target")
175
172
        self.assertEqual(2, len(t.branch.repository.all_revision_ids()))
176
173
 
211
208
        shared_repo.set_make_working_trees(True)
212
209
 
213
210
        def make_shared_tree(path):
214
 
            shared_repo.controldir.root_transport.mkdir(path)
 
211
            shared_repo.bzrdir.root_transport.mkdir(path)
215
212
            controldir.ControlDir.create_branch_convenience('repo/' + path)
216
213
            return WorkingTree.open('repo/' + path)
217
214
        tree_a = make_shared_tree('a')
218
215
        self.build_tree(['repo/a/file'])
219
216
        tree_a.add('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')
 
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')
224
222
 
225
223
        tree_b = make_shared_tree('b')
226
224
        self.build_tree(['repo/b/file'])
227
225
        tree_b.add('file')
228
 
        tree_b.commit('commit b-1', rev_id=b'b-1')
 
226
        tree_b.commit('commit b-1', rev_id='b-1')
229
227
 
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'))
 
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'))
233
231
 
234
232
        # Now that we have a repository with shared files, make sure
235
233
        # that things aren't copied out by a 'branch'
236
234
        self.run_bzr('branch repo/b branch-b')
237
235
        pushed_tree = WorkingTree.open('branch-b')
238
236
        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'))
 
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'))
242
240
 
243
241
    def test_branch_hardlink(self):
244
242
        self.requireFeature(HardlinkFeature)
265
263
        self.build_tree(['source/file1'])
266
264
        source.add('file1')
267
265
        source.commit('added file')
268
 
        source.controldir.sprout('second')
 
266
        source.bzrdir.sprout('second')
269
267
        out, err = self.run_bzr('branch source target --files-from second'
270
268
                                ' --hardlink')
271
269
        source_stat = os.stat('source/file1')
281
279
        b = branch.Branch.open('repo/target')
282
280
        expected_repo_path = os.path.abspath('repo/target/.bzr/repository')
283
281
        self.assertEqual(strip_trailing_slash(b.repository.base),
284
 
                         strip_trailing_slash(local_path_to_url(expected_repo_path)))
 
282
            strip_trailing_slash(local_path_to_url(expected_repo_path)))
285
283
 
286
284
    def test_branch_no_tree(self):
287
285
        self.example_branch('source')
291
289
 
292
290
    def test_branch_into_existing_dir(self):
293
291
        self.example_branch('a')
294
 
        # existing dir with similar files but no .brz dir
 
292
        # existing dir with similar files but no .bzr dir
295
293
        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
 
294
        self.build_tree_contents([('b/hello', 'bar')])  # different content
 
295
        self.build_tree_contents([('b/goodbye', 'baz')])# same content
298
296
        # fails without --use-existing-dir
299
 
        out, err = self.run_bzr('branch a b', retcode=3)
 
297
        out,err = self.run_bzr('branch a b', retcode=3)
300
298
        self.assertEqual('', out)
301
 
        self.assertEqual('brz: ERROR: Target directory "b" already exists.\n',
302
 
                         err)
 
299
        self.assertEqual('bzr: ERROR: Target directory "b" already exists.\n',
 
300
            err)
303
301
        # force operation
304
302
        self.run_bzr('branch a b --use-existing-dir')
305
303
        # check conflicts
306
304
        self.assertPathExists('b/hello.moved')
307
305
        self.assertPathDoesNotExist('b/godbye.moved')
308
306
        # we can't branch into branch
309
 
        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)
310
308
        self.assertEqual('', out)
311
 
        self.assertEqual('brz: ERROR: Already a branch: "b".\n', err)
 
309
        self.assertEqual('bzr: ERROR: Already a branch: "b".\n', err)
312
310
 
313
311
    def test_branch_bind(self):
314
312
        self.example_branch('a')
320
318
    def test_branch_with_post_branch_init_hook(self):
321
319
        calls = []
322
320
        branch.Branch.hooks.install_named_hook('post_branch_init',
323
 
                                               calls.append, None)
 
321
            calls.append, None)
324
322
        self.assertLength(0, calls)
325
323
        self.example_branch('a')
326
324
        self.assertLength(1, calls)
330
328
    def test_checkout_with_post_branch_init_hook(self):
331
329
        calls = []
332
330
        branch.Branch.hooks.install_named_hook('post_branch_init',
333
 
                                               calls.append, None)
 
331
            calls.append, None)
334
332
        self.assertLength(0, calls)
335
333
        self.example_branch('a')
336
334
        self.assertLength(1, calls)
340
338
    def test_lightweight_checkout_with_post_branch_init_hook(self):
341
339
        calls = []
342
340
        branch.Branch.hooks.install_named_hook('post_branch_init',
343
 
                                               calls.append, None)
 
341
            calls.append, None)
344
342
        self.assertLength(0, calls)
345
343
        self.example_branch('a')
346
344
        self.assertLength(1, calls)
349
347
 
350
348
    def test_branch_fetches_all_tags(self):
351
349
        builder = self.make_branch_builder('source')
352
 
        source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(
353
 
            builder)
354
 
        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')
355
352
        source.get_config_stack().set('branch.fetch_tags', True)
356
353
        # Now source has a tag not in its ancestry.  Make a branch from it.
357
354
        self.run_bzr('branch source new-branch')
358
355
        new_branch = branch.Branch.open('new-branch')
359
356
        # 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)
362
 
 
363
 
    def test_branch_with_nested_trees(self):
364
 
        orig = self.make_branch_and_tree('source', format='development-subtree')
365
 
        subtree = self.make_branch_and_tree('source/subtree')
366
 
        self.build_tree(['source/subtree/a'])
367
 
        subtree.add(['a'])
368
 
        subtree.commit('add subtree contents')
369
 
        orig.add_reference(subtree)
370
 
        orig.set_reference_info('subtree', subtree.branch.user_url)
371
 
        orig.commit('add subtree')
372
 
 
373
 
        self.run_bzr('branch source target')
374
 
 
375
 
        target = WorkingTree.open('target')
376
 
        target_subtree = WorkingTree.open('target/subtree')
377
 
        self.assertTreesEqual(orig, target)
378
 
        self.assertTreesEqual(subtree, target_subtree)
379
 
 
380
 
    def test_branch_with_nested_trees_reference_unset(self):
381
 
        orig = self.make_branch_and_tree('source', format='development-subtree')
382
 
        subtree = self.make_branch_and_tree('source/subtree')
383
 
        self.build_tree(['source/subtree/a'])
384
 
        subtree.add(['a'])
385
 
        subtree.commit('add subtree contents')
386
 
        orig.add_reference(subtree)
387
 
        orig.commit('add subtree')
388
 
 
389
 
        self.run_bzr('branch source target')
390
 
 
391
 
        target = WorkingTree.open('target')
392
 
        self.assertRaises(errors.NotBranchError, WorkingTree.open, 'target/subtree')
393
 
 
394
 
    def test_branch_with_nested_trees_no_recurse(self):
395
 
        orig = self.make_branch_and_tree('source', format='development-subtree')
396
 
        subtree = self.make_branch_and_tree('source/subtree')
397
 
        self.build_tree(['source/subtree/a'])
398
 
        subtree.add(['a'])
399
 
        subtree.commit('add subtree contents')
400
 
        orig.add_reference(subtree)
401
 
        orig.commit('add subtree')
402
 
 
403
 
        self.run_bzr('branch --no-recurse-nested source target')
404
 
 
405
 
        target = WorkingTree.open('target')
406
 
        self.addCleanup(subtree.lock_read().unlock)
407
 
        basis = subtree.basis_tree()
408
 
        self.addCleanup(basis.lock_read().unlock)
409
 
        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')
410
359
 
411
360
 
412
361
class TestBranchStacked(tests.TestCaseWithTransport):
425
374
    def assertRevisionsInBranchRepository(self, revid_list, branch_path):
426
375
        repo = branch.Branch.open(branch_path).repository
427
376
        self.assertEqual(set(revid_list),
428
 
                         repo.has_revisions(revid_list))
 
377
            repo.has_revisions(revid_list))
429
378
 
430
379
    def test_branch_stacked_branch_not_stacked(self):
431
380
        """Branching a stacked branch is not stacked by default"""
432
381
        # We have a mainline
433
382
        trunk_tree = self.make_branch_and_tree('target',
434
 
                                               format='1.9')
 
383
            format='1.9')
435
384
        trunk_tree.commit('mainline')
436
385
        # and a branch from it which is stacked
437
386
        branch_tree = self.make_branch_and_tree('branch',
438
 
                                                format='1.9')
 
387
            format='1.9')
439
388
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
440
389
        # with some work on it
441
 
        work_tree = trunk_tree.branch.controldir.sprout(
442
 
            'local').open_workingtree()
 
390
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
443
391
        work_tree.commit('moar work plz')
444
392
        work_tree.branch.push(branch_tree.branch)
445
393
        # branching our local branch gives us a new stacked branch pointing at
447
395
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
448
396
        self.assertEqual('', out)
449
397
        self.assertEqual('Branched 2 revisions.\n',
450
 
                         err)
 
398
            err)
451
399
        # it should have preserved the branch format, and so it should be
452
400
        # capable of supporting stacking, but not actually have a stacked_on
453
401
        # branch configured
454
402
        self.assertRaises(errors.NotStacked,
455
 
                          controldir.ControlDir.open('newbranch').open_branch().get_stacked_on_url)
 
403
            controldir.ControlDir.open('newbranch').open_branch().get_stacked_on_url)
456
404
 
457
405
    def test_branch_stacked_branch_stacked(self):
458
406
        """Asking to stack on a stacked branch does work"""
459
407
        # We have a mainline
460
408
        trunk_tree = self.make_branch_and_tree('target',
461
 
                                               format='1.9')
 
409
            format='1.9')
462
410
        trunk_revid = trunk_tree.commit('mainline')
463
411
        # and a branch from it which is stacked
464
412
        branch_tree = self.make_branch_and_tree('branch',
465
 
                                                format='1.9')
 
413
            format='1.9')
466
414
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
467
415
        # with some work on it
468
 
        work_tree = trunk_tree.branch.controldir.sprout(
469
 
            'local').open_workingtree()
 
416
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
470
417
        branch_revid = work_tree.commit('moar work plz')
471
418
        work_tree.branch.push(branch_tree.branch)
472
419
        # you can chain branches on from there
473
420
        out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
474
421
        self.assertEqual('', out)
475
422
        self.assertEqual('Created new stacked branch referring to %s.\n' %
476
 
                         branch_tree.branch.base, err)
 
423
            branch_tree.branch.base, err)
477
424
        self.assertEqual(branch_tree.branch.base,
478
 
                         branch.Branch.open('branch2').get_stacked_on_url())
 
425
            branch.Branch.open('branch2').get_stacked_on_url())
479
426
        branch2_tree = WorkingTree.open('branch2')
480
427
        branch2_revid = work_tree.commit('work on second stacked branch')
481
428
        work_tree.branch.push(branch2_tree.branch)
487
434
    def test_branch_stacked(self):
488
435
        # We have a mainline
489
436
        trunk_tree = self.make_branch_and_tree('mainline',
490
 
                                               format='1.9')
 
437
            format='1.9')
491
438
        original_revid = trunk_tree.commit('mainline')
492
439
        self.assertRevisionInRepository('mainline', original_revid)
493
440
        # and a branch from it which is stacked
494
441
        out, err = self.run_bzr(['branch', '--stacked', 'mainline',
495
 
                                 'newbranch'])
 
442
            'newbranch'])
496
443
        self.assertEqual('', out)
497
444
        self.assertEqual('Created new stacked branch referring to %s.\n' %
498
 
                         trunk_tree.branch.base, err)
 
445
            trunk_tree.branch.base, err)
499
446
        self.assertRevisionNotInRepository('newbranch', original_revid)
500
447
        new_branch = branch.Branch.open('newbranch')
501
448
        self.assertEqual(trunk_tree.branch.base,
521
468
            '  Branch format 7\n'
522
469
            'Doing on-the-fly conversion from RepositoryFormatKnitPack1() to RepositoryFormatKnitPack5().\n'
523
470
            'This may take some time. Upgrade the repositories to the same format for better performance.\n'
524
 
            'Created new stacked branch referring to %s.\n' %
525
 
            (trunk.base,),
 
471
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
526
472
            err)
527
473
 
528
474
    def test_branch_stacked_from_rich_root_non_stackable(self):
550
496
            t.commit(message='commit %d' % count)
551
497
        self.reset_smart_call_log()
552
498
        out, err = self.run_bzr(['branch', self.get_url('from'),
553
 
                                 self.get_url('target')])
 
499
            self.get_url('target')])
554
500
        # This figure represent the amount of work to perform this use case. It
555
501
        # is entirely ok to reduce this number if a test fails due to rpc_count
556
502
        # being too low. If rpc_count increases, more network roundtrips have
557
503
        # become necessary for this use case. Please do not adjust this number
558
504
        # upwards without agreement from bzr's network support maintainers.
559
505
        self.assertLength(2, self.hpss_connections)
560
 
        self.assertLength(34, self.hpss_calls)
561
 
        self.expectFailure(
562
 
            "branching to the same branch requires VFS access",
 
506
        self.assertLength(33, self.hpss_calls)
 
507
        self.expectFailure("branching to the same branch requires VFS access",
563
508
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
564
509
 
565
510
    def test_branch_from_trivial_branch_streaming_acceptance(self):
569
514
            t.commit(message='commit %d' % count)
570
515
        self.reset_smart_call_log()
571
516
        out, err = self.run_bzr(['branch', self.get_url('from'),
572
 
                                 'local-target'])
 
517
            'local-target'])
573
518
        # This figure represent the amount of work to perform this use case. It
574
519
        # is entirely ok to reduce this number if a test fails due to rpc_count
575
520
        # being too low. If rpc_count increases, more network roundtrips have
576
521
        # become necessary for this use case. Please do not adjust this number
577
522
        # upwards without agreement from bzr's network support maintainers.
578
523
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
579
 
        self.assertLength(11, self.hpss_calls)
 
524
        self.assertLength(10, self.hpss_calls)
580
525
        self.assertLength(1, self.hpss_connections)
581
526
 
582
527
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
584
529
        t = self.make_branch_and_tree('trunk')
585
530
        for count in range(8):
586
531
            t.commit(message='commit %d' % count)
587
 
        tree2 = t.branch.controldir.sprout('feature', stacked=True
588
 
                                           ).open_workingtree()
589
 
        local_tree = t.branch.controldir.sprout(
590
 
            'local-working').open_workingtree()
 
532
        tree2 = t.branch.bzrdir.sprout('feature', stacked=True
 
533
            ).open_workingtree()
 
534
        local_tree = t.branch.bzrdir.sprout('local-working').open_workingtree()
591
535
        local_tree.commit('feature change')
592
536
        local_tree.branch.push(tree2.branch)
593
537
        self.reset_smart_call_log()
594
538
        out, err = self.run_bzr(['branch', self.get_url('feature'),
595
 
                                 'local-target'])
 
539
            'local-target'])
596
540
        # This figure represent the amount of work to perform this use case. It
597
541
        # is entirely ok to reduce this number if a test fails due to rpc_count
598
542
        # being too low. If rpc_count increases, more network roundtrips have
599
543
        # become necessary for this use case. Please do not adjust this number
600
544
        # upwards without agreement from bzr's network support maintainers.
601
 
        self.assertLength(16, self.hpss_calls)
 
545
        self.assertLength(15, self.hpss_calls)
602
546
        self.assertLength(1, self.hpss_connections)
603
547
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
604
548
 
605
549
    def test_branch_from_branch_with_tags(self):
606
550
        self.setup_smart_server_with_call_log()
607
551
        builder = self.make_branch_builder('source')
608
 
        source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(
609
 
            builder)
 
552
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
610
553
        source.get_config_stack().set('branch.fetch_tags', True)
611
 
        source.tags.set_tag('tag-a', rev2)
612
 
        source.tags.set_tag('tag-missing', b'missing-rev')
 
554
        source.tags.set_tag('tag-a', 'rev-2')
 
555
        source.tags.set_tag('tag-missing', 'missing-rev')
613
556
        # Now source has a tag not in its ancestry.  Make a branch from it.
614
557
        self.reset_smart_call_log()
615
558
        out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
618
561
        # being too low. If rpc_count increases, more network roundtrips have
619
562
        # become necessary for this use case. Please do not adjust this number
620
563
        # upwards without agreement from bzr's network support maintainers.
621
 
        self.assertLength(11, self.hpss_calls)
 
564
        self.assertLength(10, self.hpss_calls)
622
565
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
623
566
        self.assertLength(1, self.hpss_connections)
624
567
 
629
572
            t.commit(message='commit %d' % count)
630
573
        self.reset_smart_call_log()
631
574
        out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
632
 
                                 'local-target'])
 
575
            'local-target'])
633
576
        # XXX: the number of hpss calls for this case isn't deterministic yet,
634
577
        # so we can't easily assert about the number of calls.
635
578
        #self.assertLength(XXX, self.hpss_calls)
642
585
        self.assertLength(1, self.hpss_connections)
643
586
        self.assertLength(0, readvs_of_rix_files)
644
587
        self.expectFailure("branching to stacked requires VFS access",
645
 
                           self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
646
 
 
647
 
    def test_branch_from_branch_with_ghosts(self):
648
 
        self.setup_smart_server_with_call_log()
649
 
        t = self.make_branch_and_tree('from')
650
 
        for count in range(9):
651
 
            t.commit(message='commit %d' % count)
652
 
        t.set_parent_ids([t.last_revision(), b'ghost'])
653
 
        t.commit(message='add commit with parent')
654
 
        self.reset_smart_call_log()
655
 
        out, err = self.run_bzr(['branch', self.get_url('from'),
656
 
                                 'local-target'])
657
 
        # This figure represent the amount of work to perform this use case. It
658
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
659
 
        # being too low. If rpc_count increases, more network roundtrips have
660
 
        # become necessary for this use case. Please do not adjust this number
661
 
        # upwards without agreement from bzr's network support maintainers.
662
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
663
 
        self.assertLength(12, self.hpss_calls)
664
 
        self.assertLength(1, self.hpss_connections)
 
588
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
665
589
 
666
590
 
667
591
class TestRemoteBranch(TestCaseWithSFTPServer):
669
593
    def setUp(self):
670
594
        super(TestRemoteBranch, self).setUp()
671
595
        tree = self.make_branch_and_tree('branch')
672
 
        self.build_tree_contents([('branch/file', b'file content\n')])
 
596
        self.build_tree_contents([('branch/file', 'file content\n')])
673
597
        tree.add('file')
674
598
        tree.commit('file created')
675
599
 
688
612
        self.assertFalse(t.has('remote/file'))
689
613
 
690
614
 
 
615
class TestDeprecatedAliases(tests.TestCaseWithTransport):
 
616
 
 
617
    def test_deprecated_aliases(self):
 
618
        """bzr 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
            $ bzr %(command)s A B
 
626
            2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
 
627
            2>bzr: ERROR: Not a branch...
 
628
            """ % locals())
 
629
 
 
630
 
691
631
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
692
632
 
693
633
    def _checkout_and_branch(self, option=''):
694
634
        self.script_runner.run_script(self, '''
695
 
                $ brz checkout %(option)s repo/trunk checkout
 
635
                $ bzr checkout %(option)s repo/trunk checkout
696
636
                $ cd checkout
697
 
                $ brz branch --switch ../repo/trunk ../repo/branched
 
637
                $ bzr branch --switch ../repo/trunk ../repo/branched
698
638
                2>Branched 0 revisions.
699
639
                2>Tree is up to date at revision 0.
700
640
                2>Switched to branch:...branched...
705
645
        return (bound_branch, master_branch)
706
646
 
707
647
    def test_branch_switch_parent_lightweight(self):
708
 
        """Lightweight checkout using brz branch --switch."""
 
648
        """Lightweight checkout using bzr branch --switch."""
709
649
        bb, mb = self._checkout_and_branch(option='--lightweight')
710
650
        self.assertParent('repo/trunk', bb)
711
651
        self.assertParent('repo/trunk', mb)
712
652
 
713
653
    def test_branch_switch_parent_heavyweight(self):
714
 
        """Heavyweight checkout using brz branch --switch."""
 
654
        """Heavyweight checkout using bzr branch --switch."""
715
655
        bb, mb = self._checkout_and_branch()
716
656
        self.assertParent('repo/trunk', bb)
717
657
        self.assertParent('repo/trunk', mb)