~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests for branch.push behaviour."""
18
18
 
19
19
from cStringIO import StringIO
 
20
import os
20
21
 
21
22
from testtools.matchers import (
22
23
    Equals,
25
26
 
26
27
from bzrlib import (
27
28
    branch,
 
29
    bzrdir,
28
30
    check,
29
 
    controldir,
30
31
    errors,
31
32
    push,
32
33
    symbol_versioning,
34
35
    vf_repository,
35
36
    )
36
37
from bzrlib.branch import Branch
37
 
from bzrlib.controldir import ControlDir
 
38
from bzrlib.bzrdir import BzrDir
38
39
from bzrlib.memorytree import MemoryTree
39
40
from bzrlib.revision import NULL_REVISION
40
41
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
60
61
        mine.merge_from_branch(other.branch)
61
62
        mine.commit('merge my change', rev_id='P2')
62
63
        result = mine.branch.push(other.branch)
63
 
        self.assertEqual('P2', other.branch.last_revision())
 
64
        self.assertEqual(['P1', 'P2'], other.branch.revision_history())
64
65
        # result object contains some structured data
65
66
        self.assertEqual(result.old_revid, 'M1')
66
67
        self.assertEqual(result.new_revid, 'P2')
 
68
        # and it can be treated as an integer for compatibility
 
69
        self.assertEqual(self.applyDeprecated(
 
70
            symbol_versioning.deprecated_in((2, 3, 0)),
 
71
            result.__int__),
 
72
            0)
67
73
 
68
74
    def test_push_merged_indirect(self):
69
75
        # it should be possible to do a push from one branch into another
80
86
        mine.merge_from_branch(other.branch)
81
87
        mine.commit('merge other', rev_id='P2')
82
88
        mine.branch.push(target.branch)
83
 
        self.assertEqual('P2', target.branch.last_revision())
 
89
        self.assertEqual(['P1', 'P2'], target.branch.revision_history())
84
90
 
85
91
    def test_push_to_checkout_updates_master(self):
86
92
        """Pushing into a checkout updates the checkout and the master branch"""
98
104
        rev2 = other.commit('other commit')
99
105
        # now push, which should update both checkout and master.
100
106
        other.branch.push(checkout.branch)
101
 
        self.assertEqual(rev2, checkout.branch.last_revision())
102
 
        self.assertEqual(rev2, master_tree.branch.last_revision())
 
107
        self.assertEqual([rev1, rev2], checkout.branch.revision_history())
 
108
        self.assertEqual([rev1, rev2], master_tree.branch.revision_history())
103
109
 
104
110
    def test_push_raises_specific_error_on_master_connection_error(self):
105
111
        master_tree = self.make_to_branch_and_tree('master')
113
119
        other = other_bzrdir.open_workingtree()
114
120
        # move the branch out of the way on disk to cause a connection
115
121
        # error.
116
 
        master_tree.bzrdir.destroy_branch()
 
122
        os.rename('master', 'master_gone')
117
123
        # try to push, which should raise a BoundBranchConnectionFailure.
118
124
        self.assertRaises(errors.BoundBranchConnectionFailure,
119
125
                other.branch.push, checkout.branch)
153
159
            return
154
160
        try:
155
161
            tree = a_branch.bzrdir.create_workingtree()
156
 
        except errors.UnsupportedOperation:
157
 
            self.assertFalse(a_branch.bzrdir._format.supports_workingtrees)
158
 
            tree = a_branch.create_checkout('repo/tree', lightweight=True)
159
162
        except errors.NotLocalUrl:
160
163
            if self.vfs_transport_factory is test_server.LocalURLServer:
161
164
                # the branch is colocated on disk, we cannot create a checkout.
162
165
                # hopefully callers will expect this.
163
 
                local_controldir = controldir.ControlDir.open(self.get_vfs_only_url('repo/tree'))
 
166
                local_controldir = bzrdir.BzrDir.open(self.get_vfs_only_url('repo/tree'))
164
167
                tree = local_controldir.create_workingtree()
165
168
            else:
166
169
                tree = a_branch.create_checkout('repo/tree', lightweight=True)
274
277
        # remote graph any further.
275
278
        bzr_core_trace = Equals(
276
279
            ['Repository.insert_stream_1.19', 'Repository.insert_stream_1.19',
277
 
             'Branch.set_last_revision_info', 'Branch.unlock'])
 
280
             'get', 'Branch.set_last_revision_info', 'Branch.unlock'])
278
281
        bzr_loom_trace = Equals(
279
282
            ['Repository.insert_stream_1.19', 'Repository.insert_stream_1.19',
280
 
             'Branch.set_last_revision_info', 'get', 'Branch.unlock'])
 
283
             'get', 'Branch.set_last_revision_info', 'get', 'Branch.unlock'])
281
284
        self.assertThat(calls_after_insert_stream,
282
285
            MatchesAny(bzr_core_trace, bzr_loom_trace))
283
286
 
294
297
 
295
298
    def setUp(self):
296
299
        self.hook_calls = []
297
 
        super(TestPushHook, self).setUp()
 
300
        TestCaseWithInterBranch.setUp(self)
298
301
 
299
302
    def capture_post_push_hook(self, result):
300
303
        """Capture post push hook calls to self.hook_calls.
344
347
            # remotebranches can't be bound.  Let's instead make a new local
345
348
            # branch of the default type, which does allow binding.
346
349
            # See https://bugs.launchpad.net/bzr/+bug/112020
347
 
            local = ControlDir.create_branch_convenience('local2')
 
350
            local = BzrDir.create_branch_convenience('local2')
348
351
            local.bind(target)
349
352
        source = self.make_from_branch('source')
350
353
        Branch.hooks.install_named_hook('post_push',
364
367
        target.add('')
365
368
        rev1 = target.commit('rev 1')
366
369
        target.unlock()
367
 
        sourcedir = target.branch.bzrdir.clone(self.get_url('source'))
 
370
        sourcedir = target.bzrdir.clone(self.get_url('source'))
368
371
        source = MemoryTree.create_on_branch(sourcedir.open_branch())
369
372
        rev2 = source.commit('rev 2')
370
373
        Branch.hooks.install_named_hook('post_push',