~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_pull.py

Fix up inter_changes with dirstate both C and python.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
"""Black-box tests for bzr pull."""
20
20
import os
21
21
import sys
22
22
 
23
 
from bzrlib import (
24
 
    debug,
25
 
    remote,
26
 
    urlutils,
27
 
    )
28
 
 
29
23
from bzrlib.branch import Branch
30
24
from bzrlib.directory_service import directories
31
25
from bzrlib.osutils import pathjoin
32
 
from bzrlib.tests import (
33
 
    fixtures,
34
 
    TestCaseWithTransport,
35
 
    )
 
26
from bzrlib.tests.blackbox import ExternalBase
36
27
from bzrlib.uncommit import uncommit
37
28
from bzrlib.workingtree import WorkingTree
38
 
 
39
 
 
40
 
class TestPull(TestCaseWithTransport):
 
29
from bzrlib import urlutils
 
30
 
 
31
 
 
32
class TestPull(ExternalBase):
41
33
 
42
34
    def example_branch(self, path='.'):
43
35
        tree = self.make_branch_and_tree(path)
145
137
        self.run_bzr('pull -r 4')
146
138
        self.assertEqual(a.revision_history(), b.revision_history())
147
139
 
148
 
    def test_pull_tags(self):
149
 
        """Tags are updated by pull, and revisions named in those tags are
150
 
        fetched.
151
 
        """
152
 
        # Make a source, sprout a target off it
153
 
        builder = self.make_branch_builder('source')
154
 
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
155
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
156
 
        target_bzrdir = source.bzrdir.sprout('target')
157
 
        source.tags.set_tag('tag-a', 'rev-2')
158
 
        # Pull from source
159
 
        self.run_bzr('pull -d target source')
160
 
        target = target_bzrdir.open_branch()
161
 
        # The tag is present, and so is its revision.
162
 
        self.assertEqual('rev-2', target.tags.lookup_tag('tag-a'))
163
 
        target.repository.get_revision('rev-2')
164
140
 
165
141
    def test_overwrite_uptodate(self):
166
142
        # Make sure pull --overwrite overwrites
263
239
        out = self.run_bzr('pull ../branch_a', retcode=3)
264
240
        self.assertEqual(out,
265
241
                ('','bzr: ERROR: These branches have diverged.'
266
 
                    ' Use the missing command to see how.\n'
267
 
                    'Use the merge command to reconcile them.\n'))
 
242
                    ' Use the merge command to reconcile them.\n'))
268
243
        self.assertEqual(branch_b.get_parent(), parent)
269
244
        # test implicit --remember after resolving previous failure
270
245
        uncommit(branch=branch_b, tree=tree_b)
362
337
            def look_up(self, name, url):
363
338
                return 'source'
364
339
        directories.register('foo:', FooService, 'Testing directory service')
365
 
        self.addCleanup(directories.remove, 'foo:')
 
340
        self.addCleanup(lambda: directories.remove('foo:'))
366
341
        self.run_bzr('pull foo:bar -d target')
367
342
        self.assertEqual(source_last, target.last_revision())
368
 
 
369
 
    def test_pull_verbose_defaults_to_long(self):
370
 
        tree = self.example_branch('source')
371
 
        target = self.make_branch_and_tree('target')
372
 
        out = self.run_bzr('pull -v source -d target')[0]
373
 
        self.assertContainsRe(out,
374
 
                              r'revno: 1\ncommitter: .*\nbranch nick: source')
375
 
        self.assertNotContainsRe(out, r'\n {4}1 .*\n {6}setup\n')
376
 
 
377
 
    def test_pull_verbose_uses_default_log(self):
378
 
        tree = self.example_branch('source')
379
 
        target = self.make_branch_and_tree('target')
380
 
        target_config = target.branch.get_config()
381
 
        target_config.set_user_option('log_format', 'short')
382
 
        out = self.run_bzr('pull -v source -d target')[0]
383
 
        self.assertContainsRe(out, r'\n {4}1 .*\n {6}setup\n')
384
 
        self.assertNotContainsRe(
385
 
            out, r'revno: 1\ncommitter: .*\nbranch nick: source')
386
 
 
387
 
    def test_pull_smart_stacked_streaming_acceptance(self):
388
 
        """'bzr pull -r 123' works on stacked, smart branches, even when the
389
 
        revision specified by the revno is only present in the fallback
390
 
        repository.
391
 
 
392
 
        See <https://launchpad.net/bugs/380314>
393
 
        """
394
 
        self.setup_smart_server_with_call_log()
395
 
        # Make a stacked-on branch with two commits so that the
396
 
        # revision-history can't be determined just by looking at the parent
397
 
        # field in the revision in the stacked repo.
398
 
        parent = self.make_branch_and_tree('parent', format='1.9')
399
 
        parent.commit(message='first commit')
400
 
        parent.commit(message='second commit')
401
 
        local = parent.bzrdir.sprout('local').open_workingtree()
402
 
        local.commit(message='local commit')
403
 
        local.branch.create_clone_on_transport(
404
 
            self.get_transport('stacked'), stacked_on=self.get_url('parent'))
405
 
        empty = self.make_branch_and_tree('empty', format='1.9')
406
 
        self.reset_smart_call_log()
407
 
        self.run_bzr(['pull', '-r', '1', self.get_url('stacked')],
408
 
            working_dir='empty')
409
 
        # This figure represent the amount of work to perform this use case. It
410
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
411
 
        # being too low. If rpc_count increases, more network roundtrips have
412
 
        # become necessary for this use case. Please do not adjust this number
413
 
        # upwards without agreement from bzr's network support maintainers.
414
 
        self.assertLength(19, self.hpss_calls)
415
 
        remote = Branch.open('stacked')
416
 
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
417
 
    
418
 
    def test_pull_cross_format_warning(self):
419
 
        """You get a warning for probably slow cross-format pulls.
420
 
        """
421
 
        # this is assumed to be going through InterDifferingSerializer
422
 
        from_tree = self.make_branch_and_tree('from', format='2a')
423
 
        to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
424
 
        from_tree.commit(message='first commit')
425
 
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
426
 
        self.assertContainsRe(err,
427
 
            "(?m)Doing on-the-fly conversion")
428
 
 
429
 
    def test_pull_cross_format_warning_no_IDS(self):
430
 
        """You get a warning for probably slow cross-format pulls.
431
 
        """
432
 
        # this simulates what would happen across the network, where
433
 
        # interdifferingserializer is not active
434
 
 
435
 
        debug.debug_flags.add('IDS_never')
436
 
        # TestCase take care of restoring them
437
 
 
438
 
        from_tree = self.make_branch_and_tree('from', format='2a')
439
 
        to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
440
 
        from_tree.commit(message='first commit')
441
 
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
442
 
        self.assertContainsRe(err,
443
 
            "(?m)Doing on-the-fly conversion")
444
 
 
445
 
    def test_pull_cross_format_from_network(self):
446
 
        self.setup_smart_server_with_call_log()
447
 
        from_tree = self.make_branch_and_tree('from', format='2a')
448
 
        to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
449
 
        self.assertIsInstance(from_tree.branch, remote.RemoteBranch)
450
 
        from_tree.commit(message='first commit')
451
 
        out, err = self.run_bzr(['pull', '-d', 'to',
452
 
            from_tree.branch.bzrdir.root_transport.base])
453
 
        self.assertContainsRe(err,
454
 
            "(?m)Doing on-the-fly conversion")
455
 
 
456
 
    def test_pull_to_experimental_format_warning(self):
457
 
        """You get a warning for pulling into experimental formats.
458
 
        """
459
 
        from_tree = self.make_branch_and_tree('from', format='development-subtree')
460
 
        to_tree = self.make_branch_and_tree('to', format='development-subtree')
461
 
        from_tree.commit(message='first commit')
462
 
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
463
 
        self.assertContainsRe(err,
464
 
            "(?m)Fetching into experimental format")
465
 
 
466
 
    def test_pull_cross_to_experimental_format_warning(self):
467
 
        """You get a warning for pulling into experimental formats.
468
 
        """
469
 
        from_tree = self.make_branch_and_tree('from', format='2a')
470
 
        to_tree = self.make_branch_and_tree('to', format='development-subtree')
471
 
        from_tree.commit(message='first commit')
472
 
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
473
 
        self.assertContainsRe(err,
474
 
            "(?m)Fetching into experimental format")
475
 
 
476
 
    def test_pull_show_base(self):
477
 
        """bzr pull supports --show-base
478
 
 
479
 
        see https://bugs.launchpad.net/bzr/+bug/202374"""
480
 
        # create two trees with conflicts, setup conflict, check that
481
 
        # conflicted file looks correct
482
 
        a_tree = self.example_branch('a')
483
 
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
484
 
 
485
 
        f = open(pathjoin('a', 'hello'),'wt')
486
 
        f.write('fee')
487
 
        f.close()
488
 
        a_tree.commit('fee')
489
 
 
490
 
        f = open(pathjoin('b', 'hello'),'wt')
491
 
        f.write('fie')
492
 
        f.close()
493
 
 
494
 
        out,err=self.run_bzr(['pull','-d','b','a','--show-base'])
495
 
 
496
 
        # check for message here
497
 
        self.assertEqual(err,
498
 
                         ' M  hello\nText conflict in hello\n1 conflicts encountered.\n')
499
 
 
500
 
        self.assertEqualDiff('<<<<<<< TREE\n'
501
 
                             'fie||||||| BASE-REVISION\n'
502
 
                             'foo=======\n'
503
 
                             'fee>>>>>>> MERGE-SOURCE\n',
504
 
                             open(pathjoin('b', 'hello')).read())
505
 
 
506
 
    def test_pull_show_base_working_tree_only(self):
507
 
        """--show-base only allowed if there's a working tree
508
 
 
509
 
        see https://bugs.launchpad.net/bzr/+bug/202374"""
510
 
        # create a branch, see that --show-base fails
511
 
        self.make_branch('from')
512
 
        self.make_branch('to')
513
 
        out=self.run_bzr(['pull','-d','to','from','--show-base'],retcode=3)
514
 
        self.assertEqual(out,
515
 
                         ('','bzr: ERROR: Need working tree for --show-base.\n'))
516
 
 
517
 
    def test_pull_tag_conflicts(self):
518
 
        """pulling tags with conflicts will change the exit code"""
519
 
        # create a branch, see that --show-base fails
520
 
        from_tree = self.make_branch_and_tree('from')
521
 
        from_tree.branch.tags.set_tag("mytag", "somerevid")
522
 
        to_tree = self.make_branch_and_tree('to')
523
 
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
524
 
        out = self.run_bzr(['pull','-d','to','from'],retcode=1)
525
 
        self.assertEqual(out,
526
 
            ('No revisions to pull.\nConflicting tags:\n    mytag\n', ''))