139
139
self.assertRaises(errors.NotStacked,
140
140
new_branch.get_stacked_on_url)
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.
145
:param in_directory: If not None, create a directory of this
146
name and create the stacking and stacked-on bzrdirs in
149
if in_directory is not None:
150
self.get_transport().mkdir(in_directory)
151
prefix = in_directory + '/'
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
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.
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.
169
raise TestNotApplicable(e)
159
170
cloned_bzrdir = stacked_bzrdir.clone('cloned', preserve_stacking=True)
161
172
self.assertEqual(
165
176
errors.UnstackableRepositoryFormat):
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.
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)
193
cloned_bzrdir.open_branch().get_stacked_on_url())
168
195
def test_clone_from_stacked_branch_no_preserve_stacking(self):
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.
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()
231
258
unstacked.fetch(stacked.branch.repository, 'rev2')
232
259
unstacked.get_revision('rev1')
233
260
unstacked.get_revision('rev2')
262
def test_autopack_when_stacked(self):
263
# in bzr.dev as of 20080730, autopack was reported to fail in stacked
264
# repositories because of problems with text deltas spanning physical
265
# repository boundaries. however, i didn't actually get this test to
266
# fail on that code. -- mbp
267
# see https://bugs.launchpad.net/bzr/+bug/252821
268
if not self.branch_format.supports_stacking():
269
raise TestNotApplicable("%r does not support stacking"
270
% self.branch_format)
271
stack_on = self.make_branch_and_tree('stack-on')
272
text_lines = ['line %d blah blah blah\n' % i for i in range(20)]
273
self.build_tree_contents([('stack-on/a', ''.join(text_lines))])
275
stack_on.commit('base commit')
276
stacked_dir = stack_on.bzrdir.sprout('stacked', stacked=True)
277
stacked_tree = stacked_dir.open_workingtree()
279
text_lines[0] = 'changed in %d\n' % i
280
self.build_tree_contents([('stacked/a', ''.join(text_lines))])
281
stacked_tree.commit('commit %d' % i)
282
stacked_tree.branch.repository.pack()
283
stacked_tree.branch.check()
285
def test_pull_delta_when_stacked(self):
286
if not self.branch_format.supports_stacking():
287
raise TestNotApplicable("%r does not support stacking"
288
% self.branch_format)
289
stack_on = self.make_branch_and_tree('stack-on')
290
text_lines = ['line %d blah blah blah\n' % i for i in range(20)]
291
self.build_tree_contents([('stack-on/a', ''.join(text_lines))])
293
stack_on.commit('base commit')
294
# make a stacked branch from the mainline
295
stacked_dir = stack_on.bzrdir.sprout('stacked', stacked=True)
296
stacked_tree = stacked_dir.open_workingtree()
297
# make a second non-stacked branch from the mainline
298
other_dir = stack_on.bzrdir.sprout('other')
299
other_tree = other_dir.open_workingtree()
300
text_lines[9] = 'changed in other\n'
301
self.build_tree_contents([('other/a', ''.join(text_lines))])
302
other_tree.commit('commit in other')
303
# this should have generated a delta; try to pull that across
304
# bug 252821 caused a RevisionNotPresent here...
305
stacked_tree.pull(other_tree.branch)
306
stacked_tree.branch.repository.pack()
307
stacked_tree.branch.check()
309
def test_fetch_revisions_with_file_changes(self):
310
# Fetching revisions including file changes into a stacked branch
311
# works without error.
312
# Make the source tree.
313
src_tree = self.make_branch_and_tree('src')
314
self.build_tree_contents([('src/a', 'content')])
316
src_tree.commit('first commit')
318
# Make the stacked-on branch.
319
src_tree.bzrdir.sprout('stacked-on')
321
# Make a branch stacked on it.
322
target = self.make_branch('target')
324
target.set_stacked_on_url('../stacked-on')
325
except (errors.UnstackableRepositoryFormat,
326
errors.UnstackableBranchFormat):
327
raise TestNotApplicable('Format does not support stacking.')
329
# Change the source branch.
330
self.build_tree_contents([('src/a', 'new content')])
331
src_tree.commit('second commit', rev_id='rev2')
333
# Fetch changes to the target.
334
target.fetch(src_tree.branch)
335
rtree = target.repository.revision_tree('rev2')
337
self.addCleanup(rtree.unlock)
338
self.assertEqual('new content', rtree.get_file_by_path('a').read())