/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2006-2012, 2016 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
6622.1.29 by Jelmer Vernooij
Fix some more tests.
18
"""Black-box tests for brz branch."""
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
19
20
import os
21
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
22
from breezy import (
4596.2.3 by Lukáš Lalinský
Add tests for various situations
23
    branch,
24
    bzrdir,
6207.3.3 by jelmer at samba
Fix tests and the like.
25
    controldir,
4596.2.3 by Lukáš Lalinský
Add tests for various situations
26
    errors,
27
    revision as _mod_revision,
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
28
    tests,
4596.2.3 by Lukáš Lalinský
Add tests for various situations
29
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
30
from breezy.repofmt.knitrepo import RepositoryFormatKnit1
31
from breezy.tests import (
5651.5.3 by Andrew Bennetts
Use new fixture in more tests.
32
    fixtures,
5017.3.40 by Vincent Ladeuil
-s bb.test_branch passing
33
    test_server,
4580.4.2 by Martin Pool
Add KnownFailure for branch --hardlink
34
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
35
from breezy.tests.features import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
36
    HardlinkFeature,
37
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
38
from breezy.tests.blackbox import test_switch
39
from breezy.tests.matchers import ContainsNoVfsCalls
40
from breezy.tests.test_sftp_transport import TestCaseWithSFTPServer
41
from breezy.tests.script import run_script
42
from breezy.urlutils import local_path_to_url, strip_trailing_slash
43
from breezy.workingtree import WorkingTree
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
44
45
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
46
class TestBranch(tests.TestCaseWithTransport):
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
47
6240.3.1 by Jelmer Vernooij
Name new branches after colocated branches.
48
    def example_branch(self, path='.', format=None):
49
        tree = self.make_branch_and_tree(path, format=format)
2664.8.2 by Daniel Watkins
tests.blackbox.test_branch now uses internals where appropriate.
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')
6240.3.1 by Jelmer Vernooij
Name new branches after colocated branches.
56
        return tree
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
57
58
    def test_branch(self):
59
        """Branch from one branch to another."""
2664.8.2 by Daniel Watkins
tests.blackbox.test_branch now uses internals where appropriate.
60
        self.example_branch('a')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
61
        self.run_bzr('branch a b')
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
62
        b = branch.Branch.open('b')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
63
        self.run_bzr('branch a c -r 1')
3400.1.3 by Martin Pool
Merge trunk
64
        # previously was erroneously created by branching
3407.2.14 by Martin Pool
Remove more cases of getting transport via control_files
65
        self.assertFalse(b._transport.has('branch-name'))
2664.8.2 by Daniel Watkins
tests.blackbox.test_branch now uses internals where appropriate.
66
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
67
6437.15.1 by Jelmer Vernooij
Fix target branch locations.
68
    def test_branch_no_to_location(self):
69
        """The to_location is derived from the source branch name."""
70
        os.mkdir("something")
71
        a = self.example_branch('something/a').branch
72
        self.run_bzr('branch something/a')
73
        b = branch.Branch.open('a')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
74
        self.assertEqual(b.last_revision_info(), a.last_revision_info())
6437.15.1 by Jelmer Vernooij
Fix target branch locations.
75
6207.2.1 by jelmer at samba
Fix cloning to colocated branch.
76
    def test_into_colocated(self):
77
        """Branch from a branch into a colocated branch."""
78
        self.example_branch('a')
79
        out, err = self.run_bzr(
80
            'init --format=development-colo file:b,branch=orig')
81
        self.assertEqual(
6240.2.12 by Jelmer Vernooij
Fix foreign tests.
82
            """Created a lightweight checkout (format: development-colo)\n""",
6207.2.1 by jelmer at samba
Fix cloning to colocated branch.
83
            out)
84
        self.assertEqual('', err)
85
        out, err = self.run_bzr(
6266.1.1 by Jelmer Vernooij
Support branching into colocated branch.
86
            'branch a file:b,branch=thiswasa')
6207.2.1 by jelmer at samba
Fix cloning to colocated branch.
87
        self.assertEqual('', out)
88
        self.assertEqual('Branched 2 revisions.\n', err)
89
        out, err = self.run_bzr('branches b')
6379.10.3 by Jelmer Vernooij
Only display active branch if it's not one of the existing colocated branches.
90
        self.assertEqual("  orig\n  thiswasa\n", out)
6207.2.1 by jelmer at samba
Fix cloning to colocated branch.
91
        self.assertEqual('', err)
6266.1.1 by Jelmer Vernooij
Support branching into colocated branch.
92
        out,err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
93
        self.assertEqual('', out)
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
94
        self.assertEqual(
6622.1.29 by Jelmer Vernooij
Fix some more tests.
95
            'brz: ERROR: Already a branch: "file:b,branch=orig".\n', err)
6207.2.1 by jelmer at samba
Fix cloning to colocated branch.
96
6240.3.1 by Jelmer Vernooij
Name new branches after colocated branches.
97
    def test_from_colocated(self):
98
        """Branch from a colocated branch into a regular branch."""
99
        tree = self.example_branch('a', format='development-colo')
100
        tree.bzrdir.create_branch(name='somecolo')
101
        out, err = self.run_bzr('branch %s,branch=somecolo' %
102
            local_path_to_url('a'))
103
        self.assertEqual('', out)
104
        self.assertEqual('Branched 0 revisions.\n', err)
105
        self.assertPathExists("somecolo")
106
5927.2.1 by Jonathan Riddell
start a test case for corrupt pack files
107
    def test_branch_broken_pack(self):
108
        """branching with a corrupted pack file."""
109
        self.example_branch('a')
6158.1.1 by Vincent Ladeuil
Fix random test failure by making the test not random
110
        # add some corruption
111
        packs_dir = 'a/.bzr/repository/packs/'
112
        fname = packs_dir + os.listdir(packs_dir)[0]
5927.2.8 by Jonathan Riddell
tidy up file opening in test
113
        with open(fname, 'rb+') as f:
6158.1.1 by Vincent Ladeuil
Fix random test failure by making the test not random
114
            # Start from the end of the file to avoid choosing a place bigger
115
            # than the file itself.
116
            f.seek(-5, os.SEEK_END)
117
            c = f.read(1)
118
            f.seek(-5, os.SEEK_END)
119
            # Make sure we inject a value different than the one we just read
120
            if c == '\xFF':
121
                corrupt = '\x00'
122
            else:
123
                corrupt = '\xFF'
124
            f.write(corrupt) # make sure we corrupt something
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
125
        self.run_bzr_error(['Corruption while decompressing repository file'],
5927.2.6 by Jonathan Riddell
Make error message less specific (might not be a local disk issue) and pass through zlib error
126
                            'branch a b', retcode=3)
5927.2.1 by Jonathan Riddell
start a test case for corrupt pack files
127
4596.2.3 by Lukáš Lalinský
Add tests for various situations
128
    def test_branch_switch_no_branch(self):
129
        # No branch in the current directory:
130
        #  => new branch will be created, but switch fails
131
        self.example_branch('a')
132
        self.make_repository('current')
133
        self.run_bzr_error(['No WorkingTree exists for'],
134
            'branch --switch ../a ../b', working_dir='current')
135
        a = branch.Branch.open('a')
136
        b = branch.Branch.open('b')
137
        self.assertEqual(a.last_revision(), b.last_revision())
138
139
    def test_branch_switch_no_wt(self):
140
        # No working tree in the current directory:
141
        #  => new branch will be created, but switch fails and the current
142
        #     branch is unmodified
143
        self.example_branch('a')
144
        self.make_branch('current')
145
        self.run_bzr_error(['No WorkingTree exists for'],
146
            'branch --switch ../a ../b', working_dir='current')
147
        a = branch.Branch.open('a')
148
        b = branch.Branch.open('b')
149
        self.assertEqual(a.last_revision(), b.last_revision())
150
        work = branch.Branch.open('current')
151
        self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
152
4596.2.1 by Lukáš Lalinský
Add support for `bzr branch --switch`
153
    def test_branch_switch_no_checkout(self):
4596.2.3 by Lukáš Lalinský
Add tests for various situations
154
        # Standalone branch in the current directory:
155
        #  => new branch will be created, but switch fails and the current
156
        #     branch is unmodified
4596.2.1 by Lukáš Lalinský
Add support for `bzr branch --switch`
157
        self.example_branch('a')
6437.21.7 by Jelmer Vernooij
Fix remaining tests.
158
        tree = self.make_branch_and_tree('current')
159
        c1 = tree.commit('some diverged change')
4596.2.1 by Lukáš Lalinský
Add support for `bzr branch --switch`
160
        self.run_bzr_error(['Cannot switch a branch, only a checkout'],
4596.2.3 by Lukáš Lalinský
Add tests for various situations
161
            'branch --switch ../a ../b', working_dir='current')
162
        a = branch.Branch.open('a')
163
        b = branch.Branch.open('b')
164
        self.assertEqual(a.last_revision(), b.last_revision())
165
        work = branch.Branch.open('current')
6437.21.7 by Jelmer Vernooij
Fix remaining tests.
166
        self.assertEqual(work.last_revision(), c1)
4596.2.3 by Lukáš Lalinský
Add tests for various situations
167
6379.13.1 by Jelmer Vernooij
Fix branching into empty control directories.
168
    def test_branch_into_empty_dir(self):
169
        t = self.example_branch('source')
170
        self.make_bzrdir('target')
171
        self.run_bzr("branch source target")
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
172
        self.assertEqual(2, len(t.branch.repository.all_revision_ids()))
6379.13.1 by Jelmer Vernooij
Fix branching into empty control directories.
173
4596.2.3 by Lukáš Lalinský
Add tests for various situations
174
    def test_branch_switch_checkout(self):
175
        # Checkout in the current directory:
176
        #  => new branch will be created and checkout bound to the new branch
177
        self.example_branch('a')
178
        self.run_bzr('checkout a current')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
179
        out, err = self.run_bzr('branch --switch ../a ../b',
180
                                working_dir='current')
4596.2.3 by Lukáš Lalinský
Add tests for various situations
181
        a = branch.Branch.open('a')
182
        b = branch.Branch.open('b')
183
        self.assertEqual(a.last_revision(), b.last_revision())
184
        work = WorkingTree.open('current')
185
        self.assertEndsWith(work.branch.get_bound_location(), '/b/')
186
        self.assertContainsRe(err, "Switched to branch: .*/b/")
187
188
    def test_branch_switch_lightweight_checkout(self):
189
        # Lightweight checkout in the current directory:
190
        #  => new branch will be created and lightweight checkout pointed to
191
        #     the new branch
192
        self.example_branch('a')
193
        self.run_bzr('checkout --lightweight a current')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
194
        out, err = self.run_bzr('branch --switch ../a ../b',
195
                                working_dir='current')
4596.2.3 by Lukáš Lalinský
Add tests for various situations
196
        a = branch.Branch.open('a')
197
        b = branch.Branch.open('b')
198
        self.assertEqual(a.last_revision(), b.last_revision())
199
        work = WorkingTree.open('current')
200
        self.assertEndsWith(work.branch.base, '/b/')
4596.2.1 by Lukáš Lalinský
Add support for `bzr branch --switch`
201
        self.assertContainsRe(err, "Switched to branch: .*/b/")
202
1711.2.6 by John Arbash Meinel
Creating a test case for bug 43713, bzr branch does the right thing
203
    def test_branch_only_copies_history(self):
204
        # Knit branches should only push the history for the current revision.
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
205
        format = bzrdir.BzrDirMetaFormat1()
1711.2.6 by John Arbash Meinel
Creating a test case for bug 43713, bzr branch does the right thing
206
        format.repository_format = RepositoryFormatKnit1()
207
        shared_repo = self.make_repository('repo', format=format, shared=True)
208
        shared_repo.set_make_working_trees(True)
209
210
        def make_shared_tree(path):
211
            shared_repo.bzrdir.root_transport.mkdir(path)
6207.3.3 by jelmer at samba
Fix tests and the like.
212
            controldir.ControlDir.create_branch_convenience('repo/' + path)
1711.2.6 by John Arbash Meinel
Creating a test case for bug 43713, bzr branch does the right thing
213
            return WorkingTree.open('repo/' + path)
214
        tree_a = make_shared_tree('a')
215
        self.build_tree(['repo/a/file'])
216
        tree_a.add('file')
217
        tree_a.commit('commit a-1', rev_id='a-1')
218
        f = open('repo/a/file', 'ab')
219
        f.write('more stuff\n')
220
        f.close()
221
        tree_a.commit('commit a-2', rev_id='a-2')
222
223
        tree_b = make_shared_tree('b')
224
        self.build_tree(['repo/b/file'])
225
        tree_b.add('file')
226
        tree_b.commit('commit b-1', rev_id='b-1')
227
228
        self.assertTrue(shared_repo.has_revision('a-1'))
229
        self.assertTrue(shared_repo.has_revision('a-2'))
230
        self.assertTrue(shared_repo.has_revision('b-1'))
231
232
        # Now that we have a repository with shared files, make sure
233
        # that things aren't copied out by a 'branch'
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
234
        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
235
        pushed_tree = WorkingTree.open('branch-b')
236
        pushed_repo = pushed_tree.branch.repository
237
        self.assertFalse(pushed_repo.has_revision('a-1'))
238
        self.assertFalse(pushed_repo.has_revision('a-2'))
239
        self.assertTrue(pushed_repo.has_revision('b-1'))
240
3136.1.3 by Aaron Bentley
Implement hard-link support for branch and checkout
241
    def test_branch_hardlink(self):
242
        self.requireFeature(HardlinkFeature)
243
        source = self.make_branch_and_tree('source')
244
        self.build_tree(['source/file1'])
245
        source.add('file1')
246
        source.commit('added file')
4580.4.2 by Martin Pool
Add KnownFailure for branch --hardlink
247
        out, err = self.run_bzr(['branch', 'source', 'target', '--hardlink'])
3136.1.3 by Aaron Bentley
Implement hard-link support for branch and checkout
248
        source_stat = os.stat('source/file1')
249
        target_stat = os.stat('target/file1')
4826.1.3 by Andrew Bennetts
Remove KnownFailure from test_branch_hardlink.
250
        self.assertEqual(source_stat, target_stat)
3136.1.3 by Aaron Bentley
Implement hard-link support for branch and checkout
251
5353.2.2 by John Arbash Meinel
update the test suite.
252
    def test_branch_files_from(self):
253
        source = self.make_branch_and_tree('source')
254
        self.build_tree(['source/file1'])
255
        source.add('file1')
256
        source.commit('added file')
257
        out, err = self.run_bzr('branch source target --files-from source')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
258
        self.assertPathExists('target/file1')
5353.2.2 by John Arbash Meinel
update the test suite.
259
260
    def test_branch_files_from_hardlink(self):
261
        self.requireFeature(HardlinkFeature)
262
        source = self.make_branch_and_tree('source')
263
        self.build_tree(['source/file1'])
264
        source.add('file1')
265
        source.commit('added file')
266
        source.bzrdir.sprout('second')
267
        out, err = self.run_bzr('branch source target --files-from second'
268
                                ' --hardlink')
269
        source_stat = os.stat('source/file1')
270
        second_stat = os.stat('second/file1')
271
        target_stat = os.stat('target/file1')
272
        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.
273
        self.assertEqual(second_stat, target_stat)
5353.2.2 by John Arbash Meinel
update the test suite.
274
3696.2.1 by Daniel Watkins
Added test for 'branch --standalone'.
275
    def test_branch_standalone(self):
276
        shared_repo = self.make_repository('repo', shared=True)
277
        self.example_branch('source')
278
        self.run_bzr('branch --standalone source repo/target')
279
        b = branch.Branch.open('repo/target')
280
        expected_repo_path = os.path.abspath('repo/target/.bzr/repository')
3696.2.4 by Daniel Watkins
Fixed test to cope with trailing slashes.
281
        self.assertEqual(strip_trailing_slash(b.repository.base),
282
            strip_trailing_slash(local_path_to_url(expected_repo_path)))
3696.2.1 by Daniel Watkins
Added test for 'branch --standalone'.
283
3983.1.5 by Daniel Watkins
Added blackbox test.
284
    def test_branch_no_tree(self):
285
        self.example_branch('source')
286
        self.run_bzr('branch --no-tree source target')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
287
        self.assertPathDoesNotExist('target/hello')
288
        self.assertPathDoesNotExist('target/goodbye')
3983.1.5 by Daniel Watkins
Added blackbox test.
289
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.
290
    def test_branch_into_existing_dir(self):
291
        self.example_branch('a')
6622.1.29 by Jelmer Vernooij
Fix some more tests.
292
        # existing dir with similar files but no .brz dir
4479.2.2 by Vincent Ladeuil
Fix typos and add NEWS entry.
293
        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.
294
        self.build_tree_contents([('b/hello', 'bar')])  # different content
4479.2.2 by Vincent Ladeuil
Fix typos and add NEWS entry.
295
        self.build_tree_contents([('b/goodbye', 'baz')])# same content
296
        # 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.
297
        out,err = self.run_bzr('branch a b', retcode=3)
298
        self.assertEqual('', out)
6622.1.29 by Jelmer Vernooij
Fix some more tests.
299
        self.assertEqual('brz: ERROR: Target directory "b" already exists.\n',
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.
300
            err)
301
        # force operation
302
        self.run_bzr('branch a b --use-existing-dir')
303
        # check conflicts
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
304
        self.assertPathExists('b/hello.moved')
305
        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.
306
        # we can't branch into branch
307
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
308
        self.assertEqual('', out)
6622.1.29 by Jelmer Vernooij
Fix some more tests.
309
        self.assertEqual('brz: ERROR: Already a branch: "b".\n', err)
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.
310
4927.3.1 by Ian Clatworthy
branch --bind option
311
    def test_branch_bind(self):
312
        self.example_branch('a')
313
        out, err = self.run_bzr('branch a b --bind')
4948.3.1 by Ian Clatworthy
branch --bind option
314
        self.assertEndsWith(err, "New branch bound to a\n")
4927.3.1 by Ian Clatworthy
branch --bind option
315
        b = branch.Branch.open('b')
316
        self.assertEndsWith(b.get_bound_location(), '/a/')
317
5107.3.6 by Marco Pantaleoni
Documented behaviour of 'post_branch_init' for lightweight checkouts.
318
    def test_branch_with_post_branch_init_hook(self):
319
        calls = []
320
        branch.Branch.hooks.install_named_hook('post_branch_init',
321
            calls.append, None)
322
        self.assertLength(0, calls)
323
        self.example_branch('a')
324
        self.assertLength(1, calls)
325
        self.run_bzr('branch a b')
326
        self.assertLength(2, calls)
327
328
    def test_checkout_with_post_branch_init_hook(self):
329
        calls = []
330
        branch.Branch.hooks.install_named_hook('post_branch_init',
331
            calls.append, None)
332
        self.assertLength(0, calls)
333
        self.example_branch('a')
334
        self.assertLength(1, calls)
335
        self.run_bzr('checkout a b')
336
        self.assertLength(2, calls)
337
338
    def test_lightweight_checkout_with_post_branch_init_hook(self):
339
        calls = []
340
        branch.Branch.hooks.install_named_hook('post_branch_init',
341
            calls.append, None)
342
        self.assertLength(0, calls)
343
        self.example_branch('a')
344
        self.assertLength(1, calls)
345
        self.run_bzr('checkout --lightweight a b')
346
        self.assertLength(2, calls)
347
5535.3.1 by Andrew Bennetts
Initial hack to make 'bzr branch' (and BzrDir.sprout) fetch all tags, not just branch tip.
348
    def test_branch_fetches_all_tags(self):
349
        builder = self.make_branch_builder('source')
5651.5.3 by Andrew Bennetts
Use new fixture in more tests.
350
        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.
351
        source.tags.set_tag('tag-a', 'rev-2')
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
352
        source.get_config_stack().set('branch.fetch_tags', True)
5535.3.1 by Andrew Bennetts
Initial hack to make 'bzr branch' (and BzrDir.sprout) fetch all tags, not just branch tip.
353
        # Now source has a tag not in its ancestry.  Make a branch from it.
354
        self.run_bzr('branch source new-branch')
355
        new_branch = branch.Branch.open('new-branch')
356
        # The tag is present, and so is its revision.
357
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
358
        new_branch.repository.get_revision('rev-2')
359
3665.2.5 by John Arbash Meinel
Test that we alert the user to the upgrade.
360
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
361
class TestBranchStacked(tests.TestCaseWithTransport):
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
362
    """Tests for branch --stacked"""
363
3517.4.11 by Martin Pool
Improved blackbox tests for stacked branches
364
    def assertRevisionInRepository(self, repo_path, revid):
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
365
        """Check that a revision is in a repo, disregarding stacking."""
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
366
        repo = controldir.ControlDir.open(repo_path).open_repository()
3517.4.11 by Martin Pool
Improved blackbox tests for stacked branches
367
        self.assertTrue(repo.has_revision(revid))
368
369
    def assertRevisionNotInRepository(self, repo_path, revid):
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
370
        """Check that a revision is not in a repo, disregarding stacking."""
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
371
        repo = controldir.ControlDir.open(repo_path).open_repository()
3517.4.11 by Martin Pool
Improved blackbox tests for stacked branches
372
        self.assertFalse(repo.has_revision(revid))
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
373
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
374
    def assertRevisionsInBranchRepository(self, revid_list, branch_path):
375
        repo = branch.Branch.open(branch_path).repository
376
        self.assertEqual(set(revid_list),
377
            repo.has_revisions(revid_list))
378
379
    def test_branch_stacked_branch_not_stacked(self):
380
        """Branching a stacked branch is not stacked by default"""
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
381
        # We have a mainline
382
        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)
383
            format='1.9')
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
384
        trunk_tree.commit('mainline')
3221.20.3 by Ian Clatworthy
shallow -> stacked
385
        # and a branch from it which is stacked
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
386
        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)
387
            format='1.9')
3537.3.3 by Martin Pool
Rename Branch.set_stacked_on to set_stacked_on_url
388
        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.
389
        # with some work on it
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
390
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
391
        work_tree.commit('moar work plz')
392
        work_tree.branch.push(branch_tree.branch)
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
393
        # branching our local branch gives us a new stacked branch pointing at
394
        # mainline.
395
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
396
        self.assertEqual('', out)
6143.1.4 by Jonathan Riddell
update tests
397
        self.assertEqual('Branched 2 revisions.\n',
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
398
            err)
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
399
        # it should have preserved the branch format, and so it should be
400
        # capable of supporting stacking, but not actually have a stacked_on
401
        # branch configured
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
402
        self.assertRaises(errors.NotStacked,
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
403
            controldir.ControlDir.open('newbranch').open_branch().get_stacked_on_url)
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
404
405
    def test_branch_stacked_branch_stacked(self):
406
        """Asking to stack on a stacked branch does work"""
407
        # We have a mainline
408
        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)
409
            format='1.9')
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
410
        trunk_revid = trunk_tree.commit('mainline')
411
        # and a branch from it which is stacked
412
        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)
413
            format='1.9')
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
414
        branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
415
        # with some work on it
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
416
        work_tree = trunk_tree.branch.bzrdir.sprout('local').open_workingtree()
417
        branch_revid = work_tree.commit('moar work plz')
418
        work_tree.branch.push(branch_tree.branch)
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
419
        # you can chain branches on from there
420
        out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
421
        self.assertEqual('', out)
3221.20.3 by Ian Clatworthy
shallow -> stacked
422
        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
423
            branch_tree.branch.base, err)
424
        self.assertEqual(branch_tree.branch.base,
425
            branch.Branch.open('branch2').get_stacked_on_url())
426
        branch2_tree = WorkingTree.open('branch2')
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
427
        branch2_revid = work_tree.commit('work on second stacked branch')
428
        work_tree.branch.push(branch2_tree.branch)
3549.1.4 by Martin Pool
Branching a stacked branch should not automatically turn on stacking
429
        self.assertRevisionInRepository('branch2', branch2_revid)
430
        self.assertRevisionsInBranchRepository(
431
            [trunk_revid, branch_revid, branch2_revid],
432
            'branch2')
3221.11.19 by Robert Collins
Branching a shallow branch gets a shallow branch.
433
3221.20.3 by Ian Clatworthy
shallow -> stacked
434
    def test_branch_stacked(self):
3221.11.20 by Robert Collins
Support --shallow on branch.
435
        # We have a mainline
436
        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)
437
            format='1.9')
3517.4.11 by Martin Pool
Improved blackbox tests for stacked branches
438
        original_revid = trunk_tree.commit('mainline')
439
        self.assertRevisionInRepository('mainline', original_revid)
3221.20.3 by Ian Clatworthy
shallow -> stacked
440
        # and a branch from it which is stacked
441
        out, err = self.run_bzr(['branch', '--stacked', 'mainline',
3221.20.1 by Ian Clatworthy
tweaks by igc during review
442
            'newbranch'])
3221.11.20 by Robert Collins
Support --shallow on branch.
443
        self.assertEqual('', out)
3221.20.3 by Ian Clatworthy
shallow -> stacked
444
        self.assertEqual('Created new stacked branch referring to %s.\n' %
3221.11.20 by Robert Collins
Support --shallow on branch.
445
            trunk_tree.branch.base, err)
3517.4.11 by Martin Pool
Improved blackbox tests for stacked branches
446
        self.assertRevisionNotInRepository('newbranch', original_revid)
4595.4.4 by Robert Collins
Disable committing directly to stacked branches from lightweight checkouts.
447
        new_branch = branch.Branch.open('newbranch')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
448
        self.assertEqual(trunk_tree.branch.base,
449
                         new_branch.get_stacked_on_url())
3221.11.20 by Robert Collins
Support --shallow on branch.
450
3221.15.10 by Robert Collins
Add test that we can stack on a smart server from Jonathan Lange.
451
    def test_branch_stacked_from_smart_server(self):
452
        # We can branch stacking on a smart server
5017.3.40 by Vincent Ladeuil
-s bb.test_branch passing
453
        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)
454
        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.
455
        out, err = self.run_bzr(
456
            ['branch', '--stacked', self.get_url('mainline'), 'shallow'])
457
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
458
    def test_branch_stacked_from_non_stacked_format(self):
459
        """The origin format doesn't support stacking"""
460
        trunk = self.make_branch('trunk', format='pack-0.92')
461
        out, err = self.run_bzr(
462
            ['branch', '--stacked', 'trunk', 'shallow'])
3665.2.5 by John Arbash Meinel
Test that we alert the user to the upgrade.
463
        # 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.
464
        self.assertEqualDiff(
4401.1.3 by John Arbash Meinel
Change back to defaulting to --1.6 format, and update the blackbox tests.
465
            'Source repository format does not support stacking, using format:\n'
6622.1.30 by Jelmer Vernooij
Some more test fixes.
466
            '  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.
467
            'Source branch format does not support stacking, using format:\n'
468
            '  Branch format 7\n'
4634.144.6 by Martin Pool
Branching that does an implicit conversion now shows the fetch warning
469
            'Doing on-the-fly conversion from RepositoryFormatKnitPack1() to RepositoryFormatKnitPack5().\n'
470
            '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.
471
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
472
            err)
473
474
    def test_branch_stacked_from_rich_root_non_stackable(self):
475
        trunk = self.make_branch('trunk', format='rich-root-pack')
476
        out, err = self.run_bzr(
477
            ['branch', '--stacked', 'trunk', 'shallow'])
478
        # We should notify the user that we upgraded their format
479
        self.assertEqualDiff(
4401.1.3 by John Arbash Meinel
Change back to defaulting to --1.6 format, and update the blackbox tests.
480
            'Source repository format does not support stacking, using format:\n'
6622.1.30 by Jelmer Vernooij
Some more test fixes.
481
            '  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.
482
            'Source branch format does not support stacking, using format:\n'
483
            '  Branch format 7\n'
4634.144.6 by Martin Pool
Branching that does an implicit conversion now shows the fetch warning
484
            'Doing on-the-fly conversion from RepositoryFormatKnitPack4() to RepositoryFormatKnitPack5RichRoot().\n'
485
            '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.
486
            'Created new stacked branch referring to %s.\n' % (trunk.base,),
487
            err)
488
3575.2.2 by Martin Pool
branch --stacked should force a stacked format
489
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
490
class TestSmartServerBranching(tests.TestCaseWithTransport):
4060.1.1 by Robert Collins
Add ratcheted acceptance test for branching from a smart server.
491
4060.1.4 by Robert Collins
Streaming fetch from remote servers.
492
    def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
493
        self.setup_smart_server_with_call_log()
494
        t = self.make_branch_and_tree('from')
495
        for count in range(9):
496
            t.commit(message='commit %d' % count)
497
        self.reset_smart_call_log()
498
        out, err = self.run_bzr(['branch', self.get_url('from'),
499
            self.get_url('target')])
500
        # This figure represent the amount of work to perform this use case. It
501
        # is entirely ok to reduce this number if a test fails due to rpc_count
502
        # being too low. If rpc_count increases, more network roundtrips have
503
        # become necessary for this use case. Please do not adjust this number
504
        # upwards without agreement from bzr's network support maintainers.
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
505
        self.assertLength(2, self.hpss_connections)
6282.6.11 by Jelmer Vernooij
Adjust some call counts.
506
        self.assertLength(33, self.hpss_calls)
6352.2.2 by Jelmer Vernooij
Use new NoVfsCalls matcher in blackbox tests.
507
        self.expectFailure("branching to the same branch requires VFS access",
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
508
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
4060.1.4 by Robert Collins
Streaming fetch from remote servers.
509
4060.1.1 by Robert Collins
Add ratcheted acceptance test for branching from a smart server.
510
    def test_branch_from_trivial_branch_streaming_acceptance(self):
511
        self.setup_smart_server_with_call_log()
512
        t = self.make_branch_and_tree('from')
513
        for count in range(9):
514
            t.commit(message='commit %d' % count)
515
        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.
516
        out, err = self.run_bzr(['branch', self.get_url('from'),
517
            'local-target'])
4060.1.1 by Robert Collins
Add ratcheted acceptance test for branching from a smart server.
518
        # This figure represent the amount of work to perform this use case. It
519
        # is entirely ok to reduce this number if a test fails due to rpc_count
520
        # being too low. If rpc_count increases, more network roundtrips have
521
        # become necessary for this use case. Please do not adjust this number
522
        # upwards without agreement from bzr's network support maintainers.
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
523
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
6015.15.3 by John Arbash Meinel
More cases that show the extra RPC
524
        self.assertLength(10, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
525
        self.assertLength(1, self.hpss_connections)
4060.1.1 by Robert Collins
Add ratcheted acceptance test for branching from a smart server.
526
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
527
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
528
        self.setup_smart_server_with_call_log()
529
        t = self.make_branch_and_tree('trunk')
530
        for count in range(8):
531
            t.commit(message='commit %d' % count)
532
        tree2 = t.branch.bzrdir.sprout('feature', stacked=True
533
            ).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.
534
        local_tree = t.branch.bzrdir.sprout('local-working').open_workingtree()
535
        local_tree.commit('feature change')
536
        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.
537
        self.reset_smart_call_log()
538
        out, err = self.run_bzr(['branch', self.get_url('feature'),
539
            'local-target'])
540
        # This figure represent the amount of work to perform this use case. It
541
        # is entirely ok to reduce this number if a test fails due to rpc_count
542
        # being too low. If rpc_count increases, more network roundtrips have
543
        # become necessary for this use case. Please do not adjust this number
544
        # upwards without agreement from bzr's network support maintainers.
6015.15.3 by John Arbash Meinel
More cases that show the extra RPC
545
        self.assertLength(15, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
546
        self.assertLength(1, self.hpss_connections)
6282.6.42 by Jelmer Vernooij
merge hpss-get-checkout-format.
547
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
548
5535.4.7 by Andrew Bennetts
Add HPSS acceptance test.
549
    def test_branch_from_branch_with_tags(self):
550
        self.setup_smart_server_with_call_log()
551
        builder = self.make_branch_builder('source')
5651.5.3 by Andrew Bennetts
Use new fixture in more tests.
552
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
6404.1.1 by Vincent Ladeuil
Migrate branch.fetch_tags
553
        source.get_config_stack().set('branch.fetch_tags', True)
5535.4.7 by Andrew Bennetts
Add HPSS acceptance test.
554
        source.tags.set_tag('tag-a', 'rev-2')
555
        source.tags.set_tag('tag-missing', 'missing-rev')
556
        # Now source has a tag not in its ancestry.  Make a branch from it.
557
        self.reset_smart_call_log()
558
        out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
559
        # This figure represent the amount of work to perform this use case. It
560
        # is entirely ok to reduce this number if a test fails due to rpc_count
561
        # being too low. If rpc_count increases, more network roundtrips have
562
        # become necessary for this use case. Please do not adjust this number
563
        # upwards without agreement from bzr's network support maintainers.
6015.15.2 by John Arbash Meinel
This adds one more hpss round trip to determine the configuration setting.
564
        self.assertLength(10, self.hpss_calls)
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
565
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
566
        self.assertLength(1, self.hpss_connections)
5535.4.7 by Andrew Bennetts
Add HPSS acceptance test.
567
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.
568
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
569
        self.setup_smart_server_with_call_log()
570
        t = self.make_branch_and_tree('from')
571
        for count in range(9):
572
            t.commit(message='commit %d' % count)
573
        self.reset_smart_call_log()
574
        out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
575
            'local-target'])
5816.8.6 by Andrew Bennetts
Fix another bug, and some cosmetic nits.
576
        # 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.
577
        # so we can't easily assert about the number of calls.
578
        #self.assertLength(XXX, self.hpss_calls)
579
        # We can assert that none of the calls were readv requests for rix
580
        # files, though (demonstrating that at least get_parent_map calls are
581
        # not using VFS RPCs).
582
        readvs_of_rix_files = [
583
            c for c in self.hpss_calls
584
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
585
        self.assertLength(1, self.hpss_connections)
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.
586
        self.assertLength(0, readvs_of_rix_files)
6352.2.2 by Jelmer Vernooij
Use new NoVfsCalls matcher in blackbox tests.
587
        self.expectFailure("branching to stacked requires VFS access",
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
588
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
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.
589
1711.2.5 by John Arbash Meinel
Factoring blackbox tests into their own file.
590
2485.8.59 by Vincent Ladeuil
Update from review comments.
591
class TestRemoteBranch(TestCaseWithSFTPServer):
592
593
    def setUp(self):
594
        super(TestRemoteBranch, self).setUp()
595
        tree = self.make_branch_and_tree('branch')
596
        self.build_tree_contents([('branch/file', 'file content\n')])
597
        tree.add('file')
598
        tree.commit('file created')
599
600
    def test_branch_local_remote(self):
601
        self.run_bzr(['branch', 'branch', self.get_url('remote')])
602
        t = self.get_transport()
2485.8.62 by Vincent Ladeuil
From review comments, fix typos and deprecate some functions.
603
        # Ensure that no working tree what created remotely
2485.8.59 by Vincent Ladeuil
Update from review comments.
604
        self.assertFalse(t.has('remote/file'))
605
606
    def test_branch_remote_remote(self):
607
        # Light cheat: we access the branch remotely
608
        self.run_bzr(['branch', self.get_url('branch'),
609
                      self.get_url('remote')])
610
        t = self.get_transport()
2485.8.62 by Vincent Ladeuil
From review comments, fix typos and deprecate some functions.
611
        # Ensure that no working tree what created remotely
2485.8.59 by Vincent Ladeuil
Update from review comments.
612
        self.assertFalse(t.has('remote/file'))
613
5741.3.3 by Martin Pool
Add a blackbox test for deprecation of commands
614
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
615
class TestDeprecatedAliases(tests.TestCaseWithTransport):
5741.3.3 by Martin Pool
Add a blackbox test for deprecation of commands
616
617
    def test_deprecated_aliases(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
618
        """brz branch can be called clone or get, but those names are
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
619
        deprecated.
5741.3.3 by Martin Pool
Add a blackbox test for deprecation of commands
620
621
        See bug 506265.
622
        """
623
        for command in ['clone', 'get']:
624
            run_script(self, """
6622.1.29 by Jelmer Vernooij
Fix some more tests.
625
            $ brz %(command)s A B
626
            2>The command 'brz %(command)s' has been deprecated in brz 2.4. Please use 'brz branch' instead.
627
            2>brz: ERROR: Not a branch...
5741.3.3 by Martin Pool
Add a blackbox test for deprecation of commands
628
            """ % 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.
629
630
5816.7.1 by Vincent Ladeuil
Remove duplication and simplify.
631
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
632
633
    def _checkout_and_branch(self, option=''):
634
        self.script_runner.run_script(self, '''
6622.1.29 by Jelmer Vernooij
Fix some more tests.
635
                $ brz checkout %(option)s repo/trunk checkout
5816.7.1 by Vincent Ladeuil
Remove duplication and simplify.
636
                $ cd checkout
6622.1.29 by Jelmer Vernooij
Fix some more tests.
637
                $ brz branch --switch ../repo/trunk ../repo/branched
6143.1.4 by Jonathan Riddell
update tests
638
                2>Branched 0 revisions.
5816.6.8 by A. S. Budden
Refactored to use common generation code for lightweight and heavyweight.
639
                2>Tree is up to date at revision 0.
5816.7.1 by Vincent Ladeuil
Remove duplication and simplify.
640
                2>Switched to branch:...branched...
5816.6.11 by A. S. Budden
Refactored assertParentCorrect to check the full path.
641
                $ cd ..
5816.6.10 by A. S. Budden
Use locals() instead of kwargs for more explicit parameters.
642
                ''' % locals())
5816.7.1 by Vincent Ladeuil
Remove duplication and simplify.
643
        bound_branch = branch.Branch.open_containing('checkout')[0]
644
        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.
645
        return (bound_branch, master_branch)
5816.6.8 by A. S. Budden
Refactored to use common generation code for lightweight and heavyweight.
646
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.
647
    def test_branch_switch_parent_lightweight(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
648
        """Lightweight checkout using brz branch --switch."""
5816.7.1 by Vincent Ladeuil
Remove duplication and simplify.
649
        bb, mb = self._checkout_and_branch(option='--lightweight')
650
        self.assertParent('repo/trunk', bb)
651
        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.
652
653
    def test_branch_switch_parent_heavyweight(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
654
        """Heavyweight checkout using brz branch --switch."""
5816.7.1 by Vincent Ladeuil
Remove duplication and simplify.
655
        bb, mb = self._checkout_and_branch()
656
        self.assertParent('repo/trunk', bb)
657
        self.assertParent('repo/trunk', mb)