~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge with extras

Show diffs side-by-side

added added

removed removed

Lines of Context:
139
139
        self.assertRaises(errors.NotStacked,
140
140
            new_branch.get_stacked_on_url)
141
141
 
142
 
    def prepare_for_clone(self):
143
 
        tree = self.make_branch_and_tree('stacked-on')
 
142
    def make_stacked_bzrdir(self, in_directory=None):
 
143
        """Create a stacked branch and return its bzrdir.
 
144
 
 
145
        :param in_directory: If not None, create a directory of this
 
146
            name and create the stacking and stacked-on bzrdirs in
 
147
            this directory.
 
148
        """
 
149
        if in_directory is not None:
 
150
            self.get_transport().mkdir(in_directory)
 
151
            prefix = in_directory + '/'
 
152
        else:
 
153
            prefix = ''
 
154
        tree = self.make_branch_and_tree(prefix + 'stacked-on')
144
155
        tree.commit('Added foo')
145
156
        stacked_bzrdir = tree.branch.bzrdir.sprout(
146
 
            'stacked', tree.branch.last_revision(), stacked=True)
 
157
            prefix + 'stacked', tree.branch.last_revision(), stacked=True)
147
158
        return stacked_bzrdir
148
159
 
149
160
    def test_clone_from_stacked_branch_preserve_stacking(self):
151
162
        # preserve_stacking is True, the cloned branch is stacked on the
152
163
        # same branch as the original.
153
164
        try:
154
 
            stacked_bzrdir = self.prepare_for_clone()
 
165
            stacked_bzrdir = self.make_stacked_bzrdir()
155
166
        except (errors.UnstackableBranchFormat,
156
 
                errors.UnstackableRepositoryFormat):
 
167
                errors.UnstackableRepositoryFormat), e:
157
168
            # not a testable combination.
158
 
            return
 
169
            raise TestNotApplicable(e)
159
170
        cloned_bzrdir = stacked_bzrdir.clone('cloned', preserve_stacking=True)
160
171
        try:
161
172
            self.assertEqual(
165
176
                errors.UnstackableRepositoryFormat):
166
177
            pass
167
178
 
 
179
    def test_clone_from_branch_stacked_on_relative_url_preserve_stacking(self):
 
180
        # If a branch's stacked-on url is relative, we can still clone
 
181
        # from it with preserve_stacking True and get a branch stacked
 
182
        # on an appropriately adjusted relative url.
 
183
        try:
 
184
            stacked_bzrdir = self.make_stacked_bzrdir(in_directory='dir')
 
185
        except (errors.UnstackableBranchFormat,
 
186
                errors.UnstackableRepositoryFormat), e:
 
187
            # not a testable combination.
 
188
            raise TestNotApplicable(e)
 
189
        stacked_bzrdir.open_branch().set_stacked_on_url('../stacked-on')
 
190
        cloned_bzrdir = stacked_bzrdir.clone('cloned', preserve_stacking=True)
 
191
        self.assertEqual(
 
192
            '../dir/stacked-on',
 
193
            cloned_bzrdir.open_branch().get_stacked_on_url())
 
194
 
168
195
    def test_clone_from_stacked_branch_no_preserve_stacking(self):
169
196
        try:
170
 
            stacked_bzrdir = self.prepare_for_clone()
 
197
            stacked_bzrdir = self.make_stacked_bzrdir()
171
198
        except (errors.UnstackableBranchFormat,
172
 
                errors.UnstackableRepositoryFormat):
 
199
                errors.UnstackableRepositoryFormat), e:
173
200
            # not a testable combination.
174
 
            return
 
201
            raise TestNotApplicable(e)
175
202
        cloned_unstacked_bzrdir = stacked_bzrdir.clone('cloned-unstacked',
176
203
            preserve_stacking=False)
177
204
        unstacked_branch = cloned_unstacked_bzrdir.open_branch()