~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge with shallow-branch

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
248
249
                'push ../dir',
249
250
                working_dir='tree')
250
251
 
 
252
    def create_trunk_and_feature_branch(self):
 
253
        # We have a mainline
 
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
 
265
 
 
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))
 
273
 
 
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)
 
285
 
 
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
 
290
        # for us.
 
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)
 
297
 
 
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
 
308
        # for us.
 
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)
 
315
 
 
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('.'))
 
326
 
251
327
 
252
328
class RedirectingMemoryTransport(MemoryTransport):
253
329