/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5609.26.1 by John Arbash Meinel
Fix bug #465517, 'bzr push' to a target with a repo but no branch
1
# Copyright (C) 2007-2011 Canonical Ltd
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
16
17
"""Tests for branch.push behaviour."""
18
19
import os
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
20
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
21
from ... import (
3703.3.7 by Andrew Bennetts
Move empty push effort tests to branch_implementations.
22
    branch,
23
    builtins,
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
24
    controldir,
4332.3.35 by Robert Collins
Fix failing tests.
25
    check,
3703.3.7 by Andrew Bennetts
Move empty push effort tests to branch_implementations.
26
    errors,
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
27
    memorytree,
3904.3.5 by Andrew Bennetts
Improve the test; now 4/7 passing.
28
    push,
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
29
    revision,
3703.3.7 by Andrew Bennetts
Move empty push effort tests to branch_implementations.
30
    tests,
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
31
    transport,
32
    )
6670.4.1 by Jelmer Vernooij
Update imports.
33
from ...bzr import (
34
    branch as bzrbranch,
35
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
36
from ...sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
37
    BytesIO,
38
    )
6670.4.16 by Jelmer Vernooij
Move smart to breezy.bzr.
39
from ...bzr.smart import (
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
40
    client,
41
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
42
from .. import (
5017.3.29 by Vincent Ladeuil
-s bt.per_branch.test_push passing
43
    per_branch,
44
    test_server,
45
    )
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
46
47
48
class TestPush(per_branch.TestCaseWithBranch):
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
49
50
    def test_push_convergence_simple(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
51
        # when revisions are pushed, the left-most accessible parents must
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
52
        # become the revision-history.
53
        mine = self.make_branch_and_tree('mine')
54
        mine.commit('1st post', rev_id='P1', allow_pointless=True)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
55
        other = mine.controldir.sprout('other').open_workingtree()
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
56
        other.commit('my change', rev_id='M1', allow_pointless=True)
57
        mine.merge_from_branch(other.branch)
58
        mine.commit('merge my change', rev_id='P2')
2297.1.4 by Martin Pool
Push now returns a PushResult rather than just an integer.
59
        result = mine.branch.push(other.branch)
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
60
        self.assertEqual('P2', other.branch.last_revision())
2297.1.4 by Martin Pool
Push now returns a PushResult rather than just an integer.
61
        # result object contains some structured data
62
        self.assertEqual(result.old_revid, 'M1')
63
        self.assertEqual(result.new_revid, 'P2')
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
64
65
    def test_push_merged_indirect(self):
66
        # it should be possible to do a push from one branch into another
67
        # when the tip of the target was merged into the source branch
68
        # via a third branch - so its buried in the ancestry and is not
69
        # directly accessible.
70
        mine = self.make_branch_and_tree('mine')
71
        mine.commit('1st post', rev_id='P1', allow_pointless=True)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
72
        target = mine.controldir.sprout('target').open_workingtree()
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
73
        target.commit('my change', rev_id='M1', allow_pointless=True)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
74
        other = mine.controldir.sprout('other').open_workingtree()
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
75
        other.merge_from_branch(target.branch)
76
        other.commit('merge my change', rev_id='O2')
77
        mine.merge_from_branch(other.branch)
78
        mine.commit('merge other', rev_id='P2')
79
        mine.branch.push(target.branch)
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
80
        self.assertEqual('P2', target.branch.last_revision())
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
81
82
    def test_push_to_checkout_updates_master(self):
83
        """Pushing into a checkout updates the checkout and the master branch"""
84
        master_tree = self.make_branch_and_tree('master')
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
85
        checkout = self.make_branch_and_tree('checkout')
86
        try:
87
            checkout.branch.bind(master_tree.branch)
88
        except errors.UpgradeRequired:
89
            # cant bind this format, the test is irrelevant.
90
            return
91
        rev1 = checkout.commit('master')
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
92
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
93
        other = master_tree.branch.controldir.sprout('other').open_workingtree()
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
94
        rev2 = other.commit('other commit')
95
        # now push, which should update both checkout and master.
96
        other.branch.push(checkout.branch)
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
97
        self.assertEqual(rev2, checkout.branch.last_revision())
98
        self.assertEqual(rev2, master_tree.branch.last_revision())
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
99
100
    def test_push_raises_specific_error_on_master_connection_error(self):
101
        master_tree = self.make_branch_and_tree('master')
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
102
        checkout = self.make_branch_and_tree('checkout')
103
        try:
104
            checkout.branch.bind(master_tree.branch)
105
        except errors.UpgradeRequired:
106
            # cant bind this format, the test is irrelevant.
107
            return
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
108
        other = master_tree.branch.controldir.sprout('other').open_workingtree()
2245.2.1 by Robert Collins
Split branch pushing out of branch pulling.
109
        # move the branch out of the way on disk to cause a connection
110
        # error.
111
        os.rename('master', 'master_gone')
112
        # try to push, which should raise a BoundBranchConnectionFailure.
113
        self.assertRaises(errors.BoundBranchConnectionFailure,
114
                other.branch.push, checkout.branch)
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
115
5609.25.1 by Andrew Bennetts
Add failing test for bug #733350.
116
    def test_push_new_tag_to_bound_branch(self):
117
        master = self.make_branch('master')
118
        bound = self.make_branch('bound')
119
        try:
120
            bound.bind(master)
121
        except errors.UpgradeRequired:
122
            raise tests.TestNotApplicable(
123
                'Format does not support bound branches')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
124
        other = bound.controldir.sprout('other').open_branch()
5609.25.1 by Andrew Bennetts
Add failing test for bug #733350.
125
        try:
126
            other.tags.set_tag('new-tag', 'some-rev')
127
        except errors.TagsNotSupported:
128
            raise tests.TestNotApplicable('Format does not support tags')
129
        other.push(bound)
5609.25.2 by Andrew Bennetts
Hackish fix: pass some extra state to our _basic_push implementation via a private instance variable, rather than changing the API of _basic_push (which bzr-svn and possibly other plugins implement).
130
        self.assertEqual({'new-tag': 'some-rev'}, bound.tags.get_tag_dict())
131
        self.assertEqual({'new-tag': 'some-rev'}, master.tags.get_tag_dict())
5609.25.1 by Andrew Bennetts
Add failing test for bug #733350.
132
2279.1.1 by John Arbash Meinel
Branch.push() only needs a read lock.
133
    def test_push_uses_read_lock(self):
134
        """Push should only need a read lock on the source side."""
135
        source = self.make_branch_and_tree('source')
136
        target = self.make_branch('target')
137
2381.1.3 by Robert Collins
Review feedback.
138
        self.build_tree(['source/a'])
2279.1.1 by John Arbash Meinel
Branch.push() only needs a read lock.
139
        source.add(['a'])
140
        source.commit('a')
141
142
        source.branch.lock_read()
143
        try:
144
            target.lock_write()
145
            try:
146
                source.branch.push(target, stop_revision=source.last_revision())
147
            finally:
148
                target.unlock()
149
        finally:
150
            source.branch.unlock()
151
2279.1.3 by John Arbash Meinel
Switch the test to being a branch_implementation test.
152
    def test_push_within_repository(self):
153
        """Push from one branch to another inside the same repository."""
154
        try:
155
            repo = self.make_repository('repo', shared=True)
156
        except (errors.IncompatibleFormat, errors.UninitializableFormat):
157
            # This Branch format cannot create shared repositories
158
            return
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
159
        if not repo._format.supports_nesting_repositories:
160
            return
2279.1.3 by John Arbash Meinel
Switch the test to being a branch_implementation test.
161
        # This is a little bit trickier because make_branch_and_tree will not
162
        # re-use a shared repository.
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
163
        a_controldir = self.make_controldir('repo/tree')
2279.1.3 by John Arbash Meinel
Switch the test to being a branch_implementation test.
164
        try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
165
            a_branch = self.branch_format.initialize(a_controldir)
2279.1.3 by John Arbash Meinel
Switch the test to being a branch_implementation test.
166
        except (errors.UninitializableFormat):
167
            # Cannot create these branches
168
            return
2018.5.97 by Andrew Bennetts
Fix more tests.
169
        try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
170
            tree = a_branch.controldir.create_workingtree()
2018.5.97 by Andrew Bennetts
Fix more tests.
171
        except errors.NotLocalUrl:
5017.3.29 by Vincent Ladeuil
-s bt.per_branch.test_push passing
172
            if self.vfs_transport_factory is test_server.LocalURLServer:
2018.5.130 by Robert Collins
Make all branch_implementations tests pass.
173
                # the branch is colocated on disk, we cannot create a checkout.
174
                # hopefully callers will expect this.
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
175
                local_controldir = controldir.ControlDir.open(
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
176
                    self.get_vfs_only_url('repo/tree'))
2018.5.130 by Robert Collins
Make all branch_implementations tests pass.
177
                tree = local_controldir.create_workingtree()
178
            else:
179
                tree = a_branch.create_checkout('repo/tree', lightweight=True)
2381.1.3 by Robert Collins
Review feedback.
180
        self.build_tree(['repo/tree/a'])
2279.1.3 by John Arbash Meinel
Switch the test to being a branch_implementation test.
181
        tree.add(['a'])
182
        tree.commit('a')
183
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
184
        to_bzrdir = self.make_controldir('repo/branch')
2279.1.3 by John Arbash Meinel
Switch the test to being a branch_implementation test.
185
        to_branch = self.branch_format.initialize(to_bzrdir)
186
        tree.branch.push(to_branch)
187
188
        self.assertEqual(tree.branch.last_revision(),
189
                         to_branch.last_revision())
190
5611.2.1 by Jelmer Vernooij
Fix 'bzr push --overwrite -rOLD_MAINLINE_REV'.
191
    def test_push_overwrite_with_older_mainline_rev(self):
192
        """Pushing an older mainline revision with overwrite.
193
194
        This was <https://bugs.launchpad.net/bzr/+bug/386576>.
195
        """
196
        source = self.make_branch_and_tree('source')
197
        target = self.make_branch('target')
198
199
        source.commit('1st commit')
200
        source.commit('2nd commit', rev_id='rev-2')
201
        source.commit('3rd commit')
202
        source.branch.push(target)
203
        source.branch.push(target, stop_revision='rev-2', overwrite=True)
204
        self.assertEqual('rev-2', target.last_revision())
205
3449.1.2 by Andrew Bennetts
Add test and NEWS entry.
206
    def test_push_overwrite_of_non_tip_with_stop_revision(self):
207
        """Combining the stop_revision and overwrite options works.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
208
3449.1.2 by Andrew Bennetts
Add test and NEWS entry.
209
        This was <https://bugs.launchpad.net/bzr/+bug/234229>.
210
        """
211
        source = self.make_branch_and_tree('source')
212
        target = self.make_branch('target')
213
214
        source.commit('1st commit')
215
        source.branch.push(target)
216
        source.commit('2nd commit', rev_id='rev-2')
217
        source.commit('3rd commit')
218
219
        source.branch.push(target, stop_revision='rev-2', overwrite=True)
220
        self.assertEqual('rev-2', target.last_revision())
221
5609.26.1 by John Arbash Meinel
Fix bug #465517, 'bzr push' to a target with a repo but no branch
222
    def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
223
        # See https://bugs.launchpad.net/bzr/+bug/465517
224
        t = self.get_transport('target')
225
        t.ensure_base()
226
        bzrdir = self.bzrdir_format.initialize_on_transport(t)
227
        try:
228
            bzrdir.open_branch()
229
        except errors.NotBranchError:
230
            pass
231
        else:
232
            raise tests.TestNotApplicable('older formats can\'t have a repo'
233
                                          ' without a branch')
234
        try:
235
            source = self.make_branch_builder('source',
236
                                              format=self.bzrdir_format)
237
        except errors.UninitializableFormat:
238
            raise tests.TestNotApplicable('cannot initialize this format')
239
        source.start_series()
240
        source.build_snapshot('A', None, [
241
            ('add', ('', 'root-id', 'directory', None))])
242
        source.build_snapshot('B', ['A'], [])
243
        source.build_snapshot('C', ['A'], [])
244
        source.finish_series()
245
        b = source.get_branch()
246
        # Note: We can't read lock the source branch. Some formats take a write
247
        # lock to 'set_push_location', which breaks
248
        self.addCleanup(b.lock_write().unlock)
249
        repo = bzrdir.create_repository()
250
        # This means 'push the source branch into this dir'
251
        bzrdir.push_branch(b)
252
        self.addCleanup(repo.lock_read().unlock)
253
        # We should have pushed 'C', but not 'B', since it isn't in the
254
        # ancestry
6113.1.3 by Jelmer Vernooij
Use all_revision_ids() when testing present revisions.
255
        self.assertEqual(['A', 'C'], sorted(repo.all_revision_ids()))
5609.26.1 by John Arbash Meinel
Fix bug #465517, 'bzr push' to a target with a repo but no branch
256
3904.3.5 by Andrew Bennetts
Improve the test; now 4/7 passing.
257
    def test_push_with_default_stacking_does_not_create_broken_branch(self):
3904.3.7 by Andrew Bennetts
Comment the new tests.
258
        """Pushing a new standalone branch works even when there's a default
259
        stacking policy at the destination.
260
261
        The new branch will preserve the repo format (even if it isn't the
262
        default for the branch), and will be stacked when the repo format
263
        allows (which means that the branch format isn't necessarly preserved).
264
        """
5673.1.3 by Jelmer Vernooij
Change flexible_components to fixed_components.
265
        if self.bzrdir_format.fixed_components:
3904.3.6 by Andrew Bennetts
Skip test for two formats, and fix format 5 by avoiding a full history sync with non-format5 branches.
266
            raise tests.TestNotApplicable('Not a metadir format.')
6653.1.2 by Jelmer Vernooij
Fix imports.
267
        if isinstance(self.branch_format, bzrbranch.BranchReferenceFormat):
3904.3.7 by Andrew Bennetts
Comment the new tests.
268
            # This test could in principle apply to BranchReferenceFormat, but
269
            # make_branch_builder doesn't support it.
3904.3.6 by Andrew Bennetts
Skip test for two formats, and fix format 5 by avoiding a full history sync with non-format5 branches.
270
            raise tests.TestSkipped(
271
                "BranchBuilder can't make reference branches.")
3904.3.7 by Andrew Bennetts
Comment the new tests.
272
        # Make a branch called "local" in a stackable repository
273
        # The branch has 3 revisions:
274
        #   - rev-1, adds a file
275
        #   - rev-2, no changes
276
        #   - rev-3, modifies the file.
3904.3.5 by Andrew Bennetts
Improve the test; now 4/7 passing.
277
        repo = self.make_repository('repo', shared=True, format='1.6')
278
        builder = self.make_branch_builder('repo/local')
3904.3.4 by Andrew Bennetts
First cut of a branch_implementations test. It fails.
279
        builder.start_series()
280
        builder.build_snapshot('rev-1', None, [
281
            ('add', ('', 'root-id', 'directory', '')),
282
            ('add', ('filename', 'f-id', 'file', 'content\n'))])
283
        builder.build_snapshot('rev-2', ['rev-1'], [])
284
        builder.build_snapshot('rev-3', ['rev-2'],
285
            [('modify', ('f-id', 'new-content\n'))])
286
        builder.finish_series()
3904.3.6 by Andrew Bennetts
Skip test for two formats, and fix format 5 by avoiding a full history sync with non-format5 branches.
287
        trunk = builder.get_branch()
3904.3.7 by Andrew Bennetts
Comment the new tests.
288
        # Sprout rev-1 to "trunk", so that we can stack on it.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
289
        trunk.controldir.sprout(self.get_url('trunk'), revision_id='rev-1')
3904.3.7 by Andrew Bennetts
Comment the new tests.
290
        # Set a default stacking policy so that new branches will automatically
291
        # stack on trunk.
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
292
        self.make_controldir('.').get_config().set_default_stack_on('trunk')
3904.3.7 by Andrew Bennetts
Comment the new tests.
293
        # Push rev-2 to a new branch "remote".  It will be stacked on "trunk".
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
294
        output = BytesIO()
3904.3.6 by Andrew Bennetts
Skip test for two formats, and fix format 5 by avoiding a full history sync with non-format5 branches.
295
        push._show_push_branch(trunk, 'rev-2', self.get_url('remote'), output)
3904.3.7 by Andrew Bennetts
Comment the new tests.
296
        # Push rev-3 onto "remote".  If "remote" not stacked and is missing the
297
        # fulltext record for f-id @ rev-1, then this will fail.
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
298
        remote_branch = branch.Branch.open(self.get_url('remote'))
3904.3.6 by Andrew Bennetts
Skip test for two formats, and fix format 5 by avoiding a full history sync with non-format5 branches.
299
        trunk.push(remote_branch)
4332.3.35 by Robert Collins
Fix failing tests.
300
        check.check_dwim(remote_branch.base, False, True, True)
3904.3.4 by Andrew Bennetts
First cut of a branch_implementations test. It fails.
301
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
302
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
303
class TestPushHook(per_branch.TestCaseWithBranch):
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
304
305
    def setUp(self):
306
        self.hook_calls = []
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
307
        super(TestPushHook, self).setUp()
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
308
2297.1.4 by Martin Pool
Push now returns a PushResult rather than just an integer.
309
    def capture_post_push_hook(self, result):
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
310
        """Capture post push hook calls to self.hook_calls.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
311
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
312
        The call is logged, as is some state of the two branches.
313
        """
2297.1.6 by Martin Pool
Add docs for Results, give some members cleaner names
314
        if result.local_branch:
315
            local_locked = result.local_branch.is_locked()
316
            local_base = result.local_branch.base
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
317
        else:
318
            local_locked = None
319
            local_base = None
320
        self.hook_calls.append(
2297.1.6 by Martin Pool
Add docs for Results, give some members cleaner names
321
            ('post_push', result.source_branch, local_base,
322
             result.master_branch.base,
2297.1.4 by Martin Pool
Push now returns a PushResult rather than just an integer.
323
             result.old_revno, result.old_revid,
2297.1.6 by Martin Pool
Add docs for Results, give some members cleaner names
324
             result.new_revno, result.new_revid,
325
             result.source_branch.is_locked(), local_locked,
326
             result.master_branch.is_locked()))
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
327
328
    def test_post_push_empty_history(self):
329
        target = self.make_branch('target')
330
        source = self.make_branch('source')
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
331
        branch.Branch.hooks.install_named_hook(
332
            'post_push', self.capture_post_push_hook, None)
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
333
        source.push(target)
334
        # with nothing there we should still get a notification, and
335
        # have both branches locked at the notification time.
336
        self.assertEqual([
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
337
            ('post_push', source, None, target.base, 0, revision.NULL_REVISION,
338
             0, revision.NULL_REVISION, True, None, True)
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
339
            ],
340
            self.hook_calls)
341
342
    def test_post_push_bound_branch(self):
343
        # pushing to a bound branch should pass in the master branch to the
344
        # hook, allowing the correct number of emails to be sent, while still
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
345
        # allowing hooks that want to modify the target to do so to both
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
346
        # instances.
347
        target = self.make_branch('target')
348
        local = self.make_branch('local')
349
        try:
350
            local.bind(target)
351
        except errors.UpgradeRequired:
2477.1.2 by Martin Pool
Rename push/pull back to 'run_hooks' (jameinel)
352
            # We can't bind this format to itself- typically it is the local
353
            # branch that doesn't support binding.  As of May 2007
354
            # remotebranches can't be bound.  Let's instead make a new local
355
            # branch of the default type, which does allow binding.
356
            # See https://bugs.launchpad.net/bzr/+bug/112020
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
357
            local = controldir.ControlDir.create_branch_convenience('local2')
2477.1.9 by Martin Pool
Review cleanups from John, mostly docs
358
            local.bind(target)
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
359
        source = self.make_branch('source')
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
360
        branch.Branch.hooks.install_named_hook(
361
            'post_push', self.capture_post_push_hook, None)
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
362
        source.push(local)
363
        # with nothing there we should still get a notification, and
364
        # have both branches locked at the notification time.
365
        self.assertEqual([
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
366
            ('post_push', source, local.base, target.base, 0,
367
             revision.NULL_REVISION, 0, revision.NULL_REVISION,
368
             True, True, True)
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
369
            ],
370
            self.hook_calls)
371
372
    def test_post_push_nonempty_history(self):
373
        target = self.make_branch_and_memory_tree('target')
374
        target.lock_write()
375
        target.add('')
376
        rev1 = target.commit('rev 1')
377
        target.unlock()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
378
        sourcedir = target.controldir.clone(self.get_url('source'))
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
379
        source = memorytree.MemoryTree.create_on_branch(sourcedir.open_branch())
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
380
        rev2 = source.commit('rev 2')
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
381
        branch.Branch.hooks.install_named_hook(
382
            'post_push', self.capture_post_push_hook, None)
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
383
        source.branch.push(target.branch)
384
        # with nothing there we should still get a notification, and
385
        # have both branches locked at the notification time.
386
        self.assertEqual([
387
            ('post_push', source.branch, None, target.branch.base, 1, rev1,
388
             2, rev2, True, None, True)
389
            ],
390
            self.hook_calls)
3703.3.7 by Andrew Bennetts
Move empty push effort tests to branch_implementations.
391
392
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
393
class EmptyPushSmartEffortTests(per_branch.TestCaseWithBranch):
3703.3.7 by Andrew Bennetts
Move empty push effort tests to branch_implementations.
394
    """Tests that a push of 0 revisions should make a limited number of smart
395
    protocol RPCs.
396
    """
397
398
    def setUp(self):
399
        # Skip some scenarios that don't apply to these tests.
5247.3.38 by Vincent Ladeuil
Fix the last remaining failures.
400
        if (self.transport_server is not None
401
            and issubclass(self.transport_server,
402
                           test_server.SmartTCPServer_for_testing)):
3703.3.7 by Andrew Bennetts
Move empty push effort tests to branch_implementations.
403
            raise tests.TestNotApplicable(
404
                'Does not apply when remote backing branch is also '
405
                'a smart branch')
5674.1.1 by Jelmer Vernooij
Add supports_leave_lock flag to BranchFormat and RepositoryFormat.
406
        if not self.branch_format.supports_leaving_lock():
3703.3.7 by Andrew Bennetts
Move empty push effort tests to branch_implementations.
407
            raise tests.TestNotApplicable(
5674.1.1 by Jelmer Vernooij
Add supports_leave_lock flag to BranchFormat and RepositoryFormat.
408
                'Branch format is not usable via HPSS.')
3703.3.7 by Andrew Bennetts
Move empty push effort tests to branch_implementations.
409
        super(EmptyPushSmartEffortTests, self).setUp()
410
        # Create a smart server that publishes whatever the backing VFS server
411
        # does.
5017.3.29 by Vincent Ladeuil
-s bt.per_branch.test_push passing
412
        self.smart_server = test_server.SmartTCPServer_for_testing()
4659.1.2 by Robert Collins
Refactor creation and shutdown of test servers to use a common helper,
413
        self.start_server(self.smart_server, self.get_server())
3703.3.7 by Andrew Bennetts
Move empty push effort tests to branch_implementations.
414
        # Make two empty branches, 'empty' and 'target'.
415
        self.empty_branch = self.make_branch('empty')
416
        self.make_branch('target')
417
        # Log all HPSS calls into self.hpss_calls.
418
        client._SmartClient.hooks.install_named_hook(
419
            'call', self.capture_hpss_call, None)
420
        self.hpss_calls = []
421
422
    def capture_hpss_call(self, params):
423
        self.hpss_calls.append(params.method)
424
425
    def test_empty_branch_api(self):
426
        """The branch_obj.push API should make a limited number of HPSS calls.
427
        """
6039.1.5 by Jelmer Vernooij
Add get_transport_from_url and get_transport_from_path functions.
428
        t = transport.get_transport_from_url(self.smart_server.get_url()).clone('target')
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
429
        target = branch.Branch.open_from_transport(t)
3703.3.7 by Andrew Bennetts
Move empty push effort tests to branch_implementations.
430
        self.empty_branch.push(target)
431
        self.assertEqual(
4634.47.8 by Andrew Bennetts
Fix per_branch.test_push effort test to expect new verb.
432
            ['BzrDir.open_2.1',
4734.4.13 by Andrew Bennetts
Fix trivial test failure.
433
             'BzrDir.open_branchV3',
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
434
             'BzrDir.find_repositoryV3',
3703.3.7 by Andrew Bennetts
Move empty push effort tests to branch_implementations.
435
             'Branch.get_stacked_on_url',
436
             'Branch.lock_write',
437
             'Branch.last_revision_info',
438
             'Branch.unlock'],
439
            self.hpss_calls)
440
441
    def test_empty_branch_command(self):
442
        """The 'bzr push' command should make a limited number of HPSS calls.
443
        """
444
        cmd = builtins.cmd_push()
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
445
        cmd.outf = BytesIO()
3703.3.7 by Andrew Bennetts
Move empty push effort tests to branch_implementations.
446
        cmd.run(
4420.1.2 by Vincent Ladeuil
Fix bug #284038 by adding a --strict option to push.
447
            directory=self.get_url('empty'),
4420.1.4 by Vincent Ladeuil
Cleanup.
448
            location=self.smart_server.get_url() + 'target')
3703.3.7 by Andrew Bennetts
Move empty push effort tests to branch_implementations.
449
        # HPSS calls as of 2008/09/22:
450
        # [BzrDir.open, BzrDir.open_branch, BzrDir.find_repositoryV2,
451
        # Branch.get_stacked_on_url, get, get, Branch.lock_write,
452
        # Branch.last_revision_info, Branch.unlock]
453
        self.assertTrue(len(self.hpss_calls) <= 9, self.hpss_calls)
454
455
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
456
class TestLossyPush(per_branch.TestCaseWithBranch):
4347.3.2 by Jelmer Vernooij
Add some basic tests for lossy_push.
457
458
    def setUp(self):
459
        self.hook_calls = []
5010.2.18 by Vincent Ladeuil
Fix imports in per_branch/test_push.py.
460
        super(TestLossyPush, self).setUp()
4347.3.2 by Jelmer Vernooij
Add some basic tests for lossy_push.
461
462
    def test_lossy_push_raises_same_vcs(self):
463
        target = self.make_branch('target')
464
        source = self.make_branch('source')
5853.2.3 by Jelmer Vernooij
Fix lossy tests.
465
        self.assertRaises(errors.LossyPushToSameVCS, source.push, target, lossy=True)