45
45
def example_branch(self, path='.'):
46
46
tree = self.make_branch_and_tree(path)
47
47
self.build_tree_contents([
48
(osutils.pathjoin(path, 'hello'), b'foo'),
49
(osutils.pathjoin(path, 'goodbye'), b'baz')])
48
(osutils.pathjoin(path, 'hello'), 'foo'),
49
(osutils.pathjoin(path, 'goodbye'), 'baz')])
51
51
tree.commit(message='setup')
52
52
tree.add('goodbye')
120
120
"""Pull some changes from one branch to another."""
121
121
a_tree = self.example_branch('a')
122
122
self.build_tree_contents([
123
('a/hello2', b'foo'),
124
('a/goodbye2', b'baz')])
124
('a/goodbye2', 'baz')])
125
125
a_tree.add('hello2')
126
126
a_tree.commit(message="setup")
127
127
a_tree.add('goodbye2')
128
128
a_tree.commit(message="setup")
130
b_tree = a_tree.controldir.sprout(
131
'b', revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
130
b_tree = a_tree.controldir.sprout('b',
131
revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
132
132
self.run_bzr('pull -r 2', working_dir='b')
133
133
a = branch.Branch.open('a')
134
134
b = branch.Branch.open('b')
135
self.assertEqual(a.revno(), 4)
136
self.assertEqual(b.revno(), 2)
135
self.assertEqual(a.revno(),4)
136
self.assertEqual(b.revno(),2)
137
137
self.run_bzr('pull -r 3', working_dir='b')
138
self.assertEqual(b.revno(), 3)
138
self.assertEqual(b.revno(),3)
139
139
self.run_bzr('pull -r 4', working_dir='b')
140
140
self.assertEqual(a.last_revision(), b.last_revision())
146
146
# Make a source, sprout a target off it
147
147
builder = self.make_branch_builder('source')
148
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(
148
source = fixtures.build_branch_with_non_ancestral_rev(builder)
150
149
source.get_config_stack().set('branch.fetch_tags', True)
151
150
target_bzrdir = source.controldir.sprout('target')
152
source.tags.set_tag('tag-a', rev2)
151
source.tags.set_tag('tag-a', 'rev-2')
153
152
# Pull from source
154
153
self.run_bzr('pull -d target source')
155
154
target = target_bzrdir.open_branch()
156
155
# The tag is present, and so is its revision.
157
self.assertEqual(rev2, target.tags.lookup_tag('tag-a'))
158
target.repository.get_revision(rev2)
156
self.assertEqual('rev-2', target.tags.lookup_tag('tag-a'))
157
target.repository.get_revision('rev-2')
160
159
def test_overwrite_uptodate(self):
161
160
# Make sure pull --overwrite overwrites
162
161
# even if the target branch has merged
163
162
# everything already.
164
163
a_tree = self.make_branch_and_tree('a')
165
self.build_tree_contents([('a/foo', b'original\n')])
164
self.build_tree_contents([('a/foo', 'original\n')])
166
165
a_tree.add('foo')
167
166
a_tree.commit(message='initial commit')
169
168
b_tree = a_tree.controldir.sprout('b').open_workingtree()
171
self.build_tree_contents([('a/foo', b'changed\n')])
170
self.build_tree_contents([('a/foo', 'changed\n')])
172
171
a_tree.commit(message='later change')
174
self.build_tree_contents([('a/foo', b'a third change')])
173
self.build_tree_contents([('a/foo', 'a third change')])
175
174
a_tree.commit(message='a third change')
177
176
self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
190
189
# Make sure pull --overwrite sets the revision-history
191
190
# to be identical to the pull source, even if we have convergence
192
191
a_tree = self.make_branch_and_tree('a')
193
self.build_tree_contents([('a/foo', b'original\n')])
192
self.build_tree_contents([('a/foo', 'original\n')])
194
193
a_tree.add('foo')
195
194
a_tree.commit(message='initial commit')
197
196
b_tree = a_tree.controldir.sprout('b').open_workingtree()
199
self.build_tree_contents([('a/foo', b'changed\n')])
198
self.build_tree_contents([('a/foo', 'changed\n')])
200
199
a_tree.commit(message='later change')
202
self.build_tree_contents([('a/foo', b'a third change')])
201
self.build_tree_contents([('a/foo', 'a third change')])
203
202
a_tree.commit(message='a third change')
205
204
self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
349
348
source.commit('commit 1')
350
349
target = source.controldir.sprout('target').open_workingtree()
351
350
source_last = source.commit('commit 2')
353
351
class FooService(object):
354
352
"""A directory service that always returns source"""
356
def look_up(self, name, url, purpose=None):
354
def look_up(self, name, url):
358
356
directories.register('foo:', FooService, 'Testing directory service')
359
357
self.addCleanup(directories.remove, 'foo:')
407
405
empty = self.make_branch_and_tree('empty', format='1.9')
408
406
self.reset_smart_call_log()
409
407
self.run_bzr(['pull', '-r', '1', self.get_url('stacked')],
411
409
# This figure represent the amount of work to perform this use case. It
412
410
# is entirely ok to reduce this number if a test fails due to rpc_count
413
411
# being too low. If rpc_count increases, more network roundtrips have
414
412
# become necessary for this use case. Please do not adjust this number
415
413
# upwards without agreement from bzr's network support maintainers.
416
self.assertLength(20, self.hpss_calls)
414
self.assertLength(19, self.hpss_calls)
417
415
self.assertLength(1, self.hpss_connections)
418
416
remote = branch.Branch.open('stacked')
419
417
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
452
450
self.assertIsInstance(from_tree.branch, remote.RemoteBranch)
453
451
from_tree.commit(message='first commit')
454
452
out, err = self.run_bzr(['pull', '-d', 'to',
455
from_tree.branch.controldir.root_transport.base])
453
from_tree.branch.controldir.root_transport.base])
456
454
self.assertContainsRe(err,
457
"(?m)Doing on-the-fly conversion")
455
"(?m)Doing on-the-fly conversion")
459
457
def test_pull_to_experimental_format_warning(self):
460
458
"""You get a warning for pulling into experimental formats.
462
from_tree = self.make_branch_and_tree(
463
'from', format='development-subtree')
460
from_tree = self.make_branch_and_tree('from', format='development-subtree')
464
461
to_tree = self.make_branch_and_tree('to', format='development-subtree')
465
462
from_tree.commit(message='first commit')
466
463
out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
467
464
self.assertContainsRe(err,
468
"(?m)Fetching into experimental format")
465
"(?m)Fetching into experimental format")
470
467
def test_pull_cross_to_experimental_format_warning(self):
471
468
"""You get a warning for pulling into experimental formats.
486
483
a_tree = self.example_branch('a')
487
484
b_tree = a_tree.controldir.sprout('b').open_workingtree()
489
with open(osutils.pathjoin('a', 'hello'), 'wt') as f:
486
with open(osutils.pathjoin('a', 'hello'),'wt') as f:
491
488
a_tree.commit('fee')
493
with open(osutils.pathjoin('b', 'hello'), 'wt') as f:
490
with open(osutils.pathjoin('b', 'hello'),'wt') as f:
496
out, err = self.run_bzr(['pull', '-d', 'b', 'a', '--show-base'])
493
out,err=self.run_bzr(['pull','-d','b','a','--show-base'])
498
495
# check for message here
499
496
self.assertEqual(
520
517
"""pulling tags with conflicts will change the exit code"""
521
518
# create a branch, see that --show-base fails
522
519
from_tree = self.make_branch_and_tree('from')
523
from_tree.branch.tags.set_tag("mytag", b"somerevid")
520
from_tree.branch.tags.set_tag("mytag", "somerevid")
524
521
to_tree = self.make_branch_and_tree('to')
525
to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
526
out = self.run_bzr(['pull', '-d', 'to', 'from'], retcode=1)
522
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
523
out = self.run_bzr(['pull','-d','to','from'],retcode=1)
527
524
self.assertEqual(out,
528
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
525
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
530
527
def test_pull_tag_notification(self):
531
528
"""pulling tags with conflicts will change the exit code"""
532
529
# create a branch, see that --show-base fails
533
530
from_tree = self.make_branch_and_tree('from')
534
from_tree.branch.tags.set_tag("mytag", b"somerevid")
531
from_tree.branch.tags.set_tag("mytag", "somerevid")
535
532
to_tree = self.make_branch_and_tree('to')
536
533
out = self.run_bzr(['pull', '-d', 'to', 'from'])
537
534
self.assertEqual(out,
538
('1 tag(s) updated.\n', ''))
535
('1 tag(s) updated.\n', ''))
540
537
def test_overwrite_tags(self):
541
538
"""--overwrite-tags only overwrites tags, not revisions."""
542
539
from_tree = self.make_branch_and_tree('from')
543
from_tree.branch.tags.set_tag("mytag", b"somerevid")
540
from_tree.branch.tags.set_tag("mytag", "somerevid")
544
541
to_tree = self.make_branch_and_tree('to')
545
to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
542
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
546
543
revid1 = to_tree.commit('my commit')
547
544
out = self.run_bzr(['pull', '-d', 'to', 'from'], retcode=1)
548
545
self.assertEqual(out,
549
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
546
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
550
547
out = self.run_bzr(['pull', '-d', 'to', '--overwrite-tags', 'from'])
551
548
self.assertEqual(out, ('1 tag(s) updated.\n', ''))
553
550
self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
555
552
self.assertEqual(to_tree.branch.last_revision(), revid1)
557
554
def test_pull_tag_overwrite(self):
558
555
"""pulling tags with --overwrite only reports changed tags."""
559
556
# create a branch, see that --show-base fails
560
557
from_tree = self.make_branch_and_tree('from')
561
from_tree.branch.tags.set_tag("mytag", b"somerevid")
558
from_tree.branch.tags.set_tag("mytag", "somerevid")
562
559
to_tree = self.make_branch_and_tree('to')
563
to_tree.branch.tags.set_tag("mytag", b"somerevid")
560
to_tree.branch.tags.set_tag("mytag", "somerevid")
564
561
out = self.run_bzr(['pull', '--overwrite', '-d', 'to', 'from'])
565
562
self.assertEqual(out,
566
('No revisions or tags to pull.\n', ''))
563
('No revisions or tags to pull.\n', ''))
569
566
class TestPullOutput(script.TestCaseWithTransportAndScript):