~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from bzrlib.branch import Branch
22
22
from bzrlib import errors
23
 
from bzrlib.tests import TestCaseWithTransport
24
 
 
25
 
 
26
 
class TestPush(TestCaseWithTransport):
 
23
from bzrlib.memorytree import MemoryTree
 
24
from bzrlib.revision import NULL_REVISION
 
25
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
 
26
 
 
27
 
 
28
class TestPush(TestCaseWithBranch):
27
29
 
28
30
    def test_push_convergence_simple(self):
29
31
        # when revisions are pushed, the left-most accessible parents must 
57
59
    def test_push_to_checkout_updates_master(self):
58
60
        """Pushing into a checkout updates the checkout and the master branch"""
59
61
        master_tree = self.make_branch_and_tree('master')
60
 
        rev1 = master_tree.commit('master')
61
 
        checkout = master_tree.branch.create_checkout('checkout')
 
62
        checkout = self.make_branch_and_tree('checkout')
 
63
        try:
 
64
            checkout.branch.bind(master_tree.branch)
 
65
        except errors.UpgradeRequired:
 
66
            # cant bind this format, the test is irrelevant.
 
67
            return
 
68
        rev1 = checkout.commit('master')
62
69
 
63
70
        other = master_tree.branch.bzrdir.sprout('other').open_workingtree()
64
71
        rev2 = other.commit('other commit')
69
76
 
70
77
    def test_push_raises_specific_error_on_master_connection_error(self):
71
78
        master_tree = self.make_branch_and_tree('master')
72
 
        checkout = master_tree.branch.create_checkout('checkout')
 
79
        checkout = self.make_branch_and_tree('checkout')
 
80
        try:
 
81
            checkout.branch.bind(master_tree.branch)
 
82
        except errors.UpgradeRequired:
 
83
            # cant bind this format, the test is irrelevant.
 
84
            return
73
85
        other = master_tree.branch.bzrdir.sprout('other').open_workingtree()
74
86
        # move the branch out of the way on disk to cause a connection
75
87
        # error.
77
89
        # try to push, which should raise a BoundBranchConnectionFailure.
78
90
        self.assertRaises(errors.BoundBranchConnectionFailure,
79
91
                other.branch.push, checkout.branch)
 
92
 
 
93
 
 
94
class TestPushHook(TestCaseWithBranch):
 
95
 
 
96
    def setUp(self):
 
97
        self.hook_calls = []
 
98
        TestCaseWithBranch.setUp(self)
 
99
 
 
100
    def capture_post_push_hook(self, source, local, master, old_revno,
 
101
        old_revid, new_revno, new_revid):
 
102
        """Capture post push hook calls to self.hook_calls.
 
103
        
 
104
        The call is logged, as is some state of the two branches.
 
105
        """
 
106
        if local:
 
107
            local_locked = local.is_locked()
 
108
            local_base = local.base
 
109
        else:
 
110
            local_locked = None
 
111
            local_base = None
 
112
        self.hook_calls.append(
 
113
            ('post_push', source, local_base, master.base, old_revno, old_revid,
 
114
             new_revno, new_revid, source.is_locked(), local_locked,
 
115
             master.is_locked()))
 
116
 
 
117
    def test_post_push_empty_history(self):
 
118
        target = self.make_branch('target')
 
119
        source = self.make_branch('source')
 
120
        Branch.hooks.install_hook('post_push', self.capture_post_push_hook)
 
121
        source.push(target)
 
122
        # with nothing there we should still get a notification, and
 
123
        # have both branches locked at the notification time.
 
124
        self.assertEqual([
 
125
            ('post_push', source, None, target.base, 0, NULL_REVISION,
 
126
             0, NULL_REVISION, True, None, True)
 
127
            ],
 
128
            self.hook_calls)
 
129
 
 
130
    def test_post_push_bound_branch(self):
 
131
        # pushing to a bound branch should pass in the master branch to the
 
132
        # hook, allowing the correct number of emails to be sent, while still
 
133
        # allowing hooks that want to modify the target to do so to both 
 
134
        # instances.
 
135
        target = self.make_branch('target')
 
136
        local = self.make_branch('local')
 
137
        try:
 
138
            local.bind(target)
 
139
        except errors.UpgradeRequired:
 
140
            # cant bind this format, the test is irrelevant.
 
141
            return
 
142
        source = self.make_branch('source')
 
143
        Branch.hooks.install_hook('post_push', self.capture_post_push_hook)
 
144
        source.push(local)
 
145
        # with nothing there we should still get a notification, and
 
146
        # have both branches locked at the notification time.
 
147
        self.assertEqual([
 
148
            ('post_push', source, local.base, target.base, 0, NULL_REVISION,
 
149
             0, NULL_REVISION, True, True, True)
 
150
            ],
 
151
            self.hook_calls)
 
152
 
 
153
    def test_post_push_nonempty_history(self):
 
154
        target = self.make_branch_and_memory_tree('target')
 
155
        target.lock_write()
 
156
        target.add('')
 
157
        rev1 = target.commit('rev 1')
 
158
        target.unlock()
 
159
        sourcedir = target.bzrdir.clone(self.get_url('source'))
 
160
        source = MemoryTree.create_on_branch(sourcedir.open_branch())
 
161
        rev2 = source.commit('rev 2')
 
162
        Branch.hooks.install_hook('post_push', self.capture_post_push_hook)
 
163
        source.branch.push(target.branch)
 
164
        # with nothing there we should still get a notification, and
 
165
        # have both branches locked at the notification time.
 
166
        self.assertEqual([
 
167
            ('post_push', source.branch, None, target.branch.base, 1, rev1,
 
168
             2, rev2, True, None, True)
 
169
            ],
 
170
            self.hook_calls)