/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_stacking.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-07-16 07:54:18 UTC
  • mfrom: (3537.3.5 stacking)
  • Revision ID: pqm@pqm.ubuntu.com-20080716075418-xbachkqt622m73v1
(mbp) post-merge review cleanups for stacking

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
"""Tests for Branch.get_stacked_on and set_stacked_on."""
 
17
"""Tests for Branch.get_stacked_on_url and set_stacked_on_url."""
18
18
 
19
19
from bzrlib import (
20
20
    bzrdir,
27
27
 
28
28
class TestStacking(TestCaseWithBranch):
29
29
 
30
 
    def test_get_set_stacked_on(self):
 
30
    def test_get_set_stacked_on_url(self):
31
31
        # branches must either:
32
32
        # raise UnstackableBranchFormat or
33
33
        # raise UnstackableRepositoryFormat or
39
39
            errors.UnstackableRepositoryFormat,
40
40
            )
41
41
        try:
42
 
            branch.set_stacked_on(target.base)
 
42
            branch.set_stacked_on_url(target.base)
43
43
        except old_format_errors:
44
44
            # if the set failed, so must the get
45
 
            self.assertRaises(old_format_errors, branch.get_stacked_on)
 
45
            self.assertRaises(old_format_errors, branch.get_stacked_on_url)
46
46
            return
47
47
        # now we have a stacked branch:
48
 
        self.assertEqual(target.base, branch.get_stacked_on())
49
 
        branch.set_stacked_on(None)
50
 
        self.assertRaises(errors.NotStacked, branch.get_stacked_on)
 
48
        self.assertEqual(target.base, branch.get_stacked_on_url())
 
49
        branch.set_stacked_on_url(None)
 
50
        self.assertRaises(errors.NotStacked, branch.get_stacked_on_url)
51
51
 
52
52
    def test_get_set_stacked_on_relative(self):
53
53
        # Branches can be stacked on other branches using relative paths.
58
58
            errors.UnstackableRepositoryFormat,
59
59
            )
60
60
        try:
61
 
            branch.set_stacked_on('../target')
 
61
            branch.set_stacked_on_url('../target')
62
62
        except old_format_errors:
63
63
            # if the set failed, so must the get
64
 
            self.assertRaises(old_format_errors, branch.get_stacked_on)
 
64
            self.assertRaises(old_format_errors, branch.get_stacked_on_url)
65
65
            return
66
 
        self.assertEqual('../target', branch.get_stacked_on())
 
66
        self.assertEqual('../target', branch.get_stacked_on_url())
67
67
 
68
68
    def assertRevisionInRepository(self, repo_path, revid):
69
69
        """Check that a revision is in a repository, disregarding stacking."""
84
84
        # it would cause a false pass of this test.
85
85
        new_branch = self.make_branch('new_branch')
86
86
        try:
87
 
            new_branch.set_stacked_on(trunk_tree.branch.base)
 
87
            new_branch.set_stacked_on_url(trunk_tree.branch.base)
88
88
        except (errors.UnstackableBranchFormat,
89
89
            errors.UnstackableRepositoryFormat), e:
90
90
            raise TestNotApplicable(e)
111
111
        # stacked repository
112
112
        self.assertRevisionNotInRepository('newbranch', trunk_revid)
113
113
        new_tree = new_dir.open_workingtree()
114
 
        new_tree.commit('something local')
 
114
        new_branch_revid = new_tree.commit('something local')
 
115
        self.assertRevisionNotInRepository('mainline', new_branch_revid)
 
116
        self.assertRevisionInRepository('newbranch', new_branch_revid)
 
117
 
 
118
    def test_unstack_fetches(self):
 
119
        """Removing the stacked-on branch pulls across all data"""
 
120
        # We have a mainline
 
121
        trunk_tree = self.make_branch_and_tree('mainline')
 
122
        trunk_revid = trunk_tree.commit('revision on mainline')
 
123
        # and make branch from it which is stacked
 
124
        try:
 
125
            new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
 
126
        except (errors.UnstackableBranchFormat,
 
127
            errors.UnstackableRepositoryFormat), e:
 
128
            raise TestNotApplicable(e)
 
129
        # stacked repository
 
130
        self.assertRevisionNotInRepository('newbranch', trunk_revid)
 
131
        # now when we unstack that should implicitly fetch, to make sure that
 
132
        # the branch will still work
 
133
        new_branch = new_dir.open_branch()
 
134
        new_branch.set_stacked_on_url(None)
 
135
        self.assertRevisionInRepository('newbranch', trunk_revid)
 
136
        # of course it's still in the mainline
 
137
        self.assertRevisionInRepository('mainline', trunk_revid)
 
138
        # and now we're no longer stacked
 
139
        self.assertRaises(errors.NotStacked,
 
140
            new_branch.get_stacked_on_url)
115
141
 
116
142
    def prepare_for_clone(self):
117
143
        tree = self.make_branch_and_tree('stacked-on')
133
159
        cloned_bzrdir = stacked_bzrdir.clone('cloned', preserve_stacking=True)
134
160
        try:
135
161
            self.assertEqual(
136
 
                stacked_bzrdir.open_branch().get_stacked_on(),
137
 
                cloned_bzrdir.open_branch().get_stacked_on())
 
162
                stacked_bzrdir.open_branch().get_stacked_on_url(),
 
163
                cloned_bzrdir.open_branch().get_stacked_on_url())
138
164
        except (errors.UnstackableBranchFormat,
139
165
                errors.UnstackableRepositoryFormat):
140
166
            pass
157
183
            self.fail('Expected a failure due to broken fetching.')
158
184
        unstacked_branch = cloned_unstacked_bzrdir.open_branch()
159
185
        self.assertRaises((errors.NotStacked, errors.UnstackableBranchFormat),
160
 
                          unstacked_branch.get_stacked_on)
 
186
                          unstacked_branch.get_stacked_on_url)
161
187
 
162
188
    def test_no_op_preserve_stacking(self):
163
189
        """With no stacking, preserve_stacking should be a no-op."""
164
190
        branch = self.make_branch('source')
165
191
        cloned_bzrdir = branch.bzrdir.clone('cloned', preserve_stacking=True)
166
192
        self.assertRaises((errors.NotStacked, errors.UnstackableBranchFormat),
167
 
                          cloned_bzrdir.open_branch().get_stacked_on)
 
193
                          cloned_bzrdir.open_branch().get_stacked_on_url)
168
194
 
169
195
    def test_sprout_stacking_policy_handling(self):
170
196
        """Obey policy where possible, ignore otherwise."""
174
200
        source = self.make_branch('source')
175
201
        target = source.bzrdir.sprout('target').open_branch()
176
202
        try:
177
 
            self.assertEqual('../stack-on', target.get_stacked_on())
 
203
            self.assertEqual('../stack-on', target.get_stacked_on_url())
178
204
        except errors.UnstackableBranchFormat:
179
205
            pass
180
206
 
186
212
        source = self.make_branch('source')
187
213
        target = source.bzrdir.clone('target').open_branch()
188
214
        try:
189
 
            self.assertEqual('../stack-on', target.get_stacked_on())
 
215
            self.assertEqual('../stack-on', target.get_stacked_on_url())
190
216
        except errors.UnstackableBranchFormat:
191
217
            pass