29
29
from bzrlib.branch import Branch
30
30
from bzrlib.directory_service import directories
31
31
from bzrlib.osutils import pathjoin
32
from bzrlib.tests.blackbox import ExternalBase
32
from bzrlib.tests import TestCaseWithTransport
33
33
from bzrlib.uncommit import uncommit
34
34
from bzrlib.workingtree import WorkingTree
37
class TestPull(ExternalBase):
37
class TestPull(TestCaseWithTransport):
39
39
def example_branch(self, path='.'):
40
40
tree = self.make_branch_and_tree(path)
142
142
self.run_bzr('pull -r 4')
143
143
self.assertEqual(a.revision_history(), b.revision_history())
145
def test_pull_tags(self):
146
"""Tags are updated by pull, and revisions named in those tags are
149
# Make a source, sprout a target off it
150
builder = self.make_branch_builder('source')
151
builder.build_commit(message="Rev 1", rev_id='rev-1')
152
source = builder.get_branch()
153
target_bzrdir = source.bzrdir.sprout('target')
154
# Add a non-ancestry tag to source
155
builder.build_commit(message="Rev 2", rev_id='rev-2')
156
source.tags.set_tag('tag-a', 'rev-2')
157
source.set_last_revision_info(1, 'rev-1')
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')
146
165
def test_overwrite_uptodate(self):
147
166
# Make sure pull --overwrite overwrites
453
472
out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
454
473
self.assertContainsRe(err,
455
474
"(?m)Fetching into experimental format")
476
def test_pull_show_base(self):
477
"""bzr pull supports --show-base
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()
485
f = open(pathjoin('a', 'hello'),'wt')
490
f = open(pathjoin('b', 'hello'),'wt')
494
out,err=self.run_bzr(['pull','-d','b','a','--show-base'])
496
# check for message here
497
self.assertEqual(err,
498
' M hello\nText conflict in hello\n1 conflicts encountered.\n')
500
self.assertEqualDiff('<<<<<<< TREE\n'
501
'fie||||||| BASE-REVISION\n'
503
'fee>>>>>>> MERGE-SOURCE\n',
504
open(pathjoin('b', 'hello')).read())
506
def test_pull_show_base_working_tree_only(self):
507
"""--show-base only allowed if there's a working tree
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'))
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', ''))