/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2006-2011 Canonical Ltd
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
16
17
18
"""Black-box tests for bzr branch."""
19
20
import os
21
4596.2.3 by Lukáš Lalinský
Add tests for various situations
22
from bzrlib import (
23
    branch,
24
    bzrdir,
25
    errors,
26
    revision as _mod_revision,
27
    )
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
28
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
29
from bzrlib.tests import TestCaseWithTransport
4580.4.2 by Martin Pool
Add KnownFailure for branch --hardlink
30
from bzrlib.tests import (
5651.5.3 by Andrew Bennetts
Use new fixture in more tests.
31
    fixtures,
4580.4.2 by Martin Pool
Add KnownFailure for branch --hardlink
32
    HardlinkFeature,
5816.6.7 by A. S. Budden
Moved test harnesses into test_switch and test_branch as these are the commands that are being tested.
33
    script,
5017.3.40 by Vincent Ladeuil
-s bb.test_branch passing
34
    test_server,
4580.4.2 by Martin Pool
Add KnownFailure for branch --hardlink
35
    )
5816.7.1 by Vincent Ladeuil
Remove duplication and simplify.
36
from bzrlib.tests.blackbox import test_switch
2485.8.59 by Vincent Ladeuil
Update from review comments.
37
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
5741.3.3 by Martin Pool
Add a blackbox test for deprecation of commands
38
from bzrlib.tests.script import run_script
3696.2.4 by Daniel Watkins
Fixed test to cope with trailing slashes.
39
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
1711.2.6 by John Arbash Meinel
Creating a test case for bug 43713, bzr branch does the right thing
40
from bzrlib.workingtree import WorkingTree
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
41
42
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
43
class TestBranch(TestCaseWithTransport):
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
44
2664.8.2 by Daniel Watkins
tests.blackbox.test_branch now uses internals where appropriate.
45
    def example_branch(self, path='.'):
46
        tree = self.make_branch_and_tree(path)
47
        self.build_tree_contents([(path + '/hello', 'foo')])
48
        tree.add('hello')
49
        tree.commit(message='setup')
50
        self.build_tree_contents([(path + '/goodbye', 'baz')])
51
        tree.add('goodbye')
52
        tree.commit(message='setup')
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
53
54
    def test_branch(self):
55
        """Branch from one branch to another."""
2664.8.2 by Daniel Watkins
tests.blackbox.test_branch now uses internals where appropriate.
56
        self.example_branch('a')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
57
        self.run_bzr('branch a b')
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
58
        b = branch.Branch.open('b')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
59
        self.run_bzr('branch a c -r 1')
3400.1.3 by Martin Pool
Merge trunk
60
        # previously was erroneously created by branching
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
61
        self.assertFalse(b._transport.has('branch-name'))
2664.8.2 by Daniel Watkins
tests.blackbox.test_branch now uses internals where appropriate.
62
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
63
5927.2.1 by Jonathan Riddell
start a test case for corrupt pack files
64
    def test_branch_broken_pack(self):
65
        """branching with a corrupted pack file."""
66
        self.example_branch('a')
67
        #now add some random corruption
5927.2.7 by Jonathan Riddell
in DecompressCorruption keep _fmt as a class member. in test use with for opening files
68
        fname = 'a/.bzr/repository/packs/' + os.listdir('a/.bzr/repository/packs')[0]
5927.2.8 by Jonathan Riddell
tidy up file opening in test
69
        with open(fname, 'rb+') as f:
70
            f.seek(750)
71
            f.write("\xff")
5927.2.6 by Jonathan Riddell
Make error message less specific (might not be a local disk issue) and pass through zlib error
72
        self.run_bzr_error(['Corruption while decompressing repository file'], 
73
                            'branch a b', retcode=3)
5927.2.1 by Jonathan Riddell
start a test case for corrupt pack files
74
4596.2.3 by Lukáš Lalinský
Add tests for various situations
75
    def test_branch_switch_no_branch(self):
76
        # No branch in the current directory:
77
        #  => new branch will be created, but switch fails
78
        self.example_branch('a')
79
        self.make_repository('current')
80
        self.run_bzr_error(['No WorkingTree exists for'],
81
            'branch --switch ../a ../b', working_dir='current')
82
        a = branch.Branch.open('a')
83
        b = branch.Branch.open('b')
84
        self.assertEqual(a.last_revision(), b.last_revision())
85
86
    def test_branch_switch_no_wt(self):
87
        # No working tree in the current directory:
88
        #  => new branch will be created, but switch fails and the current
89
        #     branch is unmodified
90
        self.example_branch('a')
91
        self.make_branch('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
        work = branch.Branch.open('current')
98
        self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
99
4596.2.1 by Lukáš Lalinský
Add support for `bzr branch --switch`
100
    def test_branch_switch_no_checkout(self):
4596.2.3 by Lukáš Lalinský
Add tests for various situations
101
        # Standalone branch in the current directory:
102
        #  => new branch will be created, but switch fails and the current
103
        #     branch is unmodified
4596.2.1 by Lukáš Lalinský
Add support for `bzr branch --switch`
104
        self.example_branch('a')
4596.2.3 by Lukáš Lalinský
Add tests for various situations
105
        self.make_branch_and_tree('current')
4596.2.1 by Lukáš Lalinský
Add support for `bzr branch --switch`
106
        self.run_bzr_error(['Cannot switch a branch, only a checkout'],
4596.2.3 by Lukáš Lalinský
Add tests for various situations
107
            'branch --switch ../a ../b', working_dir='current')
108
        a = branch.Branch.open('a')
109
        b = branch.Branch.open('b')
110
        self.assertEqual(a.last_revision(), b.last_revision())
111
        work = branch.Branch.open('current')
112
        self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
113
114
    def test_branch_switch_checkout(self):
115
        # Checkout in the current directory:
116
        #  => new branch will be created and checkout bound to the new branch
117
        self.example_branch('a')
118
        self.run_bzr('checkout a current')
119
        out, err = self.run_bzr('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 = WorkingTree.open('current')
124
        self.assertEndsWith(work.branch.get_bound_location(), '/b/')
125
        self.assertContainsRe(err, "Switched to branch: .*/b/")
126
127
    def test_branch_switch_lightweight_checkout(self):
128
        # Lightweight checkout in the current directory:
129
        #  => new branch will be created and lightweight checkout pointed to
130
        #     the new branch
131
        self.example_branch('a')
132
        self.run_bzr('checkout --lightweight a current')
133
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
134
        a = branch.Branch.open('a')
135
        b = branch.Branch.open('b')
136
        self.assertEqual(a.last_revision(), b.last_revision())
137
        work = WorkingTree.open('current')
138
        self.assertEndsWith(work.branch.base, '/b/')
4596.2.1 by Lukáš Lalinský
Add support for `bzr branch --switch`
139
        self.assertContainsRe(err, "Switched to branch: .*/b/")
140
1711.2.6 by John Arbash Meinel
Creating a test case for bug 43713, bzr branch does the right thing
141
    def test_branch_only_copies_history(self):
142
        # Knit branches should only push the history for the current revision.
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
143
        format = bzrdir.BzrDirMetaFormat1()
1711.2.6 by John Arbash Meinel
Creating a test case for bug 43713, bzr branch does the right thing
144
        format.repository_format = RepositoryFormatKnit1()
145
        shared_repo = self.make_repository('repo', format=format, shared=True)
146
        shared_repo.set_make_working_trees(True)
147
148
        def make_shared_tree(path):
149
            shared_repo.bzrdir.root_transport.mkdir(path)
150
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
151
            return WorkingTree.open('repo/' + path)
152
        tree_a = make_shared_tree('a')
153
        self.build_tree(['repo/a/file'])
154
        tree_a.add('file')
155
        tree_a.commit('commit a-1', rev_id='a-1')
156
        f = open('repo/a/file', 'ab')
157
        f.write('more stuff\n')
158
        f.close()
159
        tree_a.commit('commit a-2', rev_id='a-2')
160
161
        tree_b = make_shared_tree('b')
162
        self.build_tree(['repo/b/file'])
163
        tree_b.add('file')
164
        tree_b.commit('commit b-1', rev_id='b-1')
165
166
        self.assertTrue(shared_repo.has_revision('a-1'))
167
        self.assertTrue(shared_repo.has_revision('a-2'))
168
        self.assertTrue(shared_repo.has_revision('b-1'))
169
170
        # Now that we have a repository with shared files, make sure
171
        # that things aren't copied out by a 'branch'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
172
        self.run_bzr('branch repo/b branch-b')
1711.2.6 by John Arbash Meinel
Creating a test case for bug 43713, bzr branch does the right thing
173
        pushed_tree = WorkingTree.open('branch-b')
174
        pushed_repo = pushed_tree.branch.repository
175
        self.assertFalse(pushed_repo.has_revision('a-1'))
176
        self.assertFalse(pushed_repo.has_revision('a-2'))
177
        self.assertTrue(pushed_repo.has_revision('b-1'))
178
3136.1.3 by Aaron Bentley
Implement hard-link support for branch and checkout
179
    def test_branch_hardlink(self):
180
        self.requireFeature(HardlinkFeature)
181
        source = self.make_branch_and_tree('source')
182
        self.build_tree(['source/file1'])
183
        source.add('file1')
184
        source.commit('added file')
4580.4.2 by Martin Pool
Add KnownFailure for branch --hardlink
185
        out, err = self.run_bzr(['branch', 'source', 'target', '--hardlink'])
3136.1.3 by Aaron Bentley
Implement hard-link support for branch and checkout
186
        source_stat = os.stat('source/file1')
187
        target_stat = os.stat('target/file1')
4826.1.3 by Andrew Bennetts
Remove KnownFailure from test_branch_hardlink.
188
        self.assertEqual(source_stat, target_stat)
3136.1.3 by Aaron Bentley
Implement hard-link support for branch and checkout
189
5353.2.2 by John Arbash Meinel
update the test suite.
190
    def test_branch_files_from(self):
191
        source = self.make_branch_and_tree('source')
192
        self.build_tree(['source/file1'])
193
        source.add('file1')
194
        source.commit('added file')
195
        out, err = self.run_bzr('branch source target --files-from source')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
196
        self.assertPathExists('target/file1')
5353.2.2 by John Arbash Meinel
update the test suite.
197
198
    def test_branch_files_from_hardlink(self):
199
        self.requireFeature(HardlinkFeature)
200
        source = self.make_branch_and_tree('source')
201
        self.build_tree(['source/file1'])
202
        source.add('file1')
203
        source.commit('added file')
204
        source.bzrdir.sprout('second')
205
        out, err = self.run_bzr('branch source target --files-from second'
206
                                ' --hardlink')
207
        source_stat = os.stat('source/file1')
208
        second_stat = os.stat('second/file1')
209
        target_stat = os.stat('target/file1')
210
        self.assertNotEqual(source_stat, target_stat)
5353.2.5 by John Arbash Meinel
We need to assert that the --hardlink makes the files the same, not different.
211
        self.assertEqual(second_stat, target_stat)
5353.2.2 by John Arbash Meinel
update the test suite.
212
3696.2.1 by Daniel Watkins
Added test for 'branch --standalone'.
213
    def test_branch_standalone(self):
214
        shared_repo = self.make_repository('repo', shared=True)
215
        self.example_branch('source')
216
        self.run_bzr('branch --standalone source repo/target')
217
        b = branch.Branch.open('repo/target')
218
        expected_repo_path = os.path.abspath('repo/target/.bzr/repository')
3696.2.4 by Daniel Watkins
Fixed test to cope with trailing slashes.
219
        self.assertEqual(strip_trailing_slash(b.repository.base),
220
            strip_trailing_slash(local_path_to_url(expected_repo_path)))
3696.2.1 by Daniel Watkins
Added test for 'branch --standalone'.
221
3983.1.5 by Daniel Watkins
Added blackbox test.
222
    def test_branch_no_tree(self):
223
        self.example_branch('source')
224
        self.run_bzr('branch --no-tree source target')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
225
        self.assertPathDoesNotExist('target/hello')
226
        self.assertPathDoesNotExist('target/goodbye')
3983.1.5 by Daniel Watkins
Added blackbox test.
227
4479.2.1 by Alexander Belchenko
branch command now has new flag --use-existing-dir to force branching into existing directory if there is no branch yet.
228
    def test_branch_into_existing_dir(self):
229
        self.example_branch('a')
4479.2.2 by Vincent Ladeuil
Fix typos and add NEWS entry.
230
        # existing dir with similar files but no .bzr dir
231
        self.build_tree_contents([('b/',)])
4479.2.1 by Alexander Belchenko
branch command now has new flag --use-existing-dir to force branching into existing directory if there is no branch yet.
232
        self.build_tree_contents([('b/hello', 'bar')])  # different content
4479.2.2 by Vincent Ladeuil
Fix typos and add NEWS entry.
233
        self.build_tree_contents([('b/goodbye', 'baz')])# same content
234
        # fails without --use-existing-dir
4479.2.1 by Alexander Belchenko
branch command now has new flag --use-existing-dir to force branching into existing directory if there is no branch yet.
235
        out,err = self.run_bzr('branch a b', retcode=3)
236
        self.assertEqual('', out)
237
        self.assertEqual('bzr: ERROR: Target directory "b" already exists.\n',
238
            err)
239
        # force operation
240
        self.run_bzr('branch a b --use-existing-dir')
241
        # check conflicts
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
242
        self.assertPathExists('b/hello.moved')
243
        self.assertPathDoesNotExist('b/godbye.moved')
4479.2.1 by Alexander Belchenko
branch command now has new flag --use-existing-dir to force branching into existing directory if there is no branch yet.
244
        # we can't branch into branch
245
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
246
        self.assertEqual('', out)
247
        self.assertEqual('bzr: ERROR: Already a branch: "b".\n', err)
248
4927.3.1 by Ian Clatworthy
branch --bind option
249
    def test_branch_bind(self):
250
        self.example_branch('a')
251
        out, err = self.run_bzr('branch a b --bind')
4948.3.1 by Ian Clatworthy
branch --bind option
252
        self.assertEndsWith(err, "New branch bound to a\n")
4927.3.1 by Ian Clatworthy
branch --bind option
253
        b = branch.Branch.open('b')
254
        self.assertEndsWith(b.get_bound_location(), '/a/')
255
5107.3.6 by Marco Pantaleoni
Documented behaviour of 'post_branch_init' for lightweight checkouts.
256
    def test_branch_with_post_branch_init_hook(self):
257
        calls = []
258
        branch.Branch.hooks.install_named_hook('post_branch_init',
259
            calls.append, None)
260
        self.assertLength(0, calls)
261
        self.example_branch('a')
262
        self.assertLength(1, calls)
263
        self.run_bzr('branch a b')
264
        self.assertLength(2, calls)
265
266
    def test_checkout_with_post_branch_init_hook(self):
267
        calls = []
268
        branch.Branch.hooks.install_named_hook('post_branch_init',
269
            calls.append, None)
270
        self.assertLength(0, calls)
271
        self.example_branch('a')
272
        self.assertLength(1, calls)
273
        self.run_bzr('checkout a b')
274
        self.assertLength(2, calls)
275
276
    def test_lightweight_checkout_with_post_branch_init_hook(self):
277
        calls = []
278
        branch.Branch.hooks.install_named_hook('post_branch_init',
279
            calls.append, None)
280
        self.assertLength(0, calls)
281
        self.example_branch('a')
282
        self.assertLength(1, calls)
283
        self.run_bzr('checkout --lightweight a b')
284
        self.assertLength(2, calls)
285
5535.3.1 by Andrew Bennetts
Initial hack to make 'bzr branch' (and BzrDir.sprout) fetch all tags, not just branch tip.
286
    def test_branch_fetches_all_tags(self):
287
        builder = self.make_branch_builder('source')
5651.5.3 by Andrew Bennetts
Use new fixture in more tests.
288
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
5535.3.1 by Andrew Bennetts
Initial hack to make 'bzr branch' (and BzrDir.sprout) fetch all tags, not just branch tip.
289
        source.tags.set_tag('tag-a', 'rev-2')
290
        # Now source has a tag not in its ancestry.  Make a branch from it.
291
        self.run_bzr('branch source new-branch')
292
        new_branch = branch.Branch.open('new-branch')
293
        # The tag is present, and so is its revision.
294
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
295
        new_branch.repository.get_revision('rev-2')
296
3665.2.5 by John Arbash Meinel
Test that we alert the user to the upgrade.
297
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
298
class TestBranchStacked(TestCaseWithTransport):
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
299
    """Tests for branch --stacked"""
300
3517.4.11 by Martin Pool
Improved blackbox tests for stacked branches
301
    def assertRevisionInRepository(self, repo_path, revid):
302
        """Check that a revision is in a repository, disregarding stacking."""
303
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
304
        self.assertTrue(repo.has_revision(revid))
305
306
    def assertRevisionNotInRepository(self, repo_path, revid):
307
        """Check that a revision is not in a repository, disregarding stacking."""
308
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
309
        self.assertFalse(repo.has_revision(revid))
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
310
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
311
    def assertRevisionsInBranchRepository(self, revid_list, branch_path):
312
        repo = branch.Branch.open(branch_path).repository
313
        self.assertEqual(set(revid_list),
314
            repo.has_revisions(revid_list))
315
316
    def test_branch_stacked_branch_not_stacked(self):
317
        """Branching a stacked branch is not stacked by default"""
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
318
        # We have a mainline
319
        trunk_tree = self.make_branch_and_tree('target',
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
320
            format='1.9')
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
321
        trunk_tree.commit('mainline')
3221.20.3 by Ian Clatworthy
shallow -> stacked
322
        # and a branch from it which is stacked
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
323
        branch_tree = self.make_branch_and_tree('branch',
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
324
            format='1.9')
3537.3.3 by Martin Pool
Rename Branch.set_stacked_on to set_stacked_on_url
325
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
326
        # with some work on it
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
327
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
328
        work_tree.commit('moar work plz')
329
        work_tree.branch.push(branch_tree.branch)
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
330
        # branching our local branch gives us a new stacked branch pointing at
331
        # mainline.
332
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
333
        self.assertEqual('', out)
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
334
        self.assertEqual('Branched 2 revision(s).\n',
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
335
            err)
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
336
        # it should have preserved the branch format, and so it should be
337
        # capable of supporting stacking, but not actually have a stacked_on
338
        # branch configured
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
339
        self.assertRaises(errors.NotStacked,
340
            bzrdir.BzrDir.open('newbranch').open_branch().get_stacked_on_url)
341
342
    def test_branch_stacked_branch_stacked(self):
343
        """Asking to stack on a stacked branch does work"""
344
        # We have a mainline
345
        trunk_tree = self.make_branch_and_tree('target',
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
346
            format='1.9')
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
347
        trunk_revid = trunk_tree.commit('mainline')
348
        # and a branch from it which is stacked
349
        branch_tree = self.make_branch_and_tree('branch',
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
350
            format='1.9')
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
351
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
352
        # with some work on it
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
353
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
354
        branch_revid = work_tree.commit('moar work plz')
355
        work_tree.branch.push(branch_tree.branch)
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
356
        # you can chain branches on from there
357
        out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
358
        self.assertEqual('', out)
3221.20.3 by Ian Clatworthy
shallow -> stacked
359
        self.assertEqual('Created new stacked branch referring to %s.\n' %
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
360
            branch_tree.branch.base, err)
361
        self.assertEqual(branch_tree.branch.base,
362
            branch.Branch.open('branch2').get_stacked_on_url())
363
        branch2_tree = WorkingTree.open('branch2')
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
364
        branch2_revid = work_tree.commit('work on second stacked branch')
365
        work_tree.branch.push(branch2_tree.branch)
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
366
        self.assertRevisionInRepository('branch2', branch2_revid)
367
        self.assertRevisionsInBranchRepository(
368
            [trunk_revid, branch_revid, branch2_revid],
369
            'branch2')
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
370
3221.20.3 by Ian Clatworthy
shallow -> stacked
371
    def test_branch_stacked(self):
3221.11.20 by Robert Collins
Support --shallow on branch.
372
        # We have a mainline
373
        trunk_tree = self.make_branch_and_tree('mainline',
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
374
            format='1.9')
3517.4.11 by Martin Pool
Improved blackbox tests for stacked branches
375
        original_revid = trunk_tree.commit('mainline')
376
        self.assertRevisionInRepository('mainline', original_revid)
3221.20.3 by Ian Clatworthy
shallow -> stacked
377
        # and a branch from it which is stacked
378
        out, err = self.run_bzr(['branch', '--stacked', 'mainline',
3221.20.1 by Ian Clatworthy
tweaks by igc during review
379
            'newbranch'])
3221.11.20 by Robert Collins
Support --shallow on branch.
380
        self.assertEqual('', out)
3221.20.3 by Ian Clatworthy
shallow -> stacked
381
        self.assertEqual('Created new stacked branch referring to %s.\n' %
3221.11.20 by Robert Collins
Support --shallow on branch.
382
            trunk_tree.branch.base, err)
3517.4.11 by Martin Pool
Improved blackbox tests for stacked branches
383
        self.assertRevisionNotInRepository('newbranch', original_revid)
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
384
        new_branch = branch.Branch.open('newbranch')
385
        self.assertEqual(trunk_tree.branch.base, new_branch.get_stacked_on_url())
3221.11.20 by Robert Collins
Support --shallow on branch.
386
3221.15.10 by Robert Collins
Add test that we can stack on a smart server from Jonathan Lange.
387
    def test_branch_stacked_from_smart_server(self):
388
        # We can branch stacking on a smart server
5017.3.40 by Vincent Ladeuil
-s bb.test_branch passing
389
        self.transport_server = test_server.SmartTCPServer_for_testing
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
390
        trunk = self.make_branch('mainline', format='1.9')
3221.15.10 by Robert Collins
Add test that we can stack on a smart server from Jonathan Lange.
391
        out, err = self.run_bzr(
392
            ['branch', '--stacked', self.get_url('mainline'), 'shallow'])
393
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
394
    def test_branch_stacked_from_non_stacked_format(self):
395
        """The origin format doesn't support stacking"""
396
        trunk = self.make_branch('trunk', format='pack-0.92')
397
        out, err = self.run_bzr(
398
            ['branch', '--stacked', 'trunk', 'shallow'])
3665.2.5 by John Arbash Meinel
Test that we alert the user to the upgrade.
399
        # We should notify the user that we upgraded their format
3665.2.6 by John Arbash Meinel
Change the text a bit, and point to the explicit --1.6 or --1.6.1-rich-root bzrdir format.
400
        self.assertEqualDiff(
4401.1.3 by John Arbash Meinel
Change back to defaulting to --1.6 format, and update the blackbox tests.
401
            'Source repository format does not support stacking, using format:\n'
3665.2.6 by John Arbash Meinel
Change the text a bit, and point to the explicit --1.6 or --1.6.1-rich-root bzrdir format.
402
            '  Packs 5 (adds stacking support, requires bzr 1.6)\n'
4401.1.3 by John Arbash Meinel
Change back to defaulting to --1.6 format, and update the blackbox tests.
403
            'Source branch format does not support stacking, using format:\n'
404
            '  Branch format 7\n'
4634.144.6 by Martin Pool
Branching that does an implicit conversion now shows the fetch warning
405
            'Doing on-the-fly conversion from RepositoryFormatKnitPack1() to RepositoryFormatKnitPack5().\n'
406
            'This may take some time. Upgrade the repositories to the same format for better performance.\n'
3665.2.6 by John Arbash Meinel
Change the text a bit, and point to the explicit --1.6 or --1.6.1-rich-root bzrdir format.
407
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
408
            err)
409
410
    def test_branch_stacked_from_rich_root_non_stackable(self):
411
        trunk = self.make_branch('trunk', format='rich-root-pack')
412
        out, err = self.run_bzr(
413
            ['branch', '--stacked', 'trunk', 'shallow'])
414
        # We should notify the user that we upgraded their format
415
        self.assertEqualDiff(
4401.1.3 by John Arbash Meinel
Change back to defaulting to --1.6 format, and update the blackbox tests.
416
            'Source repository format does not support stacking, using format:\n'
3665.2.6 by John Arbash Meinel
Change the text a bit, and point to the explicit --1.6 or --1.6.1-rich-root bzrdir format.
417
            '  Packs 5 rich-root (adds stacking support, requires bzr 1.6.1)\n'
4401.1.3 by John Arbash Meinel
Change back to defaulting to --1.6 format, and update the blackbox tests.
418
            'Source branch format does not support stacking, using format:\n'
419
            '  Branch format 7\n'
4634.144.6 by Martin Pool
Branching that does an implicit conversion now shows the fetch warning
420
            'Doing on-the-fly conversion from RepositoryFormatKnitPack4() to RepositoryFormatKnitPack5RichRoot().\n'
421
            'This may take some time. Upgrade the repositories to the same format for better performance.\n'
3665.2.6 by John Arbash Meinel
Change the text a bit, and point to the explicit --1.6 or --1.6.1-rich-root bzrdir format.
422
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
423
            err)
424
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
425
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
426
class TestSmartServerBranching(TestCaseWithTransport):
4060.1.1 by Robert Collins
Add ratcheted acceptance test for branching from a smart server.
427
4060.1.4 by Robert Collins
Streaming fetch from remote servers.
428
    def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
429
        self.setup_smart_server_with_call_log()
430
        t = self.make_branch_and_tree('from')
431
        for count in range(9):
432
            t.commit(message='commit %d' % count)
433
        self.reset_smart_call_log()
434
        out, err = self.run_bzr(['branch', self.get_url('from'),
435
            self.get_url('target')])
436
        # This figure represent the amount of work to perform this use case. It
437
        # is entirely ok to reduce this number if a test fails due to rpc_count
438
        # being too low. If rpc_count increases, more network roundtrips have
439
        # become necessary for this use case. Please do not adjust this number
440
        # upwards without agreement from bzr's network support maintainers.
5535.3.5 by Andrew Bennetts
Replace for-loop of fetches with a single fetch call.
441
        self.assertLength(36, self.hpss_calls)
4060.1.4 by Robert Collins
Streaming fetch from remote servers.
442
4060.1.1 by Robert Collins
Add ratcheted acceptance test for branching from a smart server.
443
    def test_branch_from_trivial_branch_streaming_acceptance(self):
444
        self.setup_smart_server_with_call_log()
445
        t = self.make_branch_and_tree('from')
446
        for count in range(9):
447
            t.commit(message='commit %d' % count)
448
        self.reset_smart_call_log()
4060.1.2 by Robert Collins
Get RemoteToOther inter repository logic using the generic fetch code, to permit eventual streaming from smart servers.
449
        out, err = self.run_bzr(['branch', self.get_url('from'),
450
            'local-target'])
4060.1.1 by Robert Collins
Add ratcheted acceptance test for branching from a smart server.
451
        # This figure represent the amount of work to perform this use case. It
452
        # is entirely ok to reduce this number if a test fails due to rpc_count
453
        # being too low. If rpc_count increases, more network roundtrips have
454
        # become necessary for this use case. Please do not adjust this number
455
        # upwards without agreement from bzr's network support maintainers.
5535.2.1 by Andrew Bennetts
Cache a branch's tags during a read-lock.
456
        self.assertLength(9, self.hpss_calls)
4060.1.1 by Robert Collins
Add ratcheted acceptance test for branching from a smart server.
457
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
458
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
459
        self.setup_smart_server_with_call_log()
460
        t = self.make_branch_and_tree('trunk')
461
        for count in range(8):
462
            t.commit(message='commit %d' % count)
463
        tree2 = t.branch.bzrdir.sprout('feature', stacked=True
464
            ).open_workingtree()
4595.4.1 by Robert Collins
Fix test_branch_from_trivial_stacked_branch_streaming_acceptance to work with rich root formats, pending work on bug 375013.
465
        local_tree = t.branch.bzrdir.sprout('local-working').open_workingtree()
466
        local_tree.commit('feature change')
467
        local_tree.branch.push(tree2.branch)
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
468
        self.reset_smart_call_log()
469
        out, err = self.run_bzr(['branch', self.get_url('feature'),
470
            'local-target'])
471
        # This figure represent the amount of work to perform this use case. It
472
        # is entirely ok to reduce this number if a test fails due to rpc_count
473
        # being too low. If rpc_count increases, more network roundtrips have
474
        # become necessary for this use case. Please do not adjust this number
475
        # upwards without agreement from bzr's network support maintainers.
5535.2.1 by Andrew Bennetts
Cache a branch's tags during a read-lock.
476
        self.assertLength(14, self.hpss_calls)
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
477
5535.4.7 by Andrew Bennetts
Add HPSS acceptance test.
478
    def test_branch_from_branch_with_tags(self):
479
        self.setup_smart_server_with_call_log()
480
        builder = self.make_branch_builder('source')
5651.5.3 by Andrew Bennetts
Use new fixture in more tests.
481
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
5535.4.7 by Andrew Bennetts
Add HPSS acceptance test.
482
        source.tags.set_tag('tag-a', 'rev-2')
483
        source.tags.set_tag('tag-missing', 'missing-rev')
484
        # Now source has a tag not in its ancestry.  Make a branch from it.
485
        self.reset_smart_call_log()
486
        out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
487
        # This figure represent the amount of work to perform this use case. It
488
        # is entirely ok to reduce this number if a test fails due to rpc_count
489
        # being too low. If rpc_count increases, more network roundtrips have
490
        # become necessary for this use case. Please do not adjust this number
491
        # upwards without agreement from bzr's network support maintainers.
492
        self.assertLength(9, self.hpss_calls)
493
5816.8.1 by Andrew Bennetts
Be a little more clever about constructing a parents provider for stacked repositories, so that get_parent_map with local-stacked-on-remote doesn't use HPSS VFS calls.
494
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
495
        self.setup_smart_server_with_call_log()
496
        t = self.make_branch_and_tree('from')
497
        for count in range(9):
498
            t.commit(message='commit %d' % count)
499
        self.reset_smart_call_log()
500
        out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
501
            'local-target'])
5816.8.6 by Andrew Bennetts
Fix another bug, and some cosmetic nits.
502
        # XXX: the number of hpss calls for this case isn't deterministic yet,
5816.8.1 by Andrew Bennetts
Be a little more clever about constructing a parents provider for stacked repositories, so that get_parent_map with local-stacked-on-remote doesn't use HPSS VFS calls.
503
        # so we can't easily assert about the number of calls.
504
        #self.assertLength(XXX, self.hpss_calls)
505
        # We can assert that none of the calls were readv requests for rix
506
        # files, though (demonstrating that at least get_parent_map calls are
507
        # not using VFS RPCs).
508
        readvs_of_rix_files = [
509
            c for c in self.hpss_calls
510
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
511
        self.assertLength(0, readvs_of_rix_files)
512
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
513
2485.8.59 by Vincent Ladeuil
Update from review comments.
514
class TestRemoteBranch(TestCaseWithSFTPServer):
515
516
    def setUp(self):
517
        super(TestRemoteBranch, self).setUp()
518
        tree = self.make_branch_and_tree('branch')
519
        self.build_tree_contents([('branch/file', 'file content\n')])
520
        tree.add('file')
521
        tree.commit('file created')
522
523
    def test_branch_local_remote(self):
524
        self.run_bzr(['branch', 'branch', self.get_url('remote')])
525
        t = self.get_transport()
2485.8.62 by Vincent Ladeuil
From review comments, fix typos and deprecate some functions.
526
        # Ensure that no working tree what created remotely
2485.8.59 by Vincent Ladeuil
Update from review comments.
527
        self.assertFalse(t.has('remote/file'))
528
529
    def test_branch_remote_remote(self):
530
        # Light cheat: we access the branch remotely
531
        self.run_bzr(['branch', self.get_url('branch'),
532
                      self.get_url('remote')])
533
        t = self.get_transport()
2485.8.62 by Vincent Ladeuil
From review comments, fix typos and deprecate some functions.
534
        # Ensure that no working tree what created remotely
2485.8.59 by Vincent Ladeuil
Update from review comments.
535
        self.assertFalse(t.has('remote/file'))
536
5741.3.3 by Martin Pool
Add a blackbox test for deprecation of commands
537
538
class TestDeprecatedAliases(TestCaseWithTransport):
539
540
    def test_deprecated_aliases(self):
541
        """bzr branch can be called clone or get, but those names are deprecated.
542
543
        See bug 506265.
544
        """
545
        for command in ['clone', 'get']:
546
            run_script(self, """
547
            $ bzr %(command)s A B
548
            2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
549
            2>bzr: ERROR: Not a branch...
550
            """ % locals())
5816.6.7 by A. S. Budden
Moved test harnesses into test_switch and test_branch as these are the commands that are being tested.
551
552
5816.7.1 by Vincent Ladeuil
Remove duplication and simplify.
553
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
554
555
    def _checkout_and_branch(self, option=''):
556
        self.script_runner.run_script(self, '''
557
                $ bzr checkout %(option)s repo/trunk checkout
558
                $ cd checkout
559
                $ bzr branch --switch ../repo/trunk ../repo/branched
5816.6.8 by A. S. Budden
Refactored to use common generation code for lightweight and heavyweight.
560
                2>Branched 0 revision(s).
561
                2>Tree is up to date at revision 0.
5816.7.1 by Vincent Ladeuil
Remove duplication and simplify.
562
                2>Switched to branch:...branched...
5816.6.11 by A. S. Budden
Refactored assertParentCorrect to check the full path.
563
                $ cd ..
5816.6.10 by A. S. Budden
Use locals() instead of kwargs for more explicit parameters.
564
                ''' % locals())
5816.7.1 by Vincent Ladeuil
Remove duplication and simplify.
565
        bound_branch = branch.Branch.open_containing('checkout')[0]
566
        master_branch = branch.Branch.open_containing('repo/branched')[0]
5816.6.12 by A. S. Budden
Check parent branch of both the checkout (light or heavy) and the branch to which it is connected.
567
        return (bound_branch, master_branch)
5816.6.8 by A. S. Budden
Refactored to use common generation code for lightweight and heavyweight.
568
5816.6.7 by A. S. Budden
Moved test harnesses into test_switch and test_branch as these are the commands that are being tested.
569
    def test_branch_switch_parent_lightweight(self):
5816.7.1 by Vincent Ladeuil
Remove duplication and simplify.
570
        """Lightweight checkout using bzr branch --switch."""
571
        bb, mb = self._checkout_and_branch(option='--lightweight')
572
        self.assertParent('repo/trunk', bb)
573
        self.assertParent('repo/trunk', mb)
5816.6.7 by A. S. Budden
Moved test harnesses into test_switch and test_branch as these are the commands that are being tested.
574
575
    def test_branch_switch_parent_heavyweight(self):
5816.7.1 by Vincent Ladeuil
Remove duplication and simplify.
576
        """Heavyweight checkout using bzr branch --switch."""
577
        bb, mb = self._checkout_and_branch()
578
        self.assertParent('repo/trunk', bb)
579
        self.assertParent('repo/trunk', mb)