~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

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