45
54
def test_pull(self):
46
55
"""Pull changes from one branch to another."""
47
56
a_tree = self.example_branch('a')
49
self.run_bzr('pull', retcode=3)
50
self.run_bzr('missing', retcode=3)
51
self.run_bzr('missing .')
52
self.run_bzr('missing')
57
base_rev = a_tree.branch.last_revision()
58
self.run_bzr('pull', retcode=3, working_dir='a')
59
self.run_bzr('missing', retcode=3, working_dir='a')
60
self.run_bzr('missing .', working_dir='a')
61
self.run_bzr('missing', working_dir='a')
53
62
# this will work on windows because we check for the same branch
54
63
# in pull - if it fails, it is a regression
56
self.run_bzr('pull /', retcode=3)
64
self.run_bzr('pull', working_dir='a')
65
self.run_bzr('pull /', retcode=3, working_dir='a')
57
66
if sys.platform not in ('win32', 'cygwin'):
67
self.run_bzr('pull', working_dir='a')
61
69
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
70
self.run_bzr('pull', working_dir='b')
65
72
b_tree.add('subdir')
66
b_tree.commit(message='blah', allow_pointless=True)
71
self.assertEqual(a.revision_history(), b.revision_history()[:-1])
74
self.run_bzr('pull ../b')
75
self.assertEqual(a.revision_history(), b.revision_history())
73
new_rev = b_tree.commit(message='blah', allow_pointless=True)
75
a = branch.Branch.open('a')
76
b = branch.Branch.open('b')
77
self.assertEqual(a.last_revision(), base_rev)
78
self.assertEqual(b.last_revision(), new_rev)
80
self.run_bzr('pull ../b', working_dir='a')
81
self.assertEqual(a.last_revision(), b.last_revision())
76
82
a_tree.commit(message='blah2', allow_pointless=True)
77
83
b_tree.commit(message='blah3', allow_pointless=True)
80
self.run_bzr('pull ../a', retcode=3)
85
self.run_bzr('pull ../a', retcode=3, working_dir='b')
82
86
b_tree.bzrdir.sprout('overwriteme')
83
os.chdir('overwriteme')
84
self.run_bzr('pull --overwrite ../a')
85
overwritten = Branch.open('.')
86
self.assertEqual(overwritten.revision_history(),
87
self.run_bzr('pull --overwrite ../a', working_dir='overwriteme')
88
overwritten = branch.Branch.open('overwriteme')
89
self.assertEqual(overwritten.last_revision(),
88
91
a_tree.merge_from_branch(b_tree.branch)
89
92
a_tree.commit(message="blah4", allow_pointless=True)
90
os.chdir('../b/subdir')
91
self.run_bzr('pull ../../a')
92
self.assertEqual(a.revision_history()[-1], b.revision_history()[-1])
93
sub_tree = WorkingTree.open_containing('.')[0]
94
self.run_bzr('pull ../../a', working_dir='b/subdir')
95
self.assertEqual(a.last_revision(), b.last_revision())
96
sub_tree = workingtree.WorkingTree.open_containing('b/subdir')[0]
94
97
sub_tree.commit(message="blah5", allow_pointless=True)
95
98
sub_tree.commit(message="blah6", allow_pointless=True)
97
self.run_bzr('pull ../a')
99
self.run_bzr('pull ../a', working_dir='b')
99
100
a_tree.commit(message="blah7", allow_pointless=True)
100
101
a_tree.merge_from_branch(b_tree.branch)
101
102
a_tree.commit(message="blah8", allow_pointless=True)
102
self.run_bzr('pull ../b')
103
self.run_bzr('pull ../b')
103
self.run_bzr('pull ../b', working_dir='a')
104
self.run_bzr('pull ../b', working_dir='a')
105
106
def test_pull_dash_d(self):
106
107
self.example_branch('a')
337
345
def look_up(self, name, url):
339
347
directories.register('foo:', FooService, 'Testing directory service')
340
self.addCleanup(lambda: directories.remove('foo:'))
348
self.addCleanup(directories.remove, 'foo:')
341
349
self.run_bzr('pull foo:bar -d target')
342
350
self.assertEqual(source_last, target.last_revision())
352
def test_pull_verbose_defaults_to_long(self):
353
tree = self.example_branch('source')
354
target = self.make_branch_and_tree('target')
355
out = self.run_bzr('pull -v source -d target')[0]
356
self.assertContainsRe(out,
357
r'revno: 1\ncommitter: .*\nbranch nick: source')
358
self.assertNotContainsRe(out, r'\n {4}1 .*\n {6}setup\n')
360
def test_pull_verbose_uses_default_log(self):
361
tree = self.example_branch('source')
362
target = self.make_branch_and_tree('target')
363
target_config = target.branch.get_config_stack()
364
target_config.set('log_format', 'short')
365
out = self.run_bzr('pull -v source -d target')[0]
366
self.assertContainsRe(out, r'\n {4}1 .*\n {6}setup\n')
367
self.assertNotContainsRe(
368
out, r'revno: 1\ncommitter: .*\nbranch nick: source')
370
def test_pull_smart_bound_branch(self):
371
self.setup_smart_server_with_call_log()
372
parent = self.make_branch_and_tree('parent')
373
parent.commit(message='first commit')
374
child = parent.bzrdir.sprout('child').open_workingtree()
375
child.commit(message='second commit')
376
checkout = parent.branch.create_checkout('checkout')
377
self.run_bzr(['pull', self.get_url('child')], working_dir='checkout')
379
def test_pull_smart_stacked_streaming_acceptance(self):
380
"""'bzr pull -r 123' works on stacked, smart branches, even when the
381
revision specified by the revno is only present in the fallback
384
See <https://launchpad.net/bugs/380314>
386
self.setup_smart_server_with_call_log()
387
# Make a stacked-on branch with two commits so that the
388
# revision-history can't be determined just by looking at the parent
389
# field in the revision in the stacked repo.
390
parent = self.make_branch_and_tree('parent', format='1.9')
391
parent.commit(message='first commit')
392
parent.commit(message='second commit')
393
local = parent.bzrdir.sprout('local').open_workingtree()
394
local.commit(message='local commit')
395
local.branch.create_clone_on_transport(
396
self.get_transport('stacked'), stacked_on=self.get_url('parent'))
397
empty = self.make_branch_and_tree('empty', format='1.9')
398
self.reset_smart_call_log()
399
self.run_bzr(['pull', '-r', '1', self.get_url('stacked')],
401
# This figure represent the amount of work to perform this use case. It
402
# is entirely ok to reduce this number if a test fails due to rpc_count
403
# being too low. If rpc_count increases, more network roundtrips have
404
# become necessary for this use case. Please do not adjust this number
405
# upwards without agreement from bzr's network support maintainers.
406
self.assertLength(19, self.hpss_calls)
407
self.assertLength(1, self.hpss_connections)
408
remote = branch.Branch.open('stacked')
409
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
411
def test_pull_cross_format_warning(self):
412
"""You get a warning for probably slow cross-format pulls.
414
# this is assumed to be going through InterDifferingSerializer
415
from_tree = self.make_branch_and_tree('from', format='2a')
416
to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
417
from_tree.commit(message='first commit')
418
out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
419
self.assertContainsRe(err,
420
"(?m)Doing on-the-fly conversion")
422
def test_pull_cross_format_warning_no_IDS(self):
423
"""You get a warning for probably slow cross-format pulls.
425
# this simulates what would happen across the network, where
426
# interdifferingserializer is not active
428
debug.debug_flags.add('IDS_never')
429
# TestCase take care of restoring them
431
from_tree = self.make_branch_and_tree('from', format='2a')
432
to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
433
from_tree.commit(message='first commit')
434
out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
435
self.assertContainsRe(err,
436
"(?m)Doing on-the-fly conversion")
438
def test_pull_cross_format_from_network(self):
439
self.setup_smart_server_with_call_log()
440
from_tree = self.make_branch_and_tree('from', format='2a')
441
to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
442
self.assertIsInstance(from_tree.branch, remote.RemoteBranch)
443
from_tree.commit(message='first commit')
444
out, err = self.run_bzr(['pull', '-d', 'to',
445
from_tree.branch.bzrdir.root_transport.base])
446
self.assertContainsRe(err,
447
"(?m)Doing on-the-fly conversion")
449
def test_pull_to_experimental_format_warning(self):
450
"""You get a warning for pulling into experimental formats.
452
from_tree = self.make_branch_and_tree('from', format='development-subtree')
453
to_tree = self.make_branch_and_tree('to', format='development-subtree')
454
from_tree.commit(message='first commit')
455
out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
456
self.assertContainsRe(err,
457
"(?m)Fetching into experimental format")
459
def test_pull_cross_to_experimental_format_warning(self):
460
"""You get a warning for pulling into experimental formats.
462
from_tree = self.make_branch_and_tree('from', format='2a')
463
to_tree = self.make_branch_and_tree('to', format='development-subtree')
464
from_tree.commit(message='first commit')
465
out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
466
self.assertContainsRe(err,
467
"(?m)Fetching into experimental format")
469
def test_pull_show_base(self):
470
"""bzr pull supports --show-base
472
see https://bugs.launchpad.net/bzr/+bug/202374"""
473
# create two trees with conflicts, setup conflict, check that
474
# conflicted file looks correct
475
a_tree = self.example_branch('a')
476
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
478
with open(osutils.pathjoin('a', 'hello'),'wt') as f:
482
with open(osutils.pathjoin('b', 'hello'),'wt') as f:
485
out,err=self.run_bzr(['pull','-d','b','a','--show-base'])
487
# check for message here
490
' M hello\nText conflict in hello\n1 conflicts encountered.\n')
492
self.assertEqualDiff('<<<<<<< TREE\n'
493
'fie||||||| BASE-REVISION\n'
495
'fee>>>>>>> MERGE-SOURCE\n',
496
open(osutils.pathjoin('b', 'hello')).read())
498
def test_pull_show_base_working_tree_only(self):
499
"""--show-base only allowed if there's a working tree
501
see https://bugs.launchpad.net/bzr/+bug/202374"""
502
# create a branch, see that --show-base fails
503
self.make_branch('from')
504
self.make_branch('to')
505
out=self.run_bzr(['pull','-d','to','from','--show-base'],retcode=3)
507
out, ('','bzr: ERROR: Need working tree for --show-base.\n'))
509
def test_pull_tag_conflicts(self):
510
"""pulling tags with conflicts will change the exit code"""
511
# create a branch, see that --show-base fails
512
from_tree = self.make_branch_and_tree('from')
513
from_tree.branch.tags.set_tag("mytag", "somerevid")
514
to_tree = self.make_branch_and_tree('to')
515
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
516
out = self.run_bzr(['pull','-d','to','from'],retcode=1)
517
self.assertEqual(out,
518
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
520
def test_pull_tag_notification(self):
521
"""pulling tags with conflicts will change the exit code"""
522
# create a branch, see that --show-base fails
523
from_tree = self.make_branch_and_tree('from')
524
from_tree.branch.tags.set_tag("mytag", "somerevid")
525
to_tree = self.make_branch_and_tree('to')
526
out = self.run_bzr(['pull', '-d', 'to', 'from'])
527
self.assertEqual(out,
528
('1 tag(s) updated.\n', ''))
530
def test_pull_tag_overwrite(self):
531
"""pulling tags with --overwrite only reports changed tags."""
532
# create a branch, see that --show-base fails
533
from_tree = self.make_branch_and_tree('from')
534
from_tree.branch.tags.set_tag("mytag", "somerevid")
535
to_tree = self.make_branch_and_tree('to')
536
to_tree.branch.tags.set_tag("mytag", "somerevid")
537
out = self.run_bzr(['pull', '--overwrite', '-d', 'to', 'from'])
538
self.assertEqual(out,
539
('No revisions or tags to pull.\n', ''))
542
class TestPullOutput(script.TestCaseWithTransportAndScript):
544
def test_pull_log_format(self):
547
Created a standalone tree (format: 2a)
552
$ bzr commit -m 'we need some foo'
553
2>Committing to:...trunk/
555
2>Committed revision 1.
558
Created a standalone tree (format: 2a)
560
$ bzr pull -v ../trunk -Olog_format=line
563
1: jrandom@example.com ...we need some foo
565
2>All changes applied successfully.