~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Lalo Martins remotebranch patch

Show diffs side-by-side

added added

removed removed

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