~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Ian Clatworthy
  • Date: 2007-08-13 14:33:10 UTC
  • mto: (2733.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2734.
  • Revision ID: ian.clatworthy@internode.on.net-20070813143310-twhj4la0qnupvze8
Added Quick Start Summary

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
"""Black-box tests for bzr branch."""
19
19
 
20
20
import os
21
21
 
22
 
from bzrlib import (
23
 
    branch,
24
 
    bzrdir,
25
 
    errors,
26
 
    revision as _mod_revision,
27
 
    )
 
22
from bzrlib import branch, bzrdir
28
23
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
29
 
from bzrlib.tests import TestCaseWithTransport
30
 
from bzrlib.tests import (
31
 
    fixtures,
32
 
    script,
33
 
    test_server,
34
 
    )
35
 
from bzrlib.tests.features import (
36
 
    HardlinkFeature,
37
 
    )
38
 
from bzrlib.tests.blackbox import test_switch
 
24
from bzrlib.tests.blackbox import ExternalBase
39
25
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
40
 
from bzrlib.tests.script import run_script
41
 
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
42
26
from bzrlib.workingtree import WorkingTree
43
27
 
44
28
 
45
 
class TestBranch(TestCaseWithTransport):
 
29
class TestBranch(ExternalBase):
46
30
 
47
 
    def example_branch(self, path='.'):
48
 
        tree = self.make_branch_and_tree(path)
49
 
        self.build_tree_contents([(path + '/hello', 'foo')])
50
 
        tree.add('hello')
51
 
        tree.commit(message='setup')
52
 
        self.build_tree_contents([(path + '/goodbye', 'baz')])
53
 
        tree.add('goodbye')
54
 
        tree.commit(message='setup')
 
31
    def example_branch(test):
 
32
        test.run_bzr('init')
 
33
        file('hello', 'wt').write('foo')
 
34
        test.run_bzr('add hello')
 
35
        test.run_bzr('commit -m setup hello')
 
36
        file('goodbye', 'wt').write('baz')
 
37
        test.run_bzr('add goodbye')
 
38
        test.run_bzr('commit -m setup goodbye')
55
39
 
56
40
    def test_branch(self):
57
41
        """Branch from one branch to another."""
58
 
        self.example_branch('a')
 
42
        os.mkdir('a')
 
43
        os.chdir('a')
 
44
        self.example_branch()
 
45
        os.chdir('..')
59
46
        self.run_bzr('branch a b')
60
47
        b = branch.Branch.open('b')
 
48
        self.assertEqual('b\n', b.control_files.get_utf8('branch-name').read())
61
49
        self.run_bzr('branch a c -r 1')
62
 
        # previously was erroneously created by branching
63
 
        self.assertFalse(b._transport.has('branch-name'))
64
 
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
65
 
 
66
 
    def test_branch_broken_pack(self):
67
 
        """branching with a corrupted pack file."""
68
 
        self.example_branch('a')
69
 
        # add some corruption
70
 
        packs_dir = 'a/.bzr/repository/packs/'
71
 
        fname = packs_dir + os.listdir(packs_dir)[0]
72
 
        with open(fname, 'rb+') as f:
73
 
            # Start from the end of the file to avoid choosing a place bigger
74
 
            # than the file itself.
75
 
            f.seek(-5, os.SEEK_END)
76
 
            c = f.read(1)
77
 
            f.seek(-5, os.SEEK_END)
78
 
            # Make sure we inject a value different than the one we just read
79
 
            if c == '\xFF':
80
 
                corrupt = '\x00'
81
 
            else:
82
 
                corrupt = '\xFF'
83
 
            f.write(corrupt) # make sure we corrupt something
84
 
        self.run_bzr_error(['Corruption while decompressing repository file'], 
85
 
                            'branch a b', retcode=3)
86
 
 
87
 
    def test_branch_switch_no_branch(self):
88
 
        # No branch in the current directory:
89
 
        #  => new branch will be created, but switch fails
90
 
        self.example_branch('a')
91
 
        self.make_repository('current')
92
 
        self.run_bzr_error(['No WorkingTree exists for'],
93
 
            'branch --switch ../a ../b', working_dir='current')
94
 
        a = branch.Branch.open('a')
95
 
        b = branch.Branch.open('b')
96
 
        self.assertEqual(a.last_revision(), b.last_revision())
97
 
 
98
 
    def test_branch_switch_no_wt(self):
99
 
        # No working tree in the current directory:
100
 
        #  => new branch will be created, but switch fails and the current
101
 
        #     branch is unmodified
102
 
        self.example_branch('a')
103
 
        self.make_branch('current')
104
 
        self.run_bzr_error(['No WorkingTree exists for'],
105
 
            'branch --switch ../a ../b', working_dir='current')
106
 
        a = branch.Branch.open('a')
107
 
        b = branch.Branch.open('b')
108
 
        self.assertEqual(a.last_revision(), b.last_revision())
109
 
        work = branch.Branch.open('current')
110
 
        self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
111
 
 
112
 
    def test_branch_switch_no_checkout(self):
113
 
        # Standalone branch in the current directory:
114
 
        #  => new branch will be created, but switch fails and the current
115
 
        #     branch is unmodified
116
 
        self.example_branch('a')
117
 
        self.make_branch_and_tree('current')
118
 
        self.run_bzr_error(['Cannot switch a branch, only a checkout'],
119
 
            'branch --switch ../a ../b', working_dir='current')
120
 
        a = branch.Branch.open('a')
121
 
        b = branch.Branch.open('b')
122
 
        self.assertEqual(a.last_revision(), b.last_revision())
123
 
        work = branch.Branch.open('current')
124
 
        self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
125
 
 
126
 
    def test_branch_switch_checkout(self):
127
 
        # Checkout in the current directory:
128
 
        #  => new branch will be created and checkout bound to the new branch
129
 
        self.example_branch('a')
130
 
        self.run_bzr('checkout a current')
131
 
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
132
 
        a = branch.Branch.open('a')
133
 
        b = branch.Branch.open('b')
134
 
        self.assertEqual(a.last_revision(), b.last_revision())
135
 
        work = WorkingTree.open('current')
136
 
        self.assertEndsWith(work.branch.get_bound_location(), '/b/')
137
 
        self.assertContainsRe(err, "Switched to branch: .*/b/")
138
 
 
139
 
    def test_branch_switch_lightweight_checkout(self):
140
 
        # Lightweight checkout in the current directory:
141
 
        #  => new branch will be created and lightweight checkout pointed to
142
 
        #     the new branch
143
 
        self.example_branch('a')
144
 
        self.run_bzr('checkout --lightweight a current')
145
 
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
146
 
        a = branch.Branch.open('a')
147
 
        b = branch.Branch.open('b')
148
 
        self.assertEqual(a.last_revision(), b.last_revision())
149
 
        work = WorkingTree.open('current')
150
 
        self.assertEndsWith(work.branch.base, '/b/')
151
 
        self.assertContainsRe(err, "Switched to branch: .*/b/")
 
50
        os.chdir('b')
 
51
        self.run_bzr('commit -m foo --unchanged')
 
52
        os.chdir('..')
152
53
 
153
54
    def test_branch_only_copies_history(self):
154
55
        # Knit branches should only push the history for the current revision.
188
89
        self.assertFalse(pushed_repo.has_revision('a-2'))
189
90
        self.assertTrue(pushed_repo.has_revision('b-1'))
190
91
 
191
 
    def test_branch_hardlink(self):
192
 
        self.requireFeature(HardlinkFeature)
193
 
        source = self.make_branch_and_tree('source')
194
 
        self.build_tree(['source/file1'])
195
 
        source.add('file1')
196
 
        source.commit('added file')
197
 
        out, err = self.run_bzr(['branch', 'source', 'target', '--hardlink'])
198
 
        source_stat = os.stat('source/file1')
199
 
        target_stat = os.stat('target/file1')
200
 
        self.assertEqual(source_stat, target_stat)
201
 
 
202
 
    def test_branch_files_from(self):
203
 
        source = self.make_branch_and_tree('source')
204
 
        self.build_tree(['source/file1'])
205
 
        source.add('file1')
206
 
        source.commit('added file')
207
 
        out, err = self.run_bzr('branch source target --files-from source')
208
 
        self.assertPathExists('target/file1')
209
 
 
210
 
    def test_branch_files_from_hardlink(self):
211
 
        self.requireFeature(HardlinkFeature)
212
 
        source = self.make_branch_and_tree('source')
213
 
        self.build_tree(['source/file1'])
214
 
        source.add('file1')
215
 
        source.commit('added file')
216
 
        source.bzrdir.sprout('second')
217
 
        out, err = self.run_bzr('branch source target --files-from second'
218
 
                                ' --hardlink')
219
 
        source_stat = os.stat('source/file1')
220
 
        second_stat = os.stat('second/file1')
221
 
        target_stat = os.stat('target/file1')
222
 
        self.assertNotEqual(source_stat, target_stat)
223
 
        self.assertEqual(second_stat, target_stat)
224
 
 
225
 
    def test_branch_standalone(self):
226
 
        shared_repo = self.make_repository('repo', shared=True)
227
 
        self.example_branch('source')
228
 
        self.run_bzr('branch --standalone source repo/target')
229
 
        b = branch.Branch.open('repo/target')
230
 
        expected_repo_path = os.path.abspath('repo/target/.bzr/repository')
231
 
        self.assertEqual(strip_trailing_slash(b.repository.base),
232
 
            strip_trailing_slash(local_path_to_url(expected_repo_path)))
233
 
 
234
 
    def test_branch_no_tree(self):
235
 
        self.example_branch('source')
236
 
        self.run_bzr('branch --no-tree source target')
237
 
        self.assertPathDoesNotExist('target/hello')
238
 
        self.assertPathDoesNotExist('target/goodbye')
239
 
 
240
 
    def test_branch_into_existing_dir(self):
241
 
        self.example_branch('a')
242
 
        # existing dir with similar files but no .bzr dir
243
 
        self.build_tree_contents([('b/',)])
244
 
        self.build_tree_contents([('b/hello', 'bar')])  # different content
245
 
        self.build_tree_contents([('b/goodbye', 'baz')])# same content
246
 
        # fails without --use-existing-dir
247
 
        out,err = self.run_bzr('branch a b', retcode=3)
248
 
        self.assertEqual('', out)
249
 
        self.assertEqual('bzr: ERROR: Target directory "b" already exists.\n',
250
 
            err)
251
 
        # force operation
252
 
        self.run_bzr('branch a b --use-existing-dir')
253
 
        # check conflicts
254
 
        self.assertPathExists('b/hello.moved')
255
 
        self.assertPathDoesNotExist('b/godbye.moved')
256
 
        # we can't branch into branch
257
 
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
258
 
        self.assertEqual('', out)
259
 
        self.assertEqual('bzr: ERROR: Already a branch: "b".\n', err)
260
 
 
261
 
    def test_branch_bind(self):
262
 
        self.example_branch('a')
263
 
        out, err = self.run_bzr('branch a b --bind')
264
 
        self.assertEndsWith(err, "New branch bound to a\n")
265
 
        b = branch.Branch.open('b')
266
 
        self.assertEndsWith(b.get_bound_location(), '/a/')
267
 
 
268
 
    def test_branch_with_post_branch_init_hook(self):
269
 
        calls = []
270
 
        branch.Branch.hooks.install_named_hook('post_branch_init',
271
 
            calls.append, None)
272
 
        self.assertLength(0, calls)
273
 
        self.example_branch('a')
274
 
        self.assertLength(1, calls)
275
 
        self.run_bzr('branch a b')
276
 
        self.assertLength(2, calls)
277
 
 
278
 
    def test_checkout_with_post_branch_init_hook(self):
279
 
        calls = []
280
 
        branch.Branch.hooks.install_named_hook('post_branch_init',
281
 
            calls.append, None)
282
 
        self.assertLength(0, calls)
283
 
        self.example_branch('a')
284
 
        self.assertLength(1, calls)
285
 
        self.run_bzr('checkout a b')
286
 
        self.assertLength(2, calls)
287
 
 
288
 
    def test_lightweight_checkout_with_post_branch_init_hook(self):
289
 
        calls = []
290
 
        branch.Branch.hooks.install_named_hook('post_branch_init',
291
 
            calls.append, None)
292
 
        self.assertLength(0, calls)
293
 
        self.example_branch('a')
294
 
        self.assertLength(1, calls)
295
 
        self.run_bzr('checkout --lightweight a b')
296
 
        self.assertLength(2, calls)
297
 
 
298
 
    def test_branch_fetches_all_tags(self):
299
 
        builder = self.make_branch_builder('source')
300
 
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
301
 
        source.tags.set_tag('tag-a', 'rev-2')
302
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
303
 
        # Now source has a tag not in its ancestry.  Make a branch from it.
304
 
        self.run_bzr('branch source new-branch')
305
 
        new_branch = branch.Branch.open('new-branch')
306
 
        # The tag is present, and so is its revision.
307
 
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
308
 
        new_branch.repository.get_revision('rev-2')
309
 
 
310
 
 
311
 
class TestBranchStacked(TestCaseWithTransport):
312
 
    """Tests for branch --stacked"""
313
 
 
314
 
    def assertRevisionInRepository(self, repo_path, revid):
315
 
        """Check that a revision is in a repository, disregarding stacking."""
316
 
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
317
 
        self.assertTrue(repo.has_revision(revid))
318
 
 
319
 
    def assertRevisionNotInRepository(self, repo_path, revid):
320
 
        """Check that a revision is not in a repository, disregarding stacking."""
321
 
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
322
 
        self.assertFalse(repo.has_revision(revid))
323
 
 
324
 
    def assertRevisionsInBranchRepository(self, revid_list, branch_path):
325
 
        repo = branch.Branch.open(branch_path).repository
326
 
        self.assertEqual(set(revid_list),
327
 
            repo.has_revisions(revid_list))
328
 
 
329
 
    def test_branch_stacked_branch_not_stacked(self):
330
 
        """Branching a stacked branch is not stacked by default"""
331
 
        # We have a mainline
332
 
        trunk_tree = self.make_branch_and_tree('target',
333
 
            format='1.9')
334
 
        trunk_tree.commit('mainline')
335
 
        # and a branch from it which is stacked
336
 
        branch_tree = self.make_branch_and_tree('branch',
337
 
            format='1.9')
338
 
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
339
 
        # with some work on it
340
 
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
341
 
        work_tree.commit('moar work plz')
342
 
        work_tree.branch.push(branch_tree.branch)
343
 
        # branching our local branch gives us a new stacked branch pointing at
344
 
        # mainline.
345
 
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
346
 
        self.assertEqual('', out)
347
 
        self.assertEqual('Branched 2 revisions.\n',
348
 
            err)
349
 
        # it should have preserved the branch format, and so it should be
350
 
        # capable of supporting stacking, but not actually have a stacked_on
351
 
        # branch configured
352
 
        self.assertRaises(errors.NotStacked,
353
 
            bzrdir.BzrDir.open('newbranch').open_branch().get_stacked_on_url)
354
 
 
355
 
    def test_branch_stacked_branch_stacked(self):
356
 
        """Asking to stack on a stacked branch does work"""
357
 
        # We have a mainline
358
 
        trunk_tree = self.make_branch_and_tree('target',
359
 
            format='1.9')
360
 
        trunk_revid = trunk_tree.commit('mainline')
361
 
        # and a branch from it which is stacked
362
 
        branch_tree = self.make_branch_and_tree('branch',
363
 
            format='1.9')
364
 
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
365
 
        # with some work on it
366
 
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
367
 
        branch_revid = work_tree.commit('moar work plz')
368
 
        work_tree.branch.push(branch_tree.branch)
369
 
        # you can chain branches on from there
370
 
        out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
371
 
        self.assertEqual('', out)
372
 
        self.assertEqual('Created new stacked branch referring to %s.\n' %
373
 
            branch_tree.branch.base, err)
374
 
        self.assertEqual(branch_tree.branch.base,
375
 
            branch.Branch.open('branch2').get_stacked_on_url())
376
 
        branch2_tree = WorkingTree.open('branch2')
377
 
        branch2_revid = work_tree.commit('work on second stacked branch')
378
 
        work_tree.branch.push(branch2_tree.branch)
379
 
        self.assertRevisionInRepository('branch2', branch2_revid)
380
 
        self.assertRevisionsInBranchRepository(
381
 
            [trunk_revid, branch_revid, branch2_revid],
382
 
            'branch2')
383
 
 
384
 
    def test_branch_stacked(self):
385
 
        # We have a mainline
386
 
        trunk_tree = self.make_branch_and_tree('mainline',
387
 
            format='1.9')
388
 
        original_revid = trunk_tree.commit('mainline')
389
 
        self.assertRevisionInRepository('mainline', original_revid)
390
 
        # and a branch from it which is stacked
391
 
        out, err = self.run_bzr(['branch', '--stacked', 'mainline',
392
 
            'newbranch'])
393
 
        self.assertEqual('', out)
394
 
        self.assertEqual('Created new stacked branch referring to %s.\n' %
395
 
            trunk_tree.branch.base, err)
396
 
        self.assertRevisionNotInRepository('newbranch', original_revid)
397
 
        new_branch = branch.Branch.open('newbranch')
398
 
        self.assertEqual(trunk_tree.branch.base, new_branch.get_stacked_on_url())
399
 
 
400
 
    def test_branch_stacked_from_smart_server(self):
401
 
        # We can branch stacking on a smart server
402
 
        self.transport_server = test_server.SmartTCPServer_for_testing
403
 
        trunk = self.make_branch('mainline', format='1.9')
404
 
        out, err = self.run_bzr(
405
 
            ['branch', '--stacked', self.get_url('mainline'), 'shallow'])
406
 
 
407
 
    def test_branch_stacked_from_non_stacked_format(self):
408
 
        """The origin format doesn't support stacking"""
409
 
        trunk = self.make_branch('trunk', format='pack-0.92')
410
 
        out, err = self.run_bzr(
411
 
            ['branch', '--stacked', 'trunk', 'shallow'])
412
 
        # We should notify the user that we upgraded their format
413
 
        self.assertEqualDiff(
414
 
            'Source repository format does not support stacking, using format:\n'
415
 
            '  Packs 5 (adds stacking support, requires bzr 1.6)\n'
416
 
            'Source branch format does not support stacking, using format:\n'
417
 
            '  Branch format 7\n'
418
 
            'Doing on-the-fly conversion from RepositoryFormatKnitPack1() to RepositoryFormatKnitPack5().\n'
419
 
            'This may take some time. Upgrade the repositories to the same format for better performance.\n'
420
 
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
421
 
            err)
422
 
 
423
 
    def test_branch_stacked_from_rich_root_non_stackable(self):
424
 
        trunk = self.make_branch('trunk', format='rich-root-pack')
425
 
        out, err = self.run_bzr(
426
 
            ['branch', '--stacked', 'trunk', 'shallow'])
427
 
        # We should notify the user that we upgraded their format
428
 
        self.assertEqualDiff(
429
 
            'Source repository format does not support stacking, using format:\n'
430
 
            '  Packs 5 rich-root (adds stacking support, requires bzr 1.6.1)\n'
431
 
            'Source branch format does not support stacking, using format:\n'
432
 
            '  Branch format 7\n'
433
 
            'Doing on-the-fly conversion from RepositoryFormatKnitPack4() to RepositoryFormatKnitPack5RichRoot().\n'
434
 
            'This may take some time. Upgrade the repositories to the same format for better performance.\n'
435
 
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
436
 
            err)
437
 
 
438
 
 
439
 
class TestSmartServerBranching(TestCaseWithTransport):
440
 
 
441
 
    def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
442
 
        self.setup_smart_server_with_call_log()
443
 
        t = self.make_branch_and_tree('from')
444
 
        for count in range(9):
445
 
            t.commit(message='commit %d' % count)
446
 
        self.reset_smart_call_log()
447
 
        out, err = self.run_bzr(['branch', self.get_url('from'),
448
 
            self.get_url('target')])
449
 
        # This figure represent the amount of work to perform this use case. It
450
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
451
 
        # being too low. If rpc_count increases, more network roundtrips have
452
 
        # become necessary for this use case. Please do not adjust this number
453
 
        # upwards without agreement from bzr's network support maintainers.
454
 
        self.assertLength(39, self.hpss_calls)
455
 
 
456
 
    def test_branch_from_trivial_branch_streaming_acceptance(self):
457
 
        self.setup_smart_server_with_call_log()
458
 
        t = self.make_branch_and_tree('from')
459
 
        for count in range(9):
460
 
            t.commit(message='commit %d' % count)
461
 
        self.reset_smart_call_log()
462
 
        out, err = self.run_bzr(['branch', self.get_url('from'),
463
 
            'local-target'])
464
 
        # This figure represent the amount of work to perform this use case. It
465
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
466
 
        # being too low. If rpc_count increases, more network roundtrips have
467
 
        # become necessary for this use case. Please do not adjust this number
468
 
        # upwards without agreement from bzr's network support maintainers.
469
 
        self.assertLength(10, self.hpss_calls)
470
 
 
471
 
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
472
 
        self.setup_smart_server_with_call_log()
473
 
        t = self.make_branch_and_tree('trunk')
474
 
        for count in range(8):
475
 
            t.commit(message='commit %d' % count)
476
 
        tree2 = t.branch.bzrdir.sprout('feature', stacked=True
477
 
            ).open_workingtree()
478
 
        local_tree = t.branch.bzrdir.sprout('local-working').open_workingtree()
479
 
        local_tree.commit('feature change')
480
 
        local_tree.branch.push(tree2.branch)
481
 
        self.reset_smart_call_log()
482
 
        out, err = self.run_bzr(['branch', self.get_url('feature'),
483
 
            'local-target'])
484
 
        # This figure represent the amount of work to perform this use case. It
485
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
486
 
        # being too low. If rpc_count increases, more network roundtrips have
487
 
        # become necessary for this use case. Please do not adjust this number
488
 
        # upwards without agreement from bzr's network support maintainers.
489
 
        self.assertLength(15, self.hpss_calls)
490
 
 
491
 
    def test_branch_from_branch_with_tags(self):
492
 
        self.setup_smart_server_with_call_log()
493
 
        builder = self.make_branch_builder('source')
494
 
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
495
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
496
 
        source.tags.set_tag('tag-a', 'rev-2')
497
 
        source.tags.set_tag('tag-missing', 'missing-rev')
498
 
        # Now source has a tag not in its ancestry.  Make a branch from it.
499
 
        self.reset_smart_call_log()
500
 
        out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
501
 
        # This figure represent the amount of work to perform this use case. It
502
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
503
 
        # being too low. If rpc_count increases, more network roundtrips have
504
 
        # become necessary for this use case. Please do not adjust this number
505
 
        # upwards without agreement from bzr's network support maintainers.
506
 
        self.assertLength(10, self.hpss_calls)
507
 
 
508
 
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
509
 
        self.setup_smart_server_with_call_log()
510
 
        t = self.make_branch_and_tree('from')
511
 
        for count in range(9):
512
 
            t.commit(message='commit %d' % count)
513
 
        self.reset_smart_call_log()
514
 
        out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
515
 
            'local-target'])
516
 
        # XXX: the number of hpss calls for this case isn't deterministic yet,
517
 
        # so we can't easily assert about the number of calls.
518
 
        #self.assertLength(XXX, self.hpss_calls)
519
 
        # We can assert that none of the calls were readv requests for rix
520
 
        # files, though (demonstrating that at least get_parent_map calls are
521
 
        # not using VFS RPCs).
522
 
        readvs_of_rix_files = [
523
 
            c for c in self.hpss_calls
524
 
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
525
 
        self.assertLength(0, readvs_of_rix_files)
526
 
 
527
92
 
528
93
class TestRemoteBranch(TestCaseWithSFTPServer):
529
94
 
548
113
        # Ensure that no working tree what created remotely
549
114
        self.assertFalse(t.has('remote/file'))
550
115
 
551
 
 
552
 
class TestDeprecatedAliases(TestCaseWithTransport):
553
 
 
554
 
    def test_deprecated_aliases(self):
555
 
        """bzr branch can be called clone or get, but those names are deprecated.
556
 
 
557
 
        See bug 506265.
558
 
        """
559
 
        for command in ['clone', 'get']:
560
 
            run_script(self, """
561
 
            $ bzr %(command)s A B
562
 
            2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
563
 
            2>bzr: ERROR: Not a branch...
564
 
            """ % locals())
565
 
 
566
 
 
567
 
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
568
 
 
569
 
    def _checkout_and_branch(self, option=''):
570
 
        self.script_runner.run_script(self, '''
571
 
                $ bzr checkout %(option)s repo/trunk checkout
572
 
                $ cd checkout
573
 
                $ bzr branch --switch ../repo/trunk ../repo/branched
574
 
                2>Branched 0 revisions.
575
 
                2>Tree is up to date at revision 0.
576
 
                2>Switched to branch:...branched...
577
 
                $ cd ..
578
 
                ''' % locals())
579
 
        bound_branch = branch.Branch.open_containing('checkout')[0]
580
 
        master_branch = branch.Branch.open_containing('repo/branched')[0]
581
 
        return (bound_branch, master_branch)
582
 
 
583
 
    def test_branch_switch_parent_lightweight(self):
584
 
        """Lightweight checkout using bzr branch --switch."""
585
 
        bb, mb = self._checkout_and_branch(option='--lightweight')
586
 
        self.assertParent('repo/trunk', bb)
587
 
        self.assertParent('repo/trunk', mb)
588
 
 
589
 
    def test_branch_switch_parent_heavyweight(self):
590
 
        """Heavyweight checkout using bzr branch --switch."""
591
 
        bb, mb = self._checkout_and_branch()
592
 
        self.assertParent('repo/trunk', bb)
593
 
        self.assertParent('repo/trunk', mb)