~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_push.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-07-14 08:21:19 UTC
  • mfrom: (3517.4.20 stacking)
  • Revision ID: pqm@pqm.ubuntu.com-20080714082119-ju6qe5weo8pp7f1c
merge integrated branch stacking

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from bzrlib.osutils import abspath
30
30
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
31
31
from bzrlib.tests.blackbox import ExternalBase
 
32
from bzrlib.tests.http_server import HttpServer
32
33
from bzrlib.transport import register_transport, unregister_transport
33
34
from bzrlib.transport.memory import MemoryServer, MemoryTransport
34
35
from bzrlib.uncommit import uncommit
266
267
            "bzr: ERROR: bzr push --revision takes one value.\n",
267
268
            'push -r0..2 ../to', working_dir='from')
268
269
 
 
270
    def create_trunk_and_feature_branch(self):
 
271
        # We have a mainline
 
272
        trunk_tree = self.make_branch_and_tree('target',
 
273
            format='development')
 
274
        trunk_tree.commit('mainline')
 
275
        # and a branch from it
 
276
        branch_tree = self.make_branch_and_tree('branch',
 
277
            format='development')
 
278
        branch_tree.pull(trunk_tree.branch)
 
279
        branch_tree.branch.set_parent(trunk_tree.branch.base)
 
280
        # with some work on it
 
281
        branch_tree.commit('moar work plz')
 
282
        return trunk_tree, branch_tree
 
283
 
 
284
    def assertPublished(self, branch_revid, stacked_on):
 
285
        """Assert that the branch 'published' has been published correctly."""
 
286
        published_branch = Branch.open('published')
 
287
        # The published branch refers to the mainline
 
288
        self.assertEqual(stacked_on, published_branch.get_stacked_on())
 
289
        # and the branch's work was pushed
 
290
        self.assertTrue(published_branch.repository.has_revision(branch_revid))
 
291
 
 
292
    def test_push_new_branch_reference(self):
 
293
        """Pushing a new branch with --reference creates a stacked branch."""
 
294
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
 
295
        # we publish branch_tree with a reference to the mainline.
 
296
        out, err = self.run_bzr(['push', '--reference', trunk_tree.branch.base,
 
297
            self.get_url('published')], working_dir='branch')
 
298
        self.assertEqual('', out)
 
299
        self.assertEqual('Created new stacked branch referring to %s.\n' %
 
300
            trunk_tree.branch.base, err)
 
301
        self.assertPublished(branch_tree.last_revision(),
 
302
            trunk_tree.branch.base)
 
303
 
 
304
    def test_push_new_branch_stacked_uses_parent_when_no_public_url(self):
 
305
        """When the parent has no public url the parent is used as-is."""
 
306
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
 
307
        # now we do a stacked push, which should determine the public location
 
308
        # for us.
 
309
        out, err = self.run_bzr(['push', '--stacked',
 
310
            self.get_url('published')], working_dir='branch')
 
311
        self.assertEqual('', out)
 
312
        self.assertEqual('Created new stacked branch referring to %s.\n' %
 
313
            trunk_tree.branch.base, err)
 
314
        self.assertPublished(branch_tree.last_revision(), trunk_tree.branch.base)
 
315
 
 
316
    def test_push_new_branch_stacked_uses_parent_public(self):
 
317
        """Pushing a new branch with --stacked creates a stacked branch."""
 
318
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
 
319
        # the trunk is published on a web server
 
320
        self.transport_readonly_server = HttpServer
 
321
        trunk_public = self.make_branch('public_trunk', format='development')
 
322
        trunk_public.pull(trunk_tree.branch)
 
323
        trunk_public_url = self.get_readonly_url('public_trunk')
 
324
        trunk_tree.branch.set_public_branch(trunk_public_url)
 
325
        # now we do a stacked push, which should determine the public location
 
326
        # for us.
 
327
        out, err = self.run_bzr(['push', '--stacked',
 
328
            self.get_url('published')], working_dir='branch')
 
329
        self.assertEqual('', out)
 
330
        self.assertEqual('Created new stacked branch referring to %s.\n' %
 
331
            trunk_public_url, err)
 
332
        self.assertPublished(branch_tree.last_revision(), trunk_public_url)
 
333
 
 
334
    def test_push_new_branch_stacked_no_parent(self):
 
335
        """Pushing with --stacked and no parent branch errors."""
 
336
        branch = self.make_branch_and_tree('branch', format='development')
 
337
        # now we do a stacked push, which should fail as the place to refer too
 
338
        # cannot be determined.
 
339
        out, err = self.run_bzr_error(
 
340
            ['Could not determine branch to refer to\\.'], ['push', '--stacked',
 
341
            self.get_url('published')], working_dir='branch')
 
342
        self.assertEqual('', out)
 
343
        self.assertFalse(self.get_transport('published').has('.'))
 
344
 
269
345
 
270
346
class RedirectingMemoryTransport(MemoryTransport):
271
347