/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 07:18:33 UTC
  • mfrom: (7141.3.3 fix1799482)
  • Revision ID: breezy.the.bot@gmail.com-20181116071833-e01b0833f3hkc3et
Report correct paths when running "brz add" in git repositories.

Merged from https://code.launchpad.net/~jelmer/brz/fix1799482/+merge/357734

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
"""Black-box tests for bzr branch."""
 
18
"""Black-box tests for brz branch."""
19
19
 
20
20
import os
21
21
 
22
 
from bzrlib import (
 
22
from breezy import (
23
23
    branch,
24
 
    bzrdir,
 
24
    controldir,
25
25
    errors,
26
 
    repository,
27
26
    revision as _mod_revision,
28
 
    )
29
 
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
30
 
from bzrlib.tests.blackbox import ExternalBase
31
 
from bzrlib.tests import (
32
 
    KnownFailure,
 
27
    tests,
 
28
    )
 
29
from breezy.bzr import (
 
30
    bzrdir,
 
31
    )
 
32
from breezy.bzr.knitrepo import RepositoryFormatKnit1
 
33
from breezy.tests import (
 
34
    fixtures,
 
35
    test_server,
 
36
    )
 
37
from breezy.tests.features import (
33
38
    HardlinkFeature,
34
 
    test_server,
35
39
    )
36
 
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
37
 
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
38
 
from bzrlib.workingtree import WorkingTree
39
 
 
40
 
 
41
 
class TestBranch(ExternalBase):
42
 
 
43
 
    def example_branch(self, path='.'):
44
 
        tree = self.make_branch_and_tree(path)
45
 
        self.build_tree_contents([(path + '/hello', 'foo')])
 
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
 
46
 
 
47
 
 
48
class TestBranch(tests.TestCaseWithTransport):
 
49
 
 
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')])
46
53
        tree.add('hello')
47
54
        tree.commit(message='setup')
48
 
        self.build_tree_contents([(path + '/goodbye', 'baz')])
 
55
        self.build_tree_contents([(path + '/goodbye', b'baz')])
49
56
        tree.add('goodbye')
50
57
        tree.commit(message='setup')
 
58
        return tree
51
59
 
52
60
    def test_branch(self):
53
61
        """Branch from one branch to another."""
57
65
        self.run_bzr('branch a c -r 1')
58
66
        # previously was erroneously created by branching
59
67
        self.assertFalse(b._transport.has('branch-name'))
60
 
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
 
68
        b.controldir.open_workingtree().commit(message='foo', allow_pointless=True)
 
69
 
 
70
    def test_branch_no_to_location(self):
 
71
        """The to_location is derived from the source branch name."""
 
72
        os.mkdir("something")
 
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())
 
77
 
 
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')
 
83
        self.assertEqual(
 
84
            """Created a standalone tree (format: development-colo)\n""",
 
85
            out)
 
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)
 
96
        self.assertEqual(
 
97
            'brz: ERROR: Already a branch: "file:b,branch=orig".\n', err)
 
98
 
 
99
    def test_from_colocated(self):
 
100
        """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')
 
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')
 
109
 
 
110
    def test_branch_broken_pack(self):
 
111
        """branching with a corrupted pack file."""
 
112
        self.example_branch('a')
 
113
        # add some corruption
 
114
        packs_dir = 'a/.bzr/repository/packs/'
 
115
        fname = packs_dir + os.listdir(packs_dir)[0]
 
116
        with open(fname, 'rb+') as f:
 
117
            # Start from the end of the file to avoid choosing a place bigger
 
118
            # than the file itself.
 
119
            f.seek(-5, os.SEEK_END)
 
120
            c = f.read(1)
 
121
            f.seek(-5, os.SEEK_END)
 
122
            # Make sure we inject a value different than the one we just read
 
123
            if c == b'\xFF':
 
124
                corrupt = b'\x00'
 
125
            else:
 
126
                corrupt = b'\xFF'
 
127
            f.write(corrupt) # make sure we corrupt something
 
128
        self.run_bzr_error(['Corruption while decompressing repository file'],
 
129
                            'branch a b', retcode=3)
61
130
 
62
131
    def test_branch_switch_no_branch(self):
63
132
        # No branch in the current directory:
89
158
        #  => new branch will be created, but switch fails and the current
90
159
        #     branch is unmodified
91
160
        self.example_branch('a')
92
 
        self.make_branch_and_tree('current')
 
161
        tree = self.make_branch_and_tree('current')
 
162
        c1 = tree.commit('some diverged change')
93
163
        self.run_bzr_error(['Cannot switch a branch, only a checkout'],
94
164
            'branch --switch ../a ../b', working_dir='current')
95
165
        a = branch.Branch.open('a')
96
166
        b = branch.Branch.open('b')
97
167
        self.assertEqual(a.last_revision(), b.last_revision())
98
168
        work = branch.Branch.open('current')
99
 
        self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
 
169
        self.assertEqual(work.last_revision(), c1)
 
170
 
 
171
    def test_branch_into_empty_dir(self):
 
172
        t = self.example_branch('source')
 
173
        self.make_controldir('target')
 
174
        self.run_bzr("branch source target")
 
175
        self.assertEqual(2, len(t.branch.repository.all_revision_ids()))
100
176
 
101
177
    def test_branch_switch_checkout(self):
102
178
        # Checkout in the current directory:
103
179
        #  => new branch will be created and checkout bound to the new branch
104
180
        self.example_branch('a')
105
181
        self.run_bzr('checkout a current')
106
 
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
 
182
        out, err = self.run_bzr('branch --switch ../a ../b',
 
183
                                working_dir='current')
107
184
        a = branch.Branch.open('a')
108
185
        b = branch.Branch.open('b')
109
186
        self.assertEqual(a.last_revision(), b.last_revision())
117
194
        #     the new branch
118
195
        self.example_branch('a')
119
196
        self.run_bzr('checkout --lightweight a current')
120
 
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
 
197
        out, err = self.run_bzr('branch --switch ../a ../b',
 
198
                                working_dir='current')
121
199
        a = branch.Branch.open('a')
122
200
        b = branch.Branch.open('b')
123
201
        self.assertEqual(a.last_revision(), b.last_revision())
133
211
        shared_repo.set_make_working_trees(True)
134
212
 
135
213
        def make_shared_tree(path):
136
 
            shared_repo.bzrdir.root_transport.mkdir(path)
137
 
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
 
214
            shared_repo.controldir.root_transport.mkdir(path)
 
215
            controldir.ControlDir.create_branch_convenience('repo/' + path)
138
216
            return WorkingTree.open('repo/' + path)
139
217
        tree_a = make_shared_tree('a')
140
218
        self.build_tree(['repo/a/file'])
141
219
        tree_a.add('file')
142
 
        tree_a.commit('commit a-1', rev_id='a-1')
143
 
        f = open('repo/a/file', 'ab')
144
 
        f.write('more stuff\n')
145
 
        f.close()
146
 
        tree_a.commit('commit a-2', rev_id='a-2')
 
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')
147
224
 
148
225
        tree_b = make_shared_tree('b')
149
226
        self.build_tree(['repo/b/file'])
150
227
        tree_b.add('file')
151
 
        tree_b.commit('commit b-1', rev_id='b-1')
 
228
        tree_b.commit('commit b-1', rev_id=b'b-1')
152
229
 
153
 
        self.assertTrue(shared_repo.has_revision('a-1'))
154
 
        self.assertTrue(shared_repo.has_revision('a-2'))
155
 
        self.assertTrue(shared_repo.has_revision('b-1'))
 
230
        self.assertTrue(shared_repo.has_revision(b'a-1'))
 
231
        self.assertTrue(shared_repo.has_revision(b'a-2'))
 
232
        self.assertTrue(shared_repo.has_revision(b'b-1'))
156
233
 
157
234
        # Now that we have a repository with shared files, make sure
158
235
        # that things aren't copied out by a 'branch'
159
236
        self.run_bzr('branch repo/b branch-b')
160
237
        pushed_tree = WorkingTree.open('branch-b')
161
238
        pushed_repo = pushed_tree.branch.repository
162
 
        self.assertFalse(pushed_repo.has_revision('a-1'))
163
 
        self.assertFalse(pushed_repo.has_revision('a-2'))
164
 
        self.assertTrue(pushed_repo.has_revision('b-1'))
 
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'))
165
242
 
166
243
    def test_branch_hardlink(self):
167
244
        self.requireFeature(HardlinkFeature)
174
251
        target_stat = os.stat('target/file1')
175
252
        self.assertEqual(source_stat, target_stat)
176
253
 
 
254
    def test_branch_files_from(self):
 
255
        source = self.make_branch_and_tree('source')
 
256
        self.build_tree(['source/file1'])
 
257
        source.add('file1')
 
258
        source.commit('added file')
 
259
        out, err = self.run_bzr('branch source target --files-from source')
 
260
        self.assertPathExists('target/file1')
 
261
 
 
262
    def test_branch_files_from_hardlink(self):
 
263
        self.requireFeature(HardlinkFeature)
 
264
        source = self.make_branch_and_tree('source')
 
265
        self.build_tree(['source/file1'])
 
266
        source.add('file1')
 
267
        source.commit('added file')
 
268
        source.controldir.sprout('second')
 
269
        out, err = self.run_bzr('branch source target --files-from second'
 
270
                                ' --hardlink')
 
271
        source_stat = os.stat('source/file1')
 
272
        second_stat = os.stat('second/file1')
 
273
        target_stat = os.stat('target/file1')
 
274
        self.assertNotEqual(source_stat, target_stat)
 
275
        self.assertEqual(second_stat, target_stat)
 
276
 
177
277
    def test_branch_standalone(self):
178
278
        shared_repo = self.make_repository('repo', shared=True)
179
279
        self.example_branch('source')
186
286
    def test_branch_no_tree(self):
187
287
        self.example_branch('source')
188
288
        self.run_bzr('branch --no-tree source target')
189
 
        self.failIfExists('target/hello')
190
 
        self.failIfExists('target/goodbye')
 
289
        self.assertPathDoesNotExist('target/hello')
 
290
        self.assertPathDoesNotExist('target/goodbye')
191
291
 
192
292
    def test_branch_into_existing_dir(self):
193
293
        self.example_branch('a')
194
 
        # existing dir with similar files but no .bzr dir
 
294
        # existing dir with similar files but no .brz dir
195
295
        self.build_tree_contents([('b/',)])
196
 
        self.build_tree_contents([('b/hello', 'bar')])  # different content
197
 
        self.build_tree_contents([('b/goodbye', 'baz')])# same content
 
296
        self.build_tree_contents([('b/hello', b'bar')])  # different content
 
297
        self.build_tree_contents([('b/goodbye', b'baz')])# same content
198
298
        # fails without --use-existing-dir
199
 
        out,err = self.run_bzr('branch a b', retcode=3)
 
299
        out, err = self.run_bzr('branch a b', retcode=3)
200
300
        self.assertEqual('', out)
201
 
        self.assertEqual('bzr: ERROR: Target directory "b" already exists.\n',
 
301
        self.assertEqual('brz: ERROR: Target directory "b" already exists.\n',
202
302
            err)
203
303
        # force operation
204
304
        self.run_bzr('branch a b --use-existing-dir')
205
305
        # check conflicts
206
 
        self.failUnlessExists('b/hello.moved')
207
 
        self.failIfExists('b/godbye.moved')
 
306
        self.assertPathExists('b/hello.moved')
 
307
        self.assertPathDoesNotExist('b/godbye.moved')
208
308
        # we can't branch into branch
209
 
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
 
309
        out, err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
210
310
        self.assertEqual('', out)
211
 
        self.assertEqual('bzr: ERROR: Already a branch: "b".\n', err)
 
311
        self.assertEqual('brz: ERROR: Already a branch: "b".\n', err)
212
312
 
213
313
    def test_branch_bind(self):
214
314
        self.example_branch('a')
247
347
        self.run_bzr('checkout --lightweight a b')
248
348
        self.assertLength(2, calls)
249
349
 
250
 
 
251
 
class TestBranchStacked(ExternalBase):
 
350
    def test_branch_fetches_all_tags(self):
 
351
        builder = self.make_branch_builder('source')
 
352
        source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(builder)
 
353
        source.tags.set_tag('tag-a', rev2)
 
354
        source.get_config_stack().set('branch.fetch_tags', True)
 
355
        # Now source has a tag not in its ancestry.  Make a branch from it.
 
356
        self.run_bzr('branch source new-branch')
 
357
        new_branch = branch.Branch.open('new-branch')
 
358
        # The tag is present, and so is its revision.
 
359
        self.assertEqual(rev2, new_branch.tags.lookup_tag('tag-a'))
 
360
        new_branch.repository.get_revision(rev2)
 
361
 
 
362
 
 
363
class TestBranchStacked(tests.TestCaseWithTransport):
252
364
    """Tests for branch --stacked"""
253
365
 
254
366
    def assertRevisionInRepository(self, repo_path, revid):
255
 
        """Check that a revision is in a repository, disregarding stacking."""
256
 
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
 
367
        """Check that a revision is in a repo, disregarding stacking."""
 
368
        repo = controldir.ControlDir.open(repo_path).open_repository()
257
369
        self.assertTrue(repo.has_revision(revid))
258
370
 
259
371
    def assertRevisionNotInRepository(self, repo_path, revid):
260
 
        """Check that a revision is not in a repository, disregarding stacking."""
261
 
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
 
372
        """Check that a revision is not in a repo, disregarding stacking."""
 
373
        repo = controldir.ControlDir.open(repo_path).open_repository()
262
374
        self.assertFalse(repo.has_revision(revid))
263
375
 
264
376
    def assertRevisionsInBranchRepository(self, revid_list, branch_path):
277
389
            format='1.9')
278
390
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
279
391
        # with some work on it
280
 
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
 
392
        work_tree = trunk_tree.branch.controldir.sprout('local').open_workingtree()
281
393
        work_tree.commit('moar work plz')
282
394
        work_tree.branch.push(branch_tree.branch)
283
395
        # branching our local branch gives us a new stacked branch pointing at
284
396
        # mainline.
285
397
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
286
398
        self.assertEqual('', out)
287
 
        self.assertEqual('Branched 2 revision(s).\n',
 
399
        self.assertEqual('Branched 2 revisions.\n',
288
400
            err)
289
401
        # it should have preserved the branch format, and so it should be
290
402
        # capable of supporting stacking, but not actually have a stacked_on
291
403
        # branch configured
292
404
        self.assertRaises(errors.NotStacked,
293
 
            bzrdir.BzrDir.open('newbranch').open_branch().get_stacked_on_url)
 
405
            controldir.ControlDir.open('newbranch').open_branch().get_stacked_on_url)
294
406
 
295
407
    def test_branch_stacked_branch_stacked(self):
296
408
        """Asking to stack on a stacked branch does work"""
303
415
            format='1.9')
304
416
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
305
417
        # with some work on it
306
 
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
 
418
        work_tree = trunk_tree.branch.controldir.sprout('local').open_workingtree()
307
419
        branch_revid = work_tree.commit('moar work plz')
308
420
        work_tree.branch.push(branch_tree.branch)
309
421
        # you can chain branches on from there
335
447
            trunk_tree.branch.base, err)
336
448
        self.assertRevisionNotInRepository('newbranch', original_revid)
337
449
        new_branch = branch.Branch.open('newbranch')
338
 
        self.assertEqual(trunk_tree.branch.base, new_branch.get_stacked_on_url())
 
450
        self.assertEqual(trunk_tree.branch.base,
 
451
                         new_branch.get_stacked_on_url())
339
452
 
340
453
    def test_branch_stacked_from_smart_server(self):
341
454
        # We can branch stacking on a smart server
357
470
            '  Branch format 7\n'
358
471
            'Doing on-the-fly conversion from RepositoryFormatKnitPack1() to RepositoryFormatKnitPack5().\n'
359
472
            'This may take some time. Upgrade the repositories to the same format for better performance.\n'
360
 
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
 
473
            'Created new stacked branch referring to %s.\n' %
 
474
            (trunk.base,),
361
475
            err)
362
476
 
363
477
    def test_branch_stacked_from_rich_root_non_stackable(self):
376
490
            err)
377
491
 
378
492
 
379
 
class TestSmartServerBranching(ExternalBase):
 
493
class TestSmartServerBranching(tests.TestCaseWithTransport):
380
494
 
381
495
    def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
382
496
        self.setup_smart_server_with_call_log()
391
505
        # being too low. If rpc_count increases, more network roundtrips have
392
506
        # become necessary for this use case. Please do not adjust this number
393
507
        # upwards without agreement from bzr's network support maintainers.
394
 
        self.assertLength(38, self.hpss_calls)
 
508
        self.assertLength(2, self.hpss_connections)
 
509
        self.assertLength(33, self.hpss_calls)
 
510
        self.expectFailure("branching to the same branch requires VFS access",
 
511
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
395
512
 
396
513
    def test_branch_from_trivial_branch_streaming_acceptance(self):
397
514
        self.setup_smart_server_with_call_log()
406
523
        # being too low. If rpc_count increases, more network roundtrips have
407
524
        # become necessary for this use case. Please do not adjust this number
408
525
        # upwards without agreement from bzr's network support maintainers.
 
526
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
409
527
        self.assertLength(10, self.hpss_calls)
 
528
        self.assertLength(1, self.hpss_connections)
410
529
 
411
530
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
412
531
        self.setup_smart_server_with_call_log()
413
532
        t = self.make_branch_and_tree('trunk')
414
533
        for count in range(8):
415
534
            t.commit(message='commit %d' % count)
416
 
        tree2 = t.branch.bzrdir.sprout('feature', stacked=True
 
535
        tree2 = t.branch.controldir.sprout('feature', stacked=True
417
536
            ).open_workingtree()
418
 
        local_tree = t.branch.bzrdir.sprout('local-working').open_workingtree()
 
537
        local_tree = t.branch.controldir.sprout('local-working').open_workingtree()
419
538
        local_tree.commit('feature change')
420
539
        local_tree.branch.push(tree2.branch)
421
540
        self.reset_smart_call_log()
427
546
        # become necessary for this use case. Please do not adjust this number
428
547
        # upwards without agreement from bzr's network support maintainers.
429
548
        self.assertLength(15, self.hpss_calls)
 
549
        self.assertLength(1, self.hpss_connections)
 
550
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
551
 
 
552
    def test_branch_from_branch_with_tags(self):
 
553
        self.setup_smart_server_with_call_log()
 
554
        builder = self.make_branch_builder('source')
 
555
        source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(builder)
 
556
        source.get_config_stack().set('branch.fetch_tags', True)
 
557
        source.tags.set_tag('tag-a', rev2)
 
558
        source.tags.set_tag('tag-missing', b'missing-rev')
 
559
        # Now source has a tag not in its ancestry.  Make a branch from it.
 
560
        self.reset_smart_call_log()
 
561
        out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
 
562
        # This figure represent the amount of work to perform this use case. It
 
563
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
564
        # being too low. If rpc_count increases, more network roundtrips have
 
565
        # become necessary for this use case. Please do not adjust this number
 
566
        # upwards without agreement from bzr's network support maintainers.
 
567
        self.assertLength(10, self.hpss_calls)
 
568
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
569
        self.assertLength(1, self.hpss_connections)
 
570
 
 
571
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
 
572
        self.setup_smart_server_with_call_log()
 
573
        t = self.make_branch_and_tree('from')
 
574
        for count in range(9):
 
575
            t.commit(message='commit %d' % count)
 
576
        self.reset_smart_call_log()
 
577
        out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
 
578
            'local-target'])
 
579
        # XXX: the number of hpss calls for this case isn't deterministic yet,
 
580
        # so we can't easily assert about the number of calls.
 
581
        #self.assertLength(XXX, self.hpss_calls)
 
582
        # We can assert that none of the calls were readv requests for rix
 
583
        # files, though (demonstrating that at least get_parent_map calls are
 
584
        # not using VFS RPCs).
 
585
        readvs_of_rix_files = [
 
586
            c for c in self.hpss_calls
 
587
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
 
588
        self.assertLength(1, self.hpss_connections)
 
589
        self.assertLength(0, readvs_of_rix_files)
 
590
        self.expectFailure("branching to stacked requires VFS access",
 
591
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
 
592
 
 
593
    def test_branch_from_branch_with_ghosts(self):
 
594
        self.setup_smart_server_with_call_log()
 
595
        t = self.make_branch_and_tree('from')
 
596
        for count in range(9):
 
597
            t.commit(message='commit %d' % count)
 
598
        t.set_parent_ids([t.last_revision(), b'ghost'])
 
599
        t.commit(message='add commit with parent')
 
600
        self.reset_smart_call_log()
 
601
        out, err = self.run_bzr(['branch', self.get_url('from'),
 
602
            'local-target'])
 
603
        # This figure represent the amount of work to perform this use case. It
 
604
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
605
        # being too low. If rpc_count increases, more network roundtrips have
 
606
        # become necessary for this use case. Please do not adjust this number
 
607
        # upwards without agreement from bzr's network support maintainers.
 
608
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
609
        self.assertLength(11, self.hpss_calls)
 
610
        self.assertLength(1, self.hpss_connections)
430
611
 
431
612
 
432
613
class TestRemoteBranch(TestCaseWithSFTPServer):
434
615
    def setUp(self):
435
616
        super(TestRemoteBranch, self).setUp()
436
617
        tree = self.make_branch_and_tree('branch')
437
 
        self.build_tree_contents([('branch/file', 'file content\n')])
 
618
        self.build_tree_contents([('branch/file', b'file content\n')])
438
619
        tree.add('file')
439
620
        tree.commit('file created')
440
621
 
452
633
        # Ensure that no working tree what created remotely
453
634
        self.assertFalse(t.has('remote/file'))
454
635
 
 
636
 
 
637
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
 
638
 
 
639
    def _checkout_and_branch(self, option=''):
 
640
        self.script_runner.run_script(self, '''
 
641
                $ brz checkout %(option)s repo/trunk checkout
 
642
                $ cd checkout
 
643
                $ brz branch --switch ../repo/trunk ../repo/branched
 
644
                2>Branched 0 revisions.
 
645
                2>Tree is up to date at revision 0.
 
646
                2>Switched to branch:...branched...
 
647
                $ cd ..
 
648
                ''' % locals())
 
649
        bound_branch = branch.Branch.open_containing('checkout')[0]
 
650
        master_branch = branch.Branch.open_containing('repo/branched')[0]
 
651
        return (bound_branch, master_branch)
 
652
 
 
653
    def test_branch_switch_parent_lightweight(self):
 
654
        """Lightweight checkout using brz branch --switch."""
 
655
        bb, mb = self._checkout_and_branch(option='--lightweight')
 
656
        self.assertParent('repo/trunk', bb)
 
657
        self.assertParent('repo/trunk', mb)
 
658
 
 
659
    def test_branch_switch_parent_heavyweight(self):
 
660
        """Heavyweight checkout using brz branch --switch."""
 
661
        bb, mb = self._checkout_and_branch()
 
662
        self.assertParent('repo/trunk', bb)
 
663
        self.assertParent('repo/trunk', mb)