249
250
working_dir='tree')
252
def create_trunk_and_feature_branch(self):
254
trunk_tree = self.make_branch_and_tree('target',
255
format='development')
256
trunk_tree.commit('mainline')
257
# and a branch from it
258
branch_tree = self.make_branch_and_tree('branch',
259
format='development')
260
branch_tree.pull(trunk_tree.branch)
261
branch_tree.branch.set_parent(trunk_tree.branch.base)
262
# with some work on it
263
branch_tree.commit('moar work plz')
264
return trunk_tree, branch_tree
266
def assertPublished(self, branch_revid, stacked_on):
267
"""Assert that the branch 'published' has been published correctly."""
268
published_branch = Branch.open('published')
269
# The published branch refers to the mainline
270
self.assertEqual(stacked_on, published_branch.get_stacked_on())
271
# and the branch's work was pushed
272
self.assertTrue(published_branch.repository.has_revision(branch_revid))
274
def test_push_new_branch_reference(self):
275
"""Pushing a new branch with --reference creates a stacked branch."""
276
trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
277
# we publish branch_tree with a reference to the mainline.
278
out, err = self.run_bzr(['push', '--reference', trunk_tree.branch.base,
279
self.get_url('published')], working_dir='branch')
280
self.assertEqual('', out)
281
self.assertEqual('Created new shallow branch referring to %s.\n' %
282
trunk_tree.branch.base, err)
283
self.assertPublished(branch_tree.last_revision(),
284
trunk_tree.branch.base)
286
def test_push_new_branch_shallow_uses_parent_when_no_public_url(self):
287
"""When the parent has no public url the parent is used as-is."""
288
trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
289
# now we do a shallow push, which should determine the public location
291
out, err = self.run_bzr(['push', '--shallow',
292
self.get_url('published')], working_dir='branch')
293
self.assertEqual('', out)
294
self.assertEqual('Created new shallow branch referring to %s.\n' %
295
trunk_tree.branch.base, err)
296
self.assertPublished(branch_tree.last_revision(), trunk_tree.branch.base)
298
def test_push_new_branch_shallow_uses_parent_public(self):
299
"""Pushing a new branch with --shallow creates a stacked branch."""
300
trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
301
# the trunk is published on a web server
302
self.transport_readonly_server = HttpServer
303
trunk_public = self.make_branch('public_trunk', format='development')
304
trunk_public.pull(trunk_tree.branch)
305
trunk_public_url = self.get_readonly_url('public_trunk')
306
trunk_tree.branch.set_public_branch(trunk_public_url)
307
# now we do a shallow push, which should determine the public location
309
out, err = self.run_bzr(['push', '--shallow',
310
self.get_url('published')], working_dir='branch')
311
self.assertEqual('', out)
312
self.assertEqual('Created new shallow branch referring to %s.\n' %
313
trunk_public_url, err)
314
self.assertPublished(branch_tree.last_revision(), trunk_public_url)
316
def test_push_new_branch_shallow_no_parent(self):
317
"""Pushing with --shallow and no parent branch errors."""
318
branch = self.make_branch_and_tree('branch', format='development')
319
# now we do a shallow push, which should fail as the place to refer too
320
# cannot be determined.
321
out, err = self.run_bzr_error(
322
['Could not determine branch to refer to\\.'], ['push', '--shallow',
323
self.get_url('published')], working_dir='branch')
324
self.assertEqual('', out)
325
self.assertFalse(self.get_transport('published').has('.'))
252
328
class RedirectingMemoryTransport(MemoryTransport):