/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2009-03-13 02:25:46 UTC
  • mfrom: (4133 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4183.
  • Revision ID: robertc@robertcollins.net-20090313022546-e7de5zsdkbay5okf
MergeĀ .dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for branch.push behaviour."""
18
18
 
 
19
from cStringIO import StringIO
19
20
import os
20
 
 
 
21
 
21
22
from bzrlib import (
22
23
    branch,
23
24
    builtins,
24
25
    bzrdir,
25
26
    debug,
26
27
    errors,
 
28
    push,
 
29
    repository,
27
30
    tests,
28
31
    )
29
32
from bzrlib.branch import Branch
31
34
from bzrlib.memorytree import MemoryTree
32
35
from bzrlib.revision import NULL_REVISION
33
36
from bzrlib.smart import client, server
 
37
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
34
38
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
35
39
from bzrlib.transport import get_transport
36
40
from bzrlib.transport.local import LocalURLServer
39
43
class TestPush(TestCaseWithBranch):
40
44
 
41
45
    def test_push_convergence_simple(self):
42
 
        # when revisions are pushed, the left-most accessible parents must 
 
46
        # when revisions are pushed, the left-most accessible parents must
43
47
        # become the revision-history.
44
48
        mine = self.make_branch_and_tree('mine')
45
49
        mine.commit('1st post', rev_id='P1', allow_pointless=True)
163
167
 
164
168
    def test_push_overwrite_of_non_tip_with_stop_revision(self):
165
169
        """Combining the stop_revision and overwrite options works.
166
 
        
 
170
 
167
171
        This was <https://bugs.launchpad.net/bzr/+bug/234229>.
168
172
        """
169
173
        source = self.make_branch_and_tree('source')
177
181
        source.branch.push(target, stop_revision='rev-2', overwrite=True)
178
182
        self.assertEqual('rev-2', target.last_revision())
179
183
 
 
184
    def test_push_with_default_stacking_does_not_create_broken_branch(self):
 
185
        """Pushing a new standalone branch works even when there's a default
 
186
        stacking policy at the destination.
 
187
 
 
188
        The new branch will preserve the repo format (even if it isn't the
 
189
        default for the branch), and will be stacked when the repo format
 
190
        allows (which means that the branch format isn't necessarly preserved).
 
191
        """
 
192
        if isinstance(self.branch_format, branch.BzrBranchFormat4):
 
193
            raise tests.TestNotApplicable('Not a metadir format.')
 
194
        if isinstance(self.branch_format, branch.BranchReferenceFormat):
 
195
            # This test could in principle apply to BranchReferenceFormat, but
 
196
            # make_branch_builder doesn't support it.
 
197
            raise tests.TestSkipped(
 
198
                "BranchBuilder can't make reference branches.")
 
199
        # Make a branch called "local" in a stackable repository
 
200
        # The branch has 3 revisions:
 
201
        #   - rev-1, adds a file
 
202
        #   - rev-2, no changes
 
203
        #   - rev-3, modifies the file.
 
204
        repo = self.make_repository('repo', shared=True, format='1.6')
 
205
        builder = self.make_branch_builder('repo/local')
 
206
        builder.start_series()
 
207
        builder.build_snapshot('rev-1', None, [
 
208
            ('add', ('', 'root-id', 'directory', '')),
 
209
            ('add', ('filename', 'f-id', 'file', 'content\n'))])
 
210
        builder.build_snapshot('rev-2', ['rev-1'], [])
 
211
        builder.build_snapshot('rev-3', ['rev-2'],
 
212
            [('modify', ('f-id', 'new-content\n'))])
 
213
        builder.finish_series()
 
214
        trunk = builder.get_branch()
 
215
        # Sprout rev-1 to "trunk", so that we can stack on it.
 
216
        trunk.bzrdir.sprout(self.get_url('trunk'), revision_id='rev-1')
 
217
        # Set a default stacking policy so that new branches will automatically
 
218
        # stack on trunk.
 
219
        self.make_bzrdir('.').get_config().set_default_stack_on('trunk')
 
220
        # Push rev-2 to a new branch "remote".  It will be stacked on "trunk".
 
221
        output = StringIO()
 
222
        push._show_push_branch(trunk, 'rev-2', self.get_url('remote'), output)
 
223
        # Push rev-3 onto "remote".  If "remote" not stacked and is missing the
 
224
        # fulltext record for f-id @ rev-1, then this will fail.
 
225
        remote_branch = Branch.open(self.get_url('remote'))
 
226
        trunk.push(remote_branch)
 
227
        remote_branch.check()
 
228
 
 
229
    def test_no_get_parent_map_after_insert_stream(self):
 
230
        # Effort test for bug 331823
 
231
        self.setup_smart_server_with_call_log()
 
232
        # Make a local branch with four revisions.  Four revisions because:
 
233
        # one to push, one there for _walk_to_common_revisions to find, one we
 
234
        # don't want to access, one for luck :)
 
235
        if isinstance(self.branch_format, branch.BranchReferenceFormat):
 
236
            # This test could in principle apply to BranchReferenceFormat, but
 
237
            # make_branch_builder doesn't support it.
 
238
            raise tests.TestSkipped(
 
239
                "BranchBuilder can't make reference branches.")
 
240
        try:
 
241
            builder = self.make_branch_builder('local')
 
242
        except (errors.TransportNotPossible, errors.UninitializableFormat):
 
243
            raise tests.TestNotApplicable('format not directly constructable')
 
244
        builder.start_series()
 
245
        builder.build_snapshot('first', None, [
 
246
            ('add', ('', 'root-id', 'directory', ''))])
 
247
        builder.build_snapshot('second', ['first'], [])
 
248
        builder.build_snapshot('third', ['second'], [])
 
249
        builder.build_snapshot('fourth', ['third'], [])
 
250
        builder.finish_series()
 
251
        local = builder.get_branch()
 
252
        local = branch.Branch.open(self.get_vfs_only_url('local'))
 
253
        # Initial push of three revisions
 
254
        remote_bzrdir = local.bzrdir.sprout(
 
255
            self.get_url('remote'), revision_id='third')
 
256
        remote = remote_bzrdir.open_branch()
 
257
        # Push fourth revision
 
258
        self.reset_smart_call_log()
 
259
        self.disableOptimisticGetParentMap()
 
260
        self.assertFalse(local.is_locked())
 
261
        local.push(remote)
 
262
        hpss_call_names = [item.call.method for item in self.hpss_calls]
 
263
        self.assertTrue('Repository.insert_stream' in hpss_call_names)
 
264
        insert_stream_idx = hpss_call_names.index('Repository.insert_stream')
 
265
        calls_after_insert_stream = hpss_call_names[insert_stream_idx:]
 
266
        # After inserting the stream the client has no reason to query the
 
267
        # remote graph any further.
 
268
        self.assertEqual(
 
269
            ['Repository.insert_stream', 'Repository.insert_stream', 'get',
 
270
             'Branch.set_last_revision_info', 'Branch.unlock'],
 
271
            calls_after_insert_stream)
 
272
 
 
273
    def disableOptimisticGetParentMap(self):
 
274
        # Tweak some class variables to stop remote get_parent_map calls asking
 
275
        # for or receiving more data than the caller asked for.
 
276
        old_flag = SmartServerRepositoryGetParentMap.no_extra_results
 
277
        inter_classes = [repository.InterOtherToRemote,
 
278
            repository.InterPackToRemotePack]
 
279
        old_batch_sizes = []
 
280
        for inter_class in inter_classes:
 
281
            old_batch_sizes.append(
 
282
                inter_class._walk_to_common_revisions_batch_size)
 
283
            inter_class._walk_to_common_revisions_batch_size = 1
 
284
        SmartServerRepositoryGetParentMap.no_extra_results = True
 
285
        def reset_values():
 
286
            SmartServerRepositoryGetParentMap.no_extra_results = old_flag
 
287
            for inter_class, size in zip(inter_classes, old_batch_sizes):
 
288
                inter_class._walk_to_common_revisions_batch_size = size
 
289
        self.addCleanup(reset_values)
 
290
 
180
291
 
181
292
class TestPushHook(TestCaseWithBranch):
182
293
 
186
297
 
187
298
    def capture_post_push_hook(self, result):
188
299
        """Capture post push hook calls to self.hook_calls.
189
 
        
 
300
 
190
301
        The call is logged, as is some state of the two branches.
191
302
        """
192
303
        if result.local_branch:
220
331
    def test_post_push_bound_branch(self):
221
332
        # pushing to a bound branch should pass in the master branch to the
222
333
        # hook, allowing the correct number of emails to be sent, while still
223
 
        # allowing hooks that want to modify the target to do so to both 
 
334
        # allowing hooks that want to modify the target to do so to both
224
335
        # instances.
225
336
        target = self.make_branch('target')
226
337
        local = self.make_branch('local')
307
418
        self.empty_branch.push(target)
308
419
        self.assertEqual(
309
420
            ['BzrDir.open',
310
 
             'BzrDir.open_branch',
311
 
             'BzrDir.find_repositoryV2',
 
421
             'BzrDir.open_branchV2',
 
422
             'BzrDir.find_repositoryV3',
312
423
             'Branch.get_stacked_on_url',
313
424
             'Branch.lock_write',
314
425
             'Branch.last_revision_info',