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