~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-01-12 03:53:21 UTC
  • mfrom: (4948 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4964.
  • Revision ID: andrew.bennetts@canonical.com-20100112035321-hofpz5p10224ryj3
Merge lp:bzr, resolving conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for branch.push behaviour."""
18
18
 
19
19
from cStringIO import StringIO
20
20
import os
21
 
 
 
21
 
22
22
from bzrlib import (
23
23
    branch,
24
24
    builtins,
25
25
    bzrdir,
 
26
    check,
26
27
    debug,
27
28
    errors,
28
29
    push,
 
30
    repository,
29
31
    tests,
30
32
    )
31
33
from bzrlib.branch import Branch
33
35
from bzrlib.memorytree import MemoryTree
34
36
from bzrlib.revision import NULL_REVISION
35
37
from bzrlib.smart import client, server
36
 
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
 
38
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
 
39
from bzrlib.tests.per_branch.test_branch import TestCaseWithBranch
37
40
from bzrlib.transport import get_transport
38
41
from bzrlib.transport.local import LocalURLServer
39
42
 
41
44
class TestPush(TestCaseWithBranch):
42
45
 
43
46
    def test_push_convergence_simple(self):
44
 
        # when revisions are pushed, the left-most accessible parents must 
 
47
        # when revisions are pushed, the left-most accessible parents must
45
48
        # become the revision-history.
46
49
        mine = self.make_branch_and_tree('mine')
47
50
        mine.commit('1st post', rev_id='P1', allow_pointless=True)
165
168
 
166
169
    def test_push_overwrite_of_non_tip_with_stop_revision(self):
167
170
        """Combining the stop_revision and overwrite options works.
168
 
        
 
171
 
169
172
        This was <https://bugs.launchpad.net/bzr/+bug/234229>.
170
173
        """
171
174
        source = self.make_branch_and_tree('source')
222
225
        # fulltext record for f-id @ rev-1, then this will fail.
223
226
        remote_branch = Branch.open(self.get_url('remote'))
224
227
        trunk.push(remote_branch)
225
 
        remote_branch.check()
 
228
        check.check_dwim(remote_branch.base, False, True, True)
 
229
 
 
230
    def test_no_get_parent_map_after_insert_stream(self):
 
231
        # Effort test for bug 331823
 
232
        self.setup_smart_server_with_call_log()
 
233
        # Make a local branch with four revisions.  Four revisions because:
 
234
        # one to push, one there for _walk_to_common_revisions to find, one we
 
235
        # don't want to access, one for luck :)
 
236
        if isinstance(self.branch_format, branch.BranchReferenceFormat):
 
237
            # This test could in principle apply to BranchReferenceFormat, but
 
238
            # make_branch_builder doesn't support it.
 
239
            raise tests.TestSkipped(
 
240
                "BranchBuilder can't make reference branches.")
 
241
        try:
 
242
            builder = self.make_branch_builder('local')
 
243
        except (errors.TransportNotPossible, errors.UninitializableFormat):
 
244
            raise tests.TestNotApplicable('format not directly constructable')
 
245
        builder.start_series()
 
246
        builder.build_snapshot('first', None, [
 
247
            ('add', ('', 'root-id', 'directory', ''))])
 
248
        builder.build_snapshot('second', ['first'], [])
 
249
        builder.build_snapshot('third', ['second'], [])
 
250
        builder.build_snapshot('fourth', ['third'], [])
 
251
        builder.finish_series()
 
252
        local = builder.get_branch()
 
253
        local = branch.Branch.open(self.get_vfs_only_url('local'))
 
254
        # Initial push of three revisions
 
255
        remote_bzrdir = local.bzrdir.sprout(
 
256
            self.get_url('remote'), revision_id='third')
 
257
        remote = remote_bzrdir.open_branch()
 
258
        # Push fourth revision
 
259
        self.reset_smart_call_log()
 
260
        self.disableOptimisticGetParentMap()
 
261
        self.assertFalse(local.is_locked())
 
262
        local.push(remote)
 
263
        hpss_call_names = [item.call.method for item in self.hpss_calls]
 
264
        self.assertTrue('Repository.insert_stream_1.19' in hpss_call_names)
 
265
        insert_stream_idx = hpss_call_names.index(
 
266
            'Repository.insert_stream_1.19')
 
267
        calls_after_insert_stream = hpss_call_names[insert_stream_idx:]
 
268
        # After inserting the stream the client has no reason to query the
 
269
        # remote graph any further.
 
270
        self.assertEqual(
 
271
            ['Repository.insert_stream_1.19', 'Repository.insert_stream_1.19',
 
272
             'get', 'Branch.set_last_revision_info', 'Branch.unlock'],
 
273
            calls_after_insert_stream)
 
274
 
 
275
    def disableOptimisticGetParentMap(self):
 
276
        # Tweak some class variables to stop remote get_parent_map calls asking
 
277
        # for or receiving more data than the caller asked for.
 
278
        old_flag = SmartServerRepositoryGetParentMap.no_extra_results
 
279
        inter_class = repository.InterRepository
 
280
        old_batch_size = inter_class._walk_to_common_revisions_batch_size
 
281
        inter_class._walk_to_common_revisions_batch_size = 1
 
282
        SmartServerRepositoryGetParentMap.no_extra_results = True
 
283
        def reset_values():
 
284
            SmartServerRepositoryGetParentMap.no_extra_results = old_flag
 
285
            inter_class._walk_to_common_revisions_batch_size = old_batch_size
 
286
        self.addCleanup(reset_values)
226
287
 
227
288
 
228
289
class TestPushHook(TestCaseWithBranch):
233
294
 
234
295
    def capture_post_push_hook(self, result):
235
296
        """Capture post push hook calls to self.hook_calls.
236
 
        
 
297
 
237
298
        The call is logged, as is some state of the two branches.
238
299
        """
239
300
        if result.local_branch:
267
328
    def test_post_push_bound_branch(self):
268
329
        # pushing to a bound branch should pass in the master branch to the
269
330
        # hook, allowing the correct number of emails to be sent, while still
270
 
        # allowing hooks that want to modify the target to do so to both 
 
331
        # allowing hooks that want to modify the target to do so to both
271
332
        # instances.
272
333
        target = self.make_branch('target')
273
334
        local = self.make_branch('local')
333
394
        # Create a smart server that publishes whatever the backing VFS server
334
395
        # does.
335
396
        self.smart_server = server.SmartTCPServer_for_testing()
336
 
        self.smart_server.setUp(self.get_server())
337
 
        self.addCleanup(self.smart_server.tearDown)
 
397
        self.start_server(self.smart_server, self.get_server())
338
398
        # Make two empty branches, 'empty' and 'target'.
339
399
        self.empty_branch = self.make_branch('empty')
340
400
        self.make_branch('target')
353
413
        target = Branch.open_from_transport(transport)
354
414
        self.empty_branch.push(target)
355
415
        self.assertEqual(
356
 
            ['BzrDir.open',
357
 
             'BzrDir.open_branch',
358
 
             'BzrDir.find_repositoryV2',
 
416
            ['BzrDir.open_2.1',
 
417
             'BzrDir.open_branchV2',
 
418
             'BzrDir.find_repositoryV3',
359
419
             'Branch.get_stacked_on_url',
360
420
             'Branch.lock_write',
361
421
             'Branch.last_revision_info',
368
428
        cmd = builtins.cmd_push()
369
429
        cmd.outf = tests.StringIOWrapper()
370
430
        cmd.run(
371
 
            directory=self.get_url() + 'empty',
 
431
            directory=self.get_url('empty'),
372
432
            location=self.smart_server.get_url() + 'target')
373
433
        # HPSS calls as of 2008/09/22:
374
434
        # [BzrDir.open, BzrDir.open_branch, BzrDir.find_repositoryV2,
377
437
        self.assertTrue(len(self.hpss_calls) <= 9, self.hpss_calls)
378
438
 
379
439
 
 
440
class TestLossyPush(TestCaseWithBranch):
 
441
 
 
442
    def setUp(self):
 
443
        self.hook_calls = []
 
444
        TestCaseWithBranch.setUp(self)
 
445
 
 
446
    def test_lossy_push_raises_same_vcs(self):
 
447
        target = self.make_branch('target')
 
448
        source = self.make_branch('source')
 
449
        self.assertRaises(errors.LossyPushToSameVCS, source.lossy_push, target)