/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 (
31
    HardlinkFeature,
5017.3.40 by Vincent Ladeuil
-s bb.test_branch passing
32
    test_server,
4580.4.2 by Martin Pool
Add KnownFailure for branch --hardlink
33
    )
2485.8.59 by Vincent Ladeuil
Update from review comments.
34
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
3696.2.4 by Daniel Watkins
Fixed test to cope with trailing slashes.
35
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
36
from bzrlib.workingtree import WorkingTree
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
37
38
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
39
class TestBranch(TestCaseWithTransport):
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
40
2664.8.2 by Daniel Watkins
tests.blackbox.test_branch now uses internals where appropriate.
41
    def example_branch(self, path='.'):
42
        tree = self.make_branch_and_tree(path)
43
        self.build_tree_contents([(path + '/hello', 'foo')])
44
        tree.add('hello')
45
        tree.commit(message='setup')
46
        self.build_tree_contents([(path + '/goodbye', 'baz')])
47
        tree.add('goodbye')
48
        tree.commit(message='setup')
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
49
50
    def test_branch(self):
51
        """Branch from one branch to another."""
2664.8.2 by Daniel Watkins
tests.blackbox.test_branch now uses internals where appropriate.
52
        self.example_branch('a')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
53
        self.run_bzr('branch a b')
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
54
        b = branch.Branch.open('b')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
55
        self.run_bzr('branch a c -r 1')
3400.1.3 by Martin Pool
Merge trunk
56
        # previously was erroneously created by branching
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
57
        self.assertFalse(b._transport.has('branch-name'))
2664.8.2 by Daniel Watkins
tests.blackbox.test_branch now uses internals where appropriate.
58
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
59
4596.2.3 by Lukáš Lalinský
Add tests for various situations
60
    def test_branch_switch_no_branch(self):
61
        # No branch in the current directory:
62
        #  => new branch will be created, but switch fails
63
        self.example_branch('a')
64
        self.make_repository('current')
65
        self.run_bzr_error(['No WorkingTree exists for'],
66
            'branch --switch ../a ../b', working_dir='current')
67
        a = branch.Branch.open('a')
68
        b = branch.Branch.open('b')
69
        self.assertEqual(a.last_revision(), b.last_revision())
70
71
    def test_branch_switch_no_wt(self):
72
        # No working tree in the current directory:
73
        #  => new branch will be created, but switch fails and the current
74
        #     branch is unmodified
75
        self.example_branch('a')
76
        self.make_branch('current')
77
        self.run_bzr_error(['No WorkingTree exists for'],
78
            'branch --switch ../a ../b', working_dir='current')
79
        a = branch.Branch.open('a')
80
        b = branch.Branch.open('b')
81
        self.assertEqual(a.last_revision(), b.last_revision())
82
        work = branch.Branch.open('current')
83
        self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
84
4596.2.1 by Lukáš Lalinský
Add support for `bzr branch --switch`
85
    def test_branch_switch_no_checkout(self):
4596.2.3 by Lukáš Lalinský
Add tests for various situations
86
        # Standalone branch in the current directory:
87
        #  => new branch will be created, but switch fails and the current
88
        #     branch is unmodified
4596.2.1 by Lukáš Lalinský
Add support for `bzr branch --switch`
89
        self.example_branch('a')
4596.2.3 by Lukáš Lalinský
Add tests for various situations
90
        self.make_branch_and_tree('current')
4596.2.1 by Lukáš Lalinský
Add support for `bzr branch --switch`
91
        self.run_bzr_error(['Cannot switch a branch, only a checkout'],
4596.2.3 by Lukáš Lalinský
Add tests for various situations
92
            'branch --switch ../a ../b', working_dir='current')
93
        a = branch.Branch.open('a')
94
        b = branch.Branch.open('b')
95
        self.assertEqual(a.last_revision(), b.last_revision())
96
        work = branch.Branch.open('current')
97
        self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
98
99
    def test_branch_switch_checkout(self):
100
        # Checkout in the current directory:
101
        #  => new branch will be created and checkout bound to the new branch
102
        self.example_branch('a')
103
        self.run_bzr('checkout a current')
104
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
105
        a = branch.Branch.open('a')
106
        b = branch.Branch.open('b')
107
        self.assertEqual(a.last_revision(), b.last_revision())
108
        work = WorkingTree.open('current')
109
        self.assertEndsWith(work.branch.get_bound_location(), '/b/')
110
        self.assertContainsRe(err, "Switched to branch: .*/b/")
111
112
    def test_branch_switch_lightweight_checkout(self):
113
        # Lightweight checkout in the current directory:
114
        #  => new branch will be created and lightweight checkout pointed to
115
        #     the new branch
116
        self.example_branch('a')
117
        self.run_bzr('checkout --lightweight a current')
118
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
119
        a = branch.Branch.open('a')
120
        b = branch.Branch.open('b')
121
        self.assertEqual(a.last_revision(), b.last_revision())
122
        work = WorkingTree.open('current')
123
        self.assertEndsWith(work.branch.base, '/b/')
4596.2.1 by Lukáš Lalinský
Add support for `bzr branch --switch`
124
        self.assertContainsRe(err, "Switched to branch: .*/b/")
125
1711.2.6 by John Arbash Meinel
Creating a test case for bug 43713, bzr branch does the right thing
126
    def test_branch_only_copies_history(self):
127
        # Knit branches should only push the history for the current revision.
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
128
        format = bzrdir.BzrDirMetaFormat1()
1711.2.6 by John Arbash Meinel
Creating a test case for bug 43713, bzr branch does the right thing
129
        format.repository_format = RepositoryFormatKnit1()
130
        shared_repo = self.make_repository('repo', format=format, shared=True)
131
        shared_repo.set_make_working_trees(True)
132
133
        def make_shared_tree(path):
134
            shared_repo.bzrdir.root_transport.mkdir(path)
135
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
136
            return WorkingTree.open('repo/' + path)
137
        tree_a = make_shared_tree('a')
138
        self.build_tree(['repo/a/file'])
139
        tree_a.add('file')
140
        tree_a.commit('commit a-1', rev_id='a-1')
141
        f = open('repo/a/file', 'ab')
142
        f.write('more stuff\n')
143
        f.close()
144
        tree_a.commit('commit a-2', rev_id='a-2')
145
146
        tree_b = make_shared_tree('b')
147
        self.build_tree(['repo/b/file'])
148
        tree_b.add('file')
149
        tree_b.commit('commit b-1', rev_id='b-1')
150
151
        self.assertTrue(shared_repo.has_revision('a-1'))
152
        self.assertTrue(shared_repo.has_revision('a-2'))
153
        self.assertTrue(shared_repo.has_revision('b-1'))
154
155
        # Now that we have a repository with shared files, make sure
156
        # that things aren't copied out by a 'branch'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
157
        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
158
        pushed_tree = WorkingTree.open('branch-b')
159
        pushed_repo = pushed_tree.branch.repository
160
        self.assertFalse(pushed_repo.has_revision('a-1'))
161
        self.assertFalse(pushed_repo.has_revision('a-2'))
162
        self.assertTrue(pushed_repo.has_revision('b-1'))
163
3136.1.3 by Aaron Bentley
Implement hard-link support for branch and checkout
164
    def test_branch_hardlink(self):
165
        self.requireFeature(HardlinkFeature)
166
        source = self.make_branch_and_tree('source')
167
        self.build_tree(['source/file1'])
168
        source.add('file1')
169
        source.commit('added file')
4580.4.2 by Martin Pool
Add KnownFailure for branch --hardlink
170
        out, err = self.run_bzr(['branch', 'source', 'target', '--hardlink'])
3136.1.3 by Aaron Bentley
Implement hard-link support for branch and checkout
171
        source_stat = os.stat('source/file1')
172
        target_stat = os.stat('target/file1')
4826.1.3 by Andrew Bennetts
Remove KnownFailure from test_branch_hardlink.
173
        self.assertEqual(source_stat, target_stat)
3136.1.3 by Aaron Bentley
Implement hard-link support for branch and checkout
174
5353.2.2 by John Arbash Meinel
update the test suite.
175
    def test_branch_files_from(self):
176
        source = self.make_branch_and_tree('source')
177
        self.build_tree(['source/file1'])
178
        source.add('file1')
179
        source.commit('added file')
180
        out, err = self.run_bzr('branch source target --files-from source')
181
        self.failUnlessExists('target/file1')
182
183
    def test_branch_files_from_hardlink(self):
184
        self.requireFeature(HardlinkFeature)
185
        source = self.make_branch_and_tree('source')
186
        self.build_tree(['source/file1'])
187
        source.add('file1')
188
        source.commit('added file')
189
        source.bzrdir.sprout('second')
190
        out, err = self.run_bzr('branch source target --files-from second'
191
                                ' --hardlink')
192
        source_stat = os.stat('source/file1')
193
        second_stat = os.stat('second/file1')
194
        target_stat = os.stat('target/file1')
195
        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.
196
        self.assertEqual(second_stat, target_stat)
5353.2.2 by John Arbash Meinel
update the test suite.
197
3696.2.1 by Daniel Watkins
Added test for 'branch --standalone'.
198
    def test_branch_standalone(self):
199
        shared_repo = self.make_repository('repo', shared=True)
200
        self.example_branch('source')
201
        self.run_bzr('branch --standalone source repo/target')
202
        b = branch.Branch.open('repo/target')
203
        expected_repo_path = os.path.abspath('repo/target/.bzr/repository')
3696.2.4 by Daniel Watkins
Fixed test to cope with trailing slashes.
204
        self.assertEqual(strip_trailing_slash(b.repository.base),
205
            strip_trailing_slash(local_path_to_url(expected_repo_path)))
3696.2.1 by Daniel Watkins
Added test for 'branch --standalone'.
206
3983.1.5 by Daniel Watkins
Added blackbox test.
207
    def test_branch_no_tree(self):
208
        self.example_branch('source')
209
        self.run_bzr('branch --no-tree source target')
210
        self.failIfExists('target/hello')
211
        self.failIfExists('target/goodbye')
212
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.
213
    def test_branch_into_existing_dir(self):
214
        self.example_branch('a')
4479.2.2 by Vincent Ladeuil
Fix typos and add NEWS entry.
215
        # existing dir with similar files but no .bzr dir
216
        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.
217
        self.build_tree_contents([('b/hello', 'bar')])  # different content
4479.2.2 by Vincent Ladeuil
Fix typos and add NEWS entry.
218
        self.build_tree_contents([('b/goodbye', 'baz')])# same content
219
        # 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.
220
        out,err = self.run_bzr('branch a b', retcode=3)
221
        self.assertEqual('', out)
222
        self.assertEqual('bzr: ERROR: Target directory "b" already exists.\n',
223
            err)
224
        # force operation
225
        self.run_bzr('branch a b --use-existing-dir')
226
        # check conflicts
227
        self.failUnlessExists('b/hello.moved')
228
        self.failIfExists('b/godbye.moved')
229
        # we can't branch into branch
230
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
231
        self.assertEqual('', out)
232
        self.assertEqual('bzr: ERROR: Already a branch: "b".\n', err)
233
4927.3.1 by Ian Clatworthy
branch --bind option
234
    def test_branch_bind(self):
235
        self.example_branch('a')
236
        out, err = self.run_bzr('branch a b --bind')
4948.3.1 by Ian Clatworthy
branch --bind option
237
        self.assertEndsWith(err, "New branch bound to a\n")
4927.3.1 by Ian Clatworthy
branch --bind option
238
        b = branch.Branch.open('b')
239
        self.assertEndsWith(b.get_bound_location(), '/a/')
240
5107.3.6 by Marco Pantaleoni
Documented behaviour of 'post_branch_init' for lightweight checkouts.
241
    def test_branch_with_post_branch_init_hook(self):
242
        calls = []
243
        branch.Branch.hooks.install_named_hook('post_branch_init',
244
            calls.append, None)
245
        self.assertLength(0, calls)
246
        self.example_branch('a')
247
        self.assertLength(1, calls)
248
        self.run_bzr('branch a b')
249
        self.assertLength(2, calls)
250
251
    def test_checkout_with_post_branch_init_hook(self):
252
        calls = []
253
        branch.Branch.hooks.install_named_hook('post_branch_init',
254
            calls.append, None)
255
        self.assertLength(0, calls)
256
        self.example_branch('a')
257
        self.assertLength(1, calls)
258
        self.run_bzr('checkout a b')
259
        self.assertLength(2, calls)
260
261
    def test_lightweight_checkout_with_post_branch_init_hook(self):
262
        calls = []
263
        branch.Branch.hooks.install_named_hook('post_branch_init',
264
            calls.append, None)
265
        self.assertLength(0, calls)
266
        self.example_branch('a')
267
        self.assertLength(1, calls)
268
        self.run_bzr('checkout --lightweight a b')
269
        self.assertLength(2, calls)
270
5535.3.1 by Andrew Bennetts
Initial hack to make 'bzr branch' (and BzrDir.sprout) fetch all tags, not just branch tip.
271
    def test_branch_fetches_all_tags(self):
272
        builder = self.make_branch_builder('source')
273
        builder.build_commit(message="Rev 1", rev_id='rev-1')
274
        builder.build_commit(message="Rev 2", rev_id='rev-2')
275
        source = builder.get_branch()
276
        source.tags.set_tag('tag-a', 'rev-2')
277
        source.set_last_revision_info(1, 'rev-1')
278
        # Now source has a tag not in its ancestry.  Make a branch from it.
279
        self.run_bzr('branch source new-branch')
280
        new_branch = branch.Branch.open('new-branch')
281
        # The tag is present, and so is its revision.
282
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
283
        new_branch.repository.get_revision('rev-2')
284
3665.2.5 by John Arbash Meinel
Test that we alert the user to the upgrade.
285
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
286
class TestBranchStacked(TestCaseWithTransport):
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
287
    """Tests for branch --stacked"""
288
3517.4.11 by Martin Pool
Improved blackbox tests for stacked branches
289
    def assertRevisionInRepository(self, repo_path, revid):
290
        """Check that a revision is in a repository, disregarding stacking."""
291
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
292
        self.assertTrue(repo.has_revision(revid))
293
294
    def assertRevisionNotInRepository(self, repo_path, revid):
295
        """Check that a revision is not in a repository, disregarding stacking."""
296
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
297
        self.assertFalse(repo.has_revision(revid))
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
298
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
299
    def assertRevisionsInBranchRepository(self, revid_list, branch_path):
300
        repo = branch.Branch.open(branch_path).repository
301
        self.assertEqual(set(revid_list),
302
            repo.has_revisions(revid_list))
303
304
    def test_branch_stacked_branch_not_stacked(self):
305
        """Branching a stacked branch is not stacked by default"""
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
306
        # We have a mainline
307
        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)
308
            format='1.9')
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
309
        trunk_tree.commit('mainline')
3221.20.3 by Ian Clatworthy
shallow -> stacked
310
        # and a branch from it which is stacked
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
311
        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)
312
            format='1.9')
3537.3.3 by Martin Pool
Rename Branch.set_stacked_on to set_stacked_on_url
313
        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.
314
        # with some work on it
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
315
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
316
        work_tree.commit('moar work plz')
317
        work_tree.branch.push(branch_tree.branch)
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
318
        # branching our local branch gives us a new stacked branch pointing at
319
        # mainline.
320
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
321
        self.assertEqual('', out)
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
322
        self.assertEqual('Branched 2 revision(s).\n',
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
323
            err)
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
324
        # it should have preserved the branch format, and so it should be
325
        # capable of supporting stacking, but not actually have a stacked_on
326
        # branch configured
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
327
        self.assertRaises(errors.NotStacked,
328
            bzrdir.BzrDir.open('newbranch').open_branch().get_stacked_on_url)
329
330
    def test_branch_stacked_branch_stacked(self):
331
        """Asking to stack on a stacked branch does work"""
332
        # We have a mainline
333
        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)
334
            format='1.9')
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
335
        trunk_revid = trunk_tree.commit('mainline')
336
        # and a branch from it which is stacked
337
        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)
338
            format='1.9')
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
339
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
340
        # with some work on it
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
341
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
342
        branch_revid = work_tree.commit('moar work plz')
343
        work_tree.branch.push(branch_tree.branch)
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
344
        # you can chain branches on from there
345
        out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
346
        self.assertEqual('', out)
3221.20.3 by Ian Clatworthy
shallow -> stacked
347
        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
348
            branch_tree.branch.base, err)
349
        self.assertEqual(branch_tree.branch.base,
350
            branch.Branch.open('branch2').get_stacked_on_url())
351
        branch2_tree = WorkingTree.open('branch2')
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
352
        branch2_revid = work_tree.commit('work on second stacked branch')
353
        work_tree.branch.push(branch2_tree.branch)
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
354
        self.assertRevisionInRepository('branch2', branch2_revid)
355
        self.assertRevisionsInBranchRepository(
356
            [trunk_revid, branch_revid, branch2_revid],
357
            'branch2')
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
358
3221.20.3 by Ian Clatworthy
shallow -> stacked
359
    def test_branch_stacked(self):
3221.11.20 by Robert Collins
Support --shallow on branch.
360
        # We have a mainline
361
        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)
362
            format='1.9')
3517.4.11 by Martin Pool
Improved blackbox tests for stacked branches
363
        original_revid = trunk_tree.commit('mainline')
364
        self.assertRevisionInRepository('mainline', original_revid)
3221.20.3 by Ian Clatworthy
shallow -> stacked
365
        # and a branch from it which is stacked
366
        out, err = self.run_bzr(['branch', '--stacked', 'mainline',
3221.20.1 by Ian Clatworthy
tweaks by igc during review
367
            'newbranch'])
3221.11.20 by Robert Collins
Support --shallow on branch.
368
        self.assertEqual('', out)
3221.20.3 by Ian Clatworthy
shallow -> stacked
369
        self.assertEqual('Created new stacked branch referring to %s.\n' %
3221.11.20 by Robert Collins
Support --shallow on branch.
370
            trunk_tree.branch.base, err)
3517.4.11 by Martin Pool
Improved blackbox tests for stacked branches
371
        self.assertRevisionNotInRepository('newbranch', original_revid)
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
372
        new_branch = branch.Branch.open('newbranch')
373
        self.assertEqual(trunk_tree.branch.base, new_branch.get_stacked_on_url())
3221.11.20 by Robert Collins
Support --shallow on branch.
374
3221.15.10 by Robert Collins
Add test that we can stack on a smart server from Jonathan Lange.
375
    def test_branch_stacked_from_smart_server(self):
376
        # We can branch stacking on a smart server
5017.3.40 by Vincent Ladeuil
-s bb.test_branch passing
377
        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)
378
        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.
379
        out, err = self.run_bzr(
380
            ['branch', '--stacked', self.get_url('mainline'), 'shallow'])
381
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
382
    def test_branch_stacked_from_non_stacked_format(self):
383
        """The origin format doesn't support stacking"""
384
        trunk = self.make_branch('trunk', format='pack-0.92')
385
        out, err = self.run_bzr(
386
            ['branch', '--stacked', 'trunk', 'shallow'])
3665.2.5 by John Arbash Meinel
Test that we alert the user to the upgrade.
387
        # 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.
388
        self.assertEqualDiff(
4401.1.3 by John Arbash Meinel
Change back to defaulting to --1.6 format, and update the blackbox tests.
389
            '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.
390
            '  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.
391
            'Source branch format does not support stacking, using format:\n'
392
            '  Branch format 7\n'
4634.144.6 by Martin Pool
Branching that does an implicit conversion now shows the fetch warning
393
            'Doing on-the-fly conversion from RepositoryFormatKnitPack1() to RepositoryFormatKnitPack5().\n'
394
            '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.
395
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
396
            err)
397
398
    def test_branch_stacked_from_rich_root_non_stackable(self):
399
        trunk = self.make_branch('trunk', format='rich-root-pack')
400
        out, err = self.run_bzr(
401
            ['branch', '--stacked', 'trunk', 'shallow'])
402
        # We should notify the user that we upgraded their format
403
        self.assertEqualDiff(
4401.1.3 by John Arbash Meinel
Change back to defaulting to --1.6 format, and update the blackbox tests.
404
            '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.
405
            '  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.
406
            'Source branch format does not support stacking, using format:\n'
407
            '  Branch format 7\n'
4634.144.6 by Martin Pool
Branching that does an implicit conversion now shows the fetch warning
408
            'Doing on-the-fly conversion from RepositoryFormatKnitPack4() to RepositoryFormatKnitPack5RichRoot().\n'
409
            '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.
410
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
411
            err)
412
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
413
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
414
class TestSmartServerBranching(TestCaseWithTransport):
4060.1.1 by Robert Collins
Add ratcheted acceptance test for branching from a smart server.
415
4060.1.4 by Robert Collins
Streaming fetch from remote servers.
416
    def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
417
        self.setup_smart_server_with_call_log()
418
        t = self.make_branch_and_tree('from')
419
        for count in range(9):
420
            t.commit(message='commit %d' % count)
421
        self.reset_smart_call_log()
422
        out, err = self.run_bzr(['branch', self.get_url('from'),
423
            self.get_url('target')])
424
        # This figure represent the amount of work to perform this use case. It
425
        # is entirely ok to reduce this number if a test fails due to rpc_count
426
        # being too low. If rpc_count increases, more network roundtrips have
427
        # become necessary for this use case. Please do not adjust this number
428
        # 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.
429
        self.assertLength(36, self.hpss_calls)
4060.1.4 by Robert Collins
Streaming fetch from remote servers.
430
4060.1.1 by Robert Collins
Add ratcheted acceptance test for branching from a smart server.
431
    def test_branch_from_trivial_branch_streaming_acceptance(self):
432
        self.setup_smart_server_with_call_log()
433
        t = self.make_branch_and_tree('from')
434
        for count in range(9):
435
            t.commit(message='commit %d' % count)
436
        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.
437
        out, err = self.run_bzr(['branch', self.get_url('from'),
438
            'local-target'])
4060.1.1 by Robert Collins
Add ratcheted acceptance test for branching from a smart server.
439
        # This figure represent the amount of work to perform this use case. It
440
        # is entirely ok to reduce this number if a test fails due to rpc_count
441
        # being too low. If rpc_count increases, more network roundtrips have
442
        # become necessary for this use case. Please do not adjust this number
443
        # upwards without agreement from bzr's network support maintainers.
5535.2.1 by Andrew Bennetts
Cache a branch's tags during a read-lock.
444
        self.assertLength(9, self.hpss_calls)
4060.1.1 by Robert Collins
Add ratcheted acceptance test for branching from a smart server.
445
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
446
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
447
        self.setup_smart_server_with_call_log()
448
        t = self.make_branch_and_tree('trunk')
449
        for count in range(8):
450
            t.commit(message='commit %d' % count)
451
        tree2 = t.branch.bzrdir.sprout('feature', stacked=True
452
            ).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.
453
        local_tree = t.branch.bzrdir.sprout('local-working').open_workingtree()
454
        local_tree.commit('feature change')
455
        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.
456
        self.reset_smart_call_log()
457
        out, err = self.run_bzr(['branch', self.get_url('feature'),
458
            'local-target'])
459
        # This figure represent the amount of work to perform this use case. It
460
        # is entirely ok to reduce this number if a test fails due to rpc_count
461
        # being too low. If rpc_count increases, more network roundtrips have
462
        # become necessary for this use case. Please do not adjust this number
463
        # upwards without agreement from bzr's network support maintainers.
5535.2.1 by Andrew Bennetts
Cache a branch's tags during a read-lock.
464
        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.
465
5535.4.7 by Andrew Bennetts
Add HPSS acceptance test.
466
    def test_branch_from_branch_with_tags(self):
467
        self.setup_smart_server_with_call_log()
468
        builder = self.make_branch_builder('source')
469
        builder.build_commit(message="Rev 1", rev_id='rev-1')
470
        builder.build_commit(message="Rev 2", rev_id='rev-2')
471
        source = builder.get_branch()
472
        source.tags.set_tag('tag-a', 'rev-2')
473
        source.tags.set_tag('tag-missing', 'missing-rev')
474
        source.set_last_revision_info(1, 'rev-1')
475
        # Now source has a tag not in its ancestry.  Make a branch from it.
476
        self.reset_smart_call_log()
477
        out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
478
        # This figure represent the amount of work to perform this use case. It
479
        # is entirely ok to reduce this number if a test fails due to rpc_count
480
        # being too low. If rpc_count increases, more network roundtrips have
481
        # become necessary for this use case. Please do not adjust this number
482
        # upwards without agreement from bzr's network support maintainers.
483
        self.assertLength(9, self.hpss_calls)
484
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
485
2485.8.59 by Vincent Ladeuil
Update from review comments.
486
class TestRemoteBranch(TestCaseWithSFTPServer):
487
488
    def setUp(self):
489
        super(TestRemoteBranch, self).setUp()
490
        tree = self.make_branch_and_tree('branch')
491
        self.build_tree_contents([('branch/file', 'file content\n')])
492
        tree.add('file')
493
        tree.commit('file created')
494
495
    def test_branch_local_remote(self):
496
        self.run_bzr(['branch', 'branch', self.get_url('remote')])
497
        t = self.get_transport()
2485.8.62 by Vincent Ladeuil
From review comments, fix typos and deprecate some functions.
498
        # Ensure that no working tree what created remotely
2485.8.59 by Vincent Ladeuil
Update from review comments.
499
        self.assertFalse(t.has('remote/file'))
500
501
    def test_branch_remote_remote(self):
502
        # Light cheat: we access the branch remotely
503
        self.run_bzr(['branch', self.get_url('branch'),
504
                      self.get_url('remote')])
505
        t = self.get_transport()
2485.8.62 by Vincent Ladeuil
From review comments, fix typos and deprecate some functions.
506
        # Ensure that no working tree what created remotely
2485.8.59 by Vincent Ladeuil
Update from review comments.
507
        self.assertFalse(t.has('remote/file'))
508