~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2010-09-28 08:57:31 UTC
  • mto: (5490.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 5492.
  • Revision ID: v.ladeuil+lp@free.fr-20100928085731-8h0duqj5wf4acsgy
Add -m to search for a regexp in news entries instead of the bug number.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2011 Canonical Ltd
 
1
# Copyright (C) 2007-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
22
22
from bzrlib import (
23
23
    branch,
24
24
    builtins,
25
 
    controldir,
 
25
    bzrdir,
26
26
    check,
 
27
    debug,
27
28
    errors,
28
29
    memorytree,
29
30
    push,
 
31
    repository,
30
32
    revision,
31
33
    symbol_versioning,
32
34
    tests,
34
36
    )
35
37
from bzrlib.smart import (
36
38
    client,
 
39
    server,
 
40
    repository as _mod_smart_repo,
37
41
    )
38
42
from bzrlib.tests import (
39
43
    per_branch,
53
57
        mine.merge_from_branch(other.branch)
54
58
        mine.commit('merge my change', rev_id='P2')
55
59
        result = mine.branch.push(other.branch)
56
 
        self.assertEqual('P2', other.branch.last_revision())
 
60
        self.assertEqual(['P1', 'P2'], other.branch.revision_history())
57
61
        # result object contains some structured data
58
62
        self.assertEqual(result.old_revid, 'M1')
59
63
        self.assertEqual(result.new_revid, 'P2')
 
64
        # and it can be treated as an integer for compatibility
 
65
        self.assertEqual(self.applyDeprecated(
 
66
            symbol_versioning.deprecated_in((2, 3, 0)),
 
67
            result.__int__),
 
68
            0)
60
69
 
61
70
    def test_push_merged_indirect(self):
62
71
        # it should be possible to do a push from one branch into another
73
82
        mine.merge_from_branch(other.branch)
74
83
        mine.commit('merge other', rev_id='P2')
75
84
        mine.branch.push(target.branch)
76
 
        self.assertEqual('P2', target.branch.last_revision())
 
85
        self.assertEqual(['P1', 'P2'], target.branch.revision_history())
77
86
 
78
87
    def test_push_to_checkout_updates_master(self):
79
88
        """Pushing into a checkout updates the checkout and the master branch"""
90
99
        rev2 = other.commit('other commit')
91
100
        # now push, which should update both checkout and master.
92
101
        other.branch.push(checkout.branch)
93
 
        self.assertEqual(rev2, checkout.branch.last_revision())
94
 
        self.assertEqual(rev2, master_tree.branch.last_revision())
 
102
        self.assertEqual([rev1, rev2], checkout.branch.revision_history())
 
103
        self.assertEqual([rev1, rev2], master_tree.branch.revision_history())
95
104
 
96
105
    def test_push_raises_specific_error_on_master_connection_error(self):
97
106
        master_tree = self.make_branch_and_tree('master')
109
118
        self.assertRaises(errors.BoundBranchConnectionFailure,
110
119
                other.branch.push, checkout.branch)
111
120
 
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)
126
 
        self.assertEqual({'new-tag': 'some-rev'}, bound.tags.get_tag_dict())
127
 
        self.assertEqual({'new-tag': 'some-rev'}, master.tags.get_tag_dict())
128
 
 
129
121
    def test_push_uses_read_lock(self):
130
122
        """Push should only need a read lock on the source side."""
131
123
        source = self.make_branch_and_tree('source')
152
144
        except (errors.IncompatibleFormat, errors.UninitializableFormat):
153
145
            # This Branch format cannot create shared repositories
154
146
            return
155
 
        if not repo._format.supports_nesting_repositories:
156
 
            return
157
147
        # This is a little bit trickier because make_branch_and_tree will not
158
148
        # re-use a shared repository.
159
149
        a_bzrdir = self.make_bzrdir('repo/tree')
168
158
            if self.vfs_transport_factory is test_server.LocalURLServer:
169
159
                # the branch is colocated on disk, we cannot create a checkout.
170
160
                # hopefully callers will expect this.
171
 
                local_controldir = controldir.ControlDir.open(
 
161
                local_controldir= bzrdir.BzrDir.open(
172
162
                    self.get_vfs_only_url('repo/tree'))
173
163
                tree = local_controldir.create_workingtree()
174
164
            else:
184
174
        self.assertEqual(tree.branch.last_revision(),
185
175
                         to_branch.last_revision())
186
176
 
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
 
 
202
177
    def test_push_overwrite_of_non_tip_with_stop_revision(self):
203
178
        """Combining the stop_revision and overwrite options works.
204
179
 
215
190
        source.branch.push(target, stop_revision='rev-2', overwrite=True)
216
191
        self.assertEqual('rev-2', target.last_revision())
217
192
 
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
251
 
        self.assertEqual(['A', 'C'], sorted(repo.all_revision_ids()))
252
 
 
253
193
    def test_push_with_default_stacking_does_not_create_broken_branch(self):
254
194
        """Pushing a new standalone branch works even when there's a default
255
195
        stacking policy at the destination.
258
198
        default for the branch), and will be stacked when the repo format
259
199
        allows (which means that the branch format isn't necessarly preserved).
260
200
        """
261
 
        if self.bzrdir_format.fixed_components:
 
201
        if isinstance(self.branch_format, branch.BzrBranchFormat4):
262
202
            raise tests.TestNotApplicable('Not a metadir format.')
263
203
        if isinstance(self.branch_format, branch.BranchReferenceFormat):
264
204
            # This test could in principle apply to BranchReferenceFormat, but
350
290
            # remotebranches can't be bound.  Let's instead make a new local
351
291
            # branch of the default type, which does allow binding.
352
292
            # See https://bugs.launchpad.net/bzr/+bug/112020
353
 
            local = controldir.ControlDir.create_branch_convenience('local2')
 
293
            local = bzrdir.BzrDir.create_branch_convenience('local2')
354
294
            local.bind(target)
355
295
        source = self.make_branch('source')
356
296
        branch.Branch.hooks.install_named_hook(
399
339
            raise tests.TestNotApplicable(
400
340
                'Does not apply when remote backing branch is also '
401
341
                'a smart branch')
402
 
        if not self.branch_format.supports_leaving_lock():
 
342
        if isinstance(self.branch_format, branch.BzrBranchFormat4):
403
343
            raise tests.TestNotApplicable(
404
 
                'Branch format is not usable via HPSS.')
 
344
                'Branch format 4 is not usable via HPSS.')
405
345
        super(EmptyPushSmartEffortTests, self).setUp()
406
346
        # Create a smart server that publishes whatever the backing VFS server
407
347
        # does.
421
361
    def test_empty_branch_api(self):
422
362
        """The branch_obj.push API should make a limited number of HPSS calls.
423
363
        """
424
 
        t = transport.get_transport_from_url(self.smart_server.get_url()).clone('target')
 
364
        t = transport.get_transport(self.smart_server.get_url()).clone('target')
425
365
        target = branch.Branch.open_from_transport(t)
426
366
        self.empty_branch.push(target)
427
367
        self.assertEqual(
458
398
    def test_lossy_push_raises_same_vcs(self):
459
399
        target = self.make_branch('target')
460
400
        source = self.make_branch('source')
461
 
        self.assertRaises(errors.LossyPushToSameVCS, source.push, target, lossy=True)
 
401
        self.assertRaises(errors.LossyPushToSameVCS, source.lossy_push, target)