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