/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3221.11.3 by Robert Collins
Add missing test script.
1
# Copyright (C) 2008 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
3537.3.3 by Martin Pool
Rename Branch.set_stacked_on to set_stacked_on_url
17
"""Tests for Branch.get_stacked_on_url and set_stacked_on_url."""
3221.11.3 by Robert Collins
Add missing test script.
18
3517.4.12 by Martin Pool
Clearer per-branch-format tests for stacking
19
from bzrlib import (
3770.2.1 by Michael Hudson
test and feature
20
    branch,
3517.4.12 by Martin Pool
Clearer per-branch-format tests for stacking
21
    bzrdir,
22
    errors,
23
    )
24
from bzrlib.revision import NULL_REVISION
3793.1.2 by Andrew Bennetts
Add test showing that stacking from the smart server works.
25
from bzrlib.smart import server
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
26
from bzrlib.tests import TestNotApplicable, KnownFailure
3221.11.3 by Robert Collins
Add missing test script.
27
from bzrlib.tests.branch_implementations import TestCaseWithBranch
3793.1.2 by Andrew Bennetts
Add test showing that stacking from the smart server works.
28
from bzrlib.transport import get_transport
3221.11.3 by Robert Collins
Add missing test script.
29
30
31
class TestStacking(TestCaseWithBranch):
32
3830.3.16 by Martin Pool
Add passing tests for iter_lines_added_or_present in stacked repos
33
    def check_lines_added_or_present(self, stacked_branch, revid):
34
        # similar to a failure seen in bug 288751 by mbp 20081120
35
        stacked_repo = stacked_branch.repository
36
        stacked_repo.lock_read()
37
        try:
38
            list(stacked_repo.inventories.iter_lines_added_or_present_in_keys(
39
                    [(revid,)]))
40
        finally:
41
            stacked_repo.unlock()
42
3537.3.3 by Martin Pool
Rename Branch.set_stacked_on to set_stacked_on_url
43
    def test_get_set_stacked_on_url(self):
3221.11.3 by Robert Collins
Add missing test script.
44
        # branches must either:
45
        # raise UnstackableBranchFormat or
46
        # raise UnstackableRepositoryFormat or
47
        # permit stacking to be done and then return the stacked location.
48
        branch = self.make_branch('branch')
49
        target = self.make_branch('target')
50
        old_format_errors = (
51
            errors.UnstackableBranchFormat,
52
            errors.UnstackableRepositoryFormat,
53
            )
54
        try:
3537.3.3 by Martin Pool
Rename Branch.set_stacked_on to set_stacked_on_url
55
            branch.set_stacked_on_url(target.base)
3221.11.3 by Robert Collins
Add missing test script.
56
        except old_format_errors:
57
            # if the set failed, so must the get
3537.3.1 by Martin Pool
Rename branch.get_stacked_on to get_stacked_on_url
58
            self.assertRaises(old_format_errors, branch.get_stacked_on_url)
3221.11.3 by Robert Collins
Add missing test script.
59
            return
60
        # now we have a stacked branch:
3537.3.1 by Martin Pool
Rename branch.get_stacked_on to get_stacked_on_url
61
        self.assertEqual(target.base, branch.get_stacked_on_url())
3537.3.3 by Martin Pool
Rename Branch.set_stacked_on to set_stacked_on_url
62
        branch.set_stacked_on_url(None)
3537.3.1 by Martin Pool
Rename branch.get_stacked_on to get_stacked_on_url
63
        self.assertRaises(errors.NotStacked, branch.get_stacked_on_url)
3221.13.2 by Robert Collins
Add a shallow parameter to bzrdir.sprout, which involved fixing a lateny bug in pack to pack fetching with ghost discovery.
64
3242.5.1 by Jonathan Lange
Allow stacked-on branch locations to be stored as relative URLs.
65
    def test_get_set_stacked_on_relative(self):
66
        # Branches can be stacked on other branches using relative paths.
67
        branch = self.make_branch('branch')
68
        target = self.make_branch('target')
69
        old_format_errors = (
70
            errors.UnstackableBranchFormat,
71
            errors.UnstackableRepositoryFormat,
72
            )
73
        try:
3537.3.5 by Martin Pool
merge trunk including stacking policy
74
            branch.set_stacked_on_url('../target')
3242.5.1 by Jonathan Lange
Allow stacked-on branch locations to be stored as relative URLs.
75
        except old_format_errors:
76
            # if the set failed, so must the get
3537.3.5 by Martin Pool
merge trunk including stacking policy
77
            self.assertRaises(old_format_errors, branch.get_stacked_on_url)
3242.5.1 by Jonathan Lange
Allow stacked-on branch locations to be stored as relative URLs.
78
            return
3537.3.5 by Martin Pool
merge trunk including stacking policy
79
        self.assertEqual('../target', branch.get_stacked_on_url())
3242.5.1 by Jonathan Lange
Allow stacked-on branch locations to be stored as relative URLs.
80
3517.4.12 by Martin Pool
Clearer per-branch-format tests for stacking
81
    def assertRevisionInRepository(self, repo_path, revid):
82
        """Check that a revision is in a repository, disregarding stacking."""
83
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
84
        self.assertTrue(repo.has_revision(revid))
85
86
    def assertRevisionNotInRepository(self, repo_path, revid):
87
        """Check that a revision is not in a repository, disregarding stacking."""
88
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
89
        self.assertFalse(repo.has_revision(revid))
90
91
    def test_get_graph_stacked(self):
92
        """A stacked repository shows the graph of its parent."""
93
        trunk_tree = self.make_branch_and_tree('mainline')
94
        trunk_revid = trunk_tree.commit('mainline')
95
        # make a new branch, and stack on the existing one.  we don't use
96
        # sprout(stacked=True) here because if that is buggy and copies data
97
        # it would cause a false pass of this test.
98
        new_branch = self.make_branch('new_branch')
99
        try:
3537.3.3 by Martin Pool
Rename Branch.set_stacked_on to set_stacked_on_url
100
            new_branch.set_stacked_on_url(trunk_tree.branch.base)
3517.4.12 by Martin Pool
Clearer per-branch-format tests for stacking
101
        except (errors.UnstackableBranchFormat,
102
            errors.UnstackableRepositoryFormat), e:
103
            raise TestNotApplicable(e)
104
        # reading the graph from the stacked branch's repository should see
105
        # data from the stacked-on branch
106
        new_repo = new_branch.repository
107
        new_repo.lock_read()
108
        try:
109
            self.assertEqual(new_repo.get_parent_map([trunk_revid]),
110
                {trunk_revid: (NULL_REVISION, )})
111
        finally:
112
            new_repo.unlock()
113
114
    def test_sprout_stacked(self):
3221.13.2 by Robert Collins
Add a shallow parameter to bzrdir.sprout, which involved fixing a lateny bug in pack to pack fetching with ghost discovery.
115
        # We have a mainline
116
        trunk_tree = self.make_branch_and_tree('mainline')
117
        trunk_revid = trunk_tree.commit('mainline')
3221.18.4 by Ian Clatworthy
shallow -> stacked
118
        # and make branch from it which is stacked
3221.13.2 by Robert Collins
Add a shallow parameter to bzrdir.sprout, which involved fixing a lateny bug in pack to pack fetching with ghost discovery.
119
        try:
3221.18.4 by Ian Clatworthy
shallow -> stacked
120
            new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
121
        except (errors.UnstackableBranchFormat,
3517.4.12 by Martin Pool
Clearer per-branch-format tests for stacking
122
            errors.UnstackableRepositoryFormat), e:
123
            raise TestNotApplicable(e)
124
        # stacked repository
125
        self.assertRevisionNotInRepository('newbranch', trunk_revid)
3221.13.2 by Robert Collins
Add a shallow parameter to bzrdir.sprout, which involved fixing a lateny bug in pack to pack fetching with ghost discovery.
126
        new_tree = new_dir.open_workingtree()
3537.3.4 by Martin Pool
Improved branch stacking tests
127
        new_branch_revid = new_tree.commit('something local')
128
        self.assertRevisionNotInRepository('mainline', new_branch_revid)
129
        self.assertRevisionInRepository('newbranch', new_branch_revid)
130
3793.1.2 by Andrew Bennetts
Add test showing that stacking from the smart server works.
131
    # XXX: this helper probably belongs on TestCaseWithTransport
132
    def make_smart_server(self, path):
133
        smart_server = server.SmartTCPServer_for_testing()
134
        smart_server.setUp(self.get_server())
135
        remote_transport = get_transport(smart_server.get_url()).clone(path)
136
        self.addCleanup(smart_server.tearDown)
137
        return remote_transport
138
139
    def test_sprout_stacked_from_smart_server(self):
140
        if isinstance(self.branch_format, branch.BzrBranchFormat4):
141
            raise TestNotApplicable('Branch format 4 is not usable via HPSS.')
142
        # We have a mainline
143
        trunk_tree = self.make_branch_and_tree('mainline')
144
        trunk_revid = trunk_tree.commit('mainline')
145
        # Make sure that we can make a stacked branch from it
146
        try:
147
            trunk_tree.bzrdir.sprout('testbranch', stacked=True)
148
        except (errors.UnstackableBranchFormat,
149
            errors.UnstackableRepositoryFormat), e:
150
            raise TestNotApplicable(e)
151
        # Now serve the original mainline from a smart server
152
        remote_transport = self.make_smart_server('mainline')
153
        remote_bzrdir = bzrdir.BzrDir.open_from_transport(remote_transport)
154
        # and make branch from the smart server which is stacked
155
        new_dir = remote_bzrdir.sprout('newbranch', stacked=True)
156
        # stacked repository
157
        self.assertRevisionNotInRepository('newbranch', trunk_revid)
158
        new_tree = new_dir.open_workingtree()
159
        new_branch_revid = new_tree.commit('something local')
160
        self.assertRevisionNotInRepository('mainline', new_branch_revid)
161
        self.assertRevisionInRepository('newbranch', new_branch_revid)
162
3537.3.4 by Martin Pool
Improved branch stacking tests
163
    def test_unstack_fetches(self):
164
        """Removing the stacked-on branch pulls across all data"""
165
        # We have a mainline
166
        trunk_tree = self.make_branch_and_tree('mainline')
167
        trunk_revid = trunk_tree.commit('revision on mainline')
168
        # and make branch from it which is stacked
169
        try:
170
            new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
171
        except (errors.UnstackableBranchFormat,
172
            errors.UnstackableRepositoryFormat), e:
173
            raise TestNotApplicable(e)
174
        # stacked repository
175
        self.assertRevisionNotInRepository('newbranch', trunk_revid)
176
        # now when we unstack that should implicitly fetch, to make sure that
177
        # the branch will still work
178
        new_branch = new_dir.open_branch()
179
        new_branch.set_stacked_on_url(None)
180
        self.assertRevisionInRepository('newbranch', trunk_revid)
181
        # of course it's still in the mainline
182
        self.assertRevisionInRepository('mainline', trunk_revid)
183
        # and now we're no longer stacked
3537.3.5 by Martin Pool
merge trunk including stacking policy
184
        self.assertRaises(errors.NotStacked,
185
            new_branch.get_stacked_on_url)
3221.13.2 by Robert Collins
Add a shallow parameter to bzrdir.sprout, which involved fixing a lateny bug in pack to pack fetching with ghost discovery.
186
3567.3.4 by Michael Hudson
make test a lot better
187
    def make_stacked_bzrdir(self, in_directory=None):
3567.3.7 by Michael Hudson
better docstring
188
        """Create a stacked branch and return its bzrdir.
3567.3.4 by Michael Hudson
make test a lot better
189
190
        :param in_directory: If not None, create a directory of this
191
            name and create the stacking and stacked-on bzrdirs in
192
            this directory.
193
        """
194
        if in_directory is not None:
195
            self.get_transport().mkdir(in_directory)
196
            prefix = in_directory + '/'
197
        else:
198
            prefix = ''
199
        tree = self.make_branch_and_tree(prefix + 'stacked-on')
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
200
        tree.commit('Added foo')
201
        stacked_bzrdir = tree.branch.bzrdir.sprout(
3567.3.4 by Michael Hudson
make test a lot better
202
            prefix + 'stacked', tree.branch.last_revision(), stacked=True)
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
203
        return stacked_bzrdir
204
205
    def test_clone_from_stacked_branch_preserve_stacking(self):
3242.3.24 by Aaron Bentley
Fix test failures
206
        # We can clone from the bzrdir of a stacked branch. If
207
        # preserve_stacking is True, the cloned branch is stacked on the
208
        # same branch as the original.
3242.3.21 by Jonathan Lange
Preserve stacking in clone
209
        try:
3567.3.4 by Michael Hudson
make test a lot better
210
            stacked_bzrdir = self.make_stacked_bzrdir()
3242.3.21 by Jonathan Lange
Preserve stacking in clone
211
        except (errors.UnstackableBranchFormat,
3567.3.5 by Michael Hudson
use TestNotApplicable in all the stacking clone() tests.
212
                errors.UnstackableRepositoryFormat), e:
3242.3.21 by Jonathan Lange
Preserve stacking in clone
213
            # not a testable combination.
3567.3.5 by Michael Hudson
use TestNotApplicable in all the stacking clone() tests.
214
            raise TestNotApplicable(e)
3242.3.24 by Aaron Bentley
Fix test failures
215
        cloned_bzrdir = stacked_bzrdir.clone('cloned', preserve_stacking=True)
3242.3.21 by Jonathan Lange
Preserve stacking in clone
216
        try:
217
            self.assertEqual(
3537.3.5 by Martin Pool
merge trunk including stacking policy
218
                stacked_bzrdir.open_branch().get_stacked_on_url(),
219
                cloned_bzrdir.open_branch().get_stacked_on_url())
3242.3.21 by Jonathan Lange
Preserve stacking in clone
220
        except (errors.UnstackableBranchFormat,
221
                errors.UnstackableRepositoryFormat):
222
            pass
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
223
3567.3.4 by Michael Hudson
make test a lot better
224
    def test_clone_from_branch_stacked_on_relative_url_preserve_stacking(self):
225
        # If a branch's stacked-on url is relative, we can still clone
226
        # from it with preserve_stacking True and get a branch stacked
227
        # on an appropriately adjusted relative url.
3567.3.3 by Michael Hudson
very hackish test
228
        try:
3567.3.4 by Michael Hudson
make test a lot better
229
            stacked_bzrdir = self.make_stacked_bzrdir(in_directory='dir')
3567.3.3 by Michael Hudson
very hackish test
230
        except (errors.UnstackableBranchFormat,
3567.3.6 by Michael Hudson
oops
231
                errors.UnstackableRepositoryFormat), e:
3567.3.3 by Michael Hudson
very hackish test
232
            # not a testable combination.
3567.3.5 by Michael Hudson
use TestNotApplicable in all the stacking clone() tests.
233
            raise TestNotApplicable(e)
3567.3.4 by Michael Hudson
make test a lot better
234
        stacked_bzrdir.open_branch().set_stacked_on_url('../stacked-on')
3567.3.3 by Michael Hudson
very hackish test
235
        cloned_bzrdir = stacked_bzrdir.clone('cloned', preserve_stacking=True)
3567.3.4 by Michael Hudson
make test a lot better
236
        self.assertEqual(
237
            '../dir/stacked-on',
238
            cloned_bzrdir.open_branch().get_stacked_on_url())
3567.3.3 by Michael Hudson
very hackish test
239
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
240
    def test_clone_from_stacked_branch_no_preserve_stacking(self):
241
        try:
3567.3.4 by Michael Hudson
make test a lot better
242
            stacked_bzrdir = self.make_stacked_bzrdir()
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
243
        except (errors.UnstackableBranchFormat,
3567.3.6 by Michael Hudson
oops
244
                errors.UnstackableRepositoryFormat), e:
3242.3.40 by Aaron Bentley
Turn failing test into KnownFailure
245
            # not a testable combination.
3567.3.5 by Michael Hudson
use TestNotApplicable in all the stacking clone() tests.
246
            raise TestNotApplicable(e)
1551.19.46 by Aaron Bentley
Fix fetch from stacked respositories (#248506)
247
        cloned_unstacked_bzrdir = stacked_bzrdir.clone('cloned-unstacked',
248
            preserve_stacking=False)
3242.3.24 by Aaron Bentley
Fix test failures
249
        unstacked_branch = cloned_unstacked_bzrdir.open_branch()
3242.3.37 by Aaron Bentley
Updates from reviews
250
        self.assertRaises((errors.NotStacked, errors.UnstackableBranchFormat),
3537.3.5 by Martin Pool
merge trunk including stacking policy
251
                          unstacked_branch.get_stacked_on_url)
3242.3.37 by Aaron Bentley
Updates from reviews
252
253
    def test_no_op_preserve_stacking(self):
254
        """With no stacking, preserve_stacking should be a no-op."""
255
        branch = self.make_branch('source')
256
        cloned_bzrdir = branch.bzrdir.clone('cloned', preserve_stacking=True)
257
        self.assertRaises((errors.NotStacked, errors.UnstackableBranchFormat),
3537.3.5 by Martin Pool
merge trunk including stacking policy
258
                          cloned_bzrdir.open_branch().get_stacked_on_url)
3242.3.37 by Aaron Bentley
Updates from reviews
259
260
    def test_sprout_stacking_policy_handling(self):
261
        """Obey policy where possible, ignore otherwise."""
262
        stack_on = self.make_branch('stack-on')
263
        parent_bzrdir = self.make_bzrdir('.', format='default')
264
        parent_bzrdir.get_config().set_default_stack_on('stack-on')
265
        source = self.make_branch('source')
266
        target = source.bzrdir.sprout('target').open_branch()
3641.1.1 by John Arbash Meinel
Merge in 1.6rc5 and revert disabling default stack on policy
267
        try:
268
            self.assertEqual('../stack-on', target.get_stacked_on_url())
269
        except errors.UnstackableBranchFormat:
270
            pass
3242.3.38 by Aaron Bentley
Enhance tests
271
272
    def test_clone_stacking_policy_handling(self):
273
        """Obey policy where possible, ignore otherwise."""
274
        stack_on = self.make_branch('stack-on')
275
        parent_bzrdir = self.make_bzrdir('.', format='default')
276
        parent_bzrdir.get_config().set_default_stack_on('stack-on')
277
        source = self.make_branch('source')
278
        target = source.bzrdir.clone('target').open_branch()
3641.1.1 by John Arbash Meinel
Merge in 1.6rc5 and revert disabling default stack on policy
279
        try:
280
            self.assertEqual('../stack-on', target.get_stacked_on_url())
281
        except errors.UnstackableBranchFormat:
282
            pass
1551.19.46 by Aaron Bentley
Fix fetch from stacked respositories (#248506)
283
1551.19.47 by Aaron Bentley
Add test per JAM
284
    def prepare_stacked_on_fetch(self):
1551.19.46 by Aaron Bentley
Fix fetch from stacked respositories (#248506)
285
        stack_on = self.make_branch_and_tree('stack-on')
286
        stack_on.commit('first commit', rev_id='rev1')
287
        try:
288
            stacked_dir = stack_on.bzrdir.sprout('stacked', stacked=True)
289
        except (errors.UnstackableRepositoryFormat,
290
                errors.UnstackableBranchFormat):
291
            raise TestNotApplicable('Format does not support stacking.')
292
        unstacked = self.make_repository('unstacked')
1551.19.47 by Aaron Bentley
Add test per JAM
293
        return stacked_dir.open_workingtree(), unstacked
294
295
    def test_fetch_copies_from_stacked_on(self):
296
        stacked, unstacked = self.prepare_stacked_on_fetch()
297
        unstacked.fetch(stacked.branch.repository, 'rev1')
298
        unstacked.get_revision('rev1')
299
300
    def test_fetch_copies_from_stacked_on_and_stacked(self):
301
        stacked, unstacked = self.prepare_stacked_on_fetch()
302
        stacked.commit('second commit', rev_id='rev2')
303
        unstacked.fetch(stacked.branch.repository, 'rev2')
304
        unstacked.get_revision('rev1')
305
        unstacked.get_revision('rev2')
3830.3.16 by Martin Pool
Add passing tests for iter_lines_added_or_present in stacked repos
306
        self.check_lines_added_or_present(stacked.branch, 'rev1')
307
        self.check_lines_added_or_present(stacked.branch, 'rev2')
3582.2.1 by Jonathan Lange
Fix up problems with fetching revisions. Almost entirely abentley's work.
308
3582.1.8 by Martin Pool
Add test for repeated commits into packed repository
309
    def test_autopack_when_stacked(self):
310
        # in bzr.dev as of 20080730, autopack was reported to fail in stacked
311
        # repositories because of problems with text deltas spanning physical
3582.1.10 by Martin Pool
Add failing tets for pull into stacked repository
312
        # repository boundaries.  however, i didn't actually get this test to
313
        # fail on that code. -- mbp
3582.1.11 by Martin Pool
doc
314
        # see https://bugs.launchpad.net/bzr/+bug/252821
3582.1.8 by Martin Pool
Add test for repeated commits into packed repository
315
        if not self.branch_format.supports_stacking():
316
            raise TestNotApplicable("%r does not support stacking"
317
                % self.branch_format)
318
        stack_on = self.make_branch_and_tree('stack-on')
3582.1.9 by Martin Pool
Make autopack-stacked test use larger files; still does not fail
319
        text_lines = ['line %d blah blah blah\n' % i for i in range(20)]
320
        self.build_tree_contents([('stack-on/a', ''.join(text_lines))])
3582.1.8 by Martin Pool
Add test for repeated commits into packed repository
321
        stack_on.add('a')
322
        stack_on.commit('base commit')
323
        stacked_dir = stack_on.bzrdir.sprout('stacked', stacked=True)
324
        stacked_tree = stacked_dir.open_workingtree()
325
        for i in range(20):
3582.1.9 by Martin Pool
Make autopack-stacked test use larger files; still does not fail
326
            text_lines[0] = 'changed in %d\n' % i
327
            self.build_tree_contents([('stacked/a', ''.join(text_lines))])
3582.1.8 by Martin Pool
Add test for repeated commits into packed repository
328
            stacked_tree.commit('commit %d' % i)
329
        stacked_tree.branch.repository.pack()
3582.1.10 by Martin Pool
Add failing tets for pull into stacked repository
330
        stacked_tree.branch.check()
331
332
    def test_pull_delta_when_stacked(self):
333
        if not self.branch_format.supports_stacking():
334
            raise TestNotApplicable("%r does not support stacking"
335
                % self.branch_format)
336
        stack_on = self.make_branch_and_tree('stack-on')
337
        text_lines = ['line %d blah blah blah\n' % i for i in range(20)]
338
        self.build_tree_contents([('stack-on/a', ''.join(text_lines))])
339
        stack_on.add('a')
340
        stack_on.commit('base commit')
341
        # make a stacked branch from the mainline
342
        stacked_dir = stack_on.bzrdir.sprout('stacked', stacked=True)
343
        stacked_tree = stacked_dir.open_workingtree()
344
        # make a second non-stacked branch from the mainline
345
        other_dir = stack_on.bzrdir.sprout('other')
346
        other_tree = other_dir.open_workingtree()
347
        text_lines[9] = 'changed in other\n'
348
        self.build_tree_contents([('other/a', ''.join(text_lines))])
3830.3.16 by Martin Pool
Add passing tests for iter_lines_added_or_present in stacked repos
349
        stacked_revid = other_tree.commit('commit in other')
3582.1.10 by Martin Pool
Add failing tets for pull into stacked repository
350
        # this should have generated a delta; try to pull that across
3582.1.15 by Martin Pool
Comments and tests for repository stacking
351
        # bug 252821 caused a RevisionNotPresent here...
352
        stacked_tree.pull(other_tree.branch)
3582.1.10 by Martin Pool
Add failing tets for pull into stacked repository
353
        stacked_tree.branch.repository.pack()
354
        stacked_tree.branch.check()
3830.3.16 by Martin Pool
Add passing tests for iter_lines_added_or_present in stacked repos
355
        self.check_lines_added_or_present(stacked_tree.branch, stacked_revid)
3582.1.12 by Martin Pool
merge from trunk
356
3582.2.1 by Jonathan Lange
Fix up problems with fetching revisions. Almost entirely abentley's work.
357
    def test_fetch_revisions_with_file_changes(self):
358
        # Fetching revisions including file changes into a stacked branch
359
        # works without error.
360
        # Make the source tree.
361
        src_tree = self.make_branch_and_tree('src')
362
        self.build_tree_contents([('src/a', 'content')])
363
        src_tree.add('a')
364
        src_tree.commit('first commit')
365
366
        # Make the stacked-on branch.
367
        src_tree.bzrdir.sprout('stacked-on')
368
369
        # Make a branch stacked on it.
370
        target = self.make_branch('target')
371
        try:
372
            target.set_stacked_on_url('../stacked-on')
373
        except (errors.UnstackableRepositoryFormat,
374
                errors.UnstackableBranchFormat):
375
            raise TestNotApplicable('Format does not support stacking.')
376
377
        # Change the source branch.
378
        self.build_tree_contents([('src/a', 'new content')])
379
        src_tree.commit('second commit', rev_id='rev2')
380
381
        # Fetch changes to the target.
382
        target.fetch(src_tree.branch)
383
        rtree = target.repository.revision_tree('rev2')
384
        rtree.lock_read()
385
        self.addCleanup(rtree.unlock)
386
        self.assertEqual('new content', rtree.get_file_by_path('a').read())
3830.3.16 by Martin Pool
Add passing tests for iter_lines_added_or_present in stacked repos
387
        self.check_lines_added_or_present(target, 'rev2')
3770.2.1 by Michael Hudson
test and feature
388
389
    def test_transform_fallback_location_hook(self):
390
        # The 'transform_fallback_location' branch hook allows us to inspect
391
        # and transform the URL of the fallback location for the branch.
392
        stack_on = self.make_branch('stack-on')
393
        stacked = self.make_branch('stacked')
394
        try:
395
            stacked.set_stacked_on_url('../stack-on')
396
        except (errors.UnstackableRepositoryFormat,
397
                errors.UnstackableBranchFormat):
398
            raise TestNotApplicable('Format does not support stacking.')
399
        self.get_transport().rename('stack-on', 'new-stack-on')
400
        hook_calls = []
401
        def hook(stacked_branch, url):
402
            hook_calls.append(url)
403
            return '../new-stack-on'
404
        branch.Branch.hooks.install_named_hook(
405
            'transform_fallback_location', hook, None)
406
        branch.Branch.open('stacked')
407
        self.assertEqual(['../stack-on'], hook_calls)
3830.2.1 by Aaron Bentley
Fix HPSS with branch stacked on repository branch
408
409
    def test_stack_on_repository_branch(self):
410
        # Stacking should work when the repo isn't co-located with the
411
        # stack-on branch.
412
        try:
413
            repo = self.make_repository('repo', shared=True)
414
        except errors.IncompatibleFormat:
415
            raise TestNotApplicable()
416
        # Avoid make_branch, which produces standalone branches.
417
        bzrdir = self.make_bzrdir('repo/stack-on')
3834.5.4 by John Arbash Meinel
Skip the stack_on_repository test for BranchReference branches.
418
        try:
419
            b = bzrdir.create_branch()
420
        except errors.UninitializableFormat:
421
            raise TestNotApplicable()
3830.2.1 by Aaron Bentley
Fix HPSS with branch stacked on repository branch
422
        transport = self.get_transport('stacked')
423
        b.bzrdir.clone_on_transport(transport, stacked_on=b.base)
3830.2.2 by Aaron Bentley
Add explanatory comment.
424
        # Ensure that opening the branch doesn't raise.
3830.2.1 by Aaron Bentley
Fix HPSS with branch stacked on repository branch
425
        branch.Branch.open(transport.base)