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'), 'foo'),
49
(osutils.pathjoin(path, 'goodbye'), 'baz')])
48
(osutils.pathjoin(path, 'hello'), b'foo'),
49
(osutils.pathjoin(path, 'goodbye'), b'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([
124
('a/goodbye2', 'baz')])
123
('a/hello2', b'foo'),
124
('a/goodbye2', b'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
130
b_tree = a_tree.controldir.sprout(
131
'b', revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
131
'b', 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')
161
162
# even if the target branch has merged
162
163
# everything already.
163
164
a_tree = self.make_branch_and_tree('a')
164
self.build_tree_contents([('a/foo', 'original\n')])
165
self.build_tree_contents([('a/foo', b'original\n')])
165
166
a_tree.add('foo')
166
167
a_tree.commit(message='initial commit')
168
169
b_tree = a_tree.controldir.sprout('b').open_workingtree()
170
self.build_tree_contents([('a/foo', 'changed\n')])
171
self.build_tree_contents([('a/foo', b'changed\n')])
171
172
a_tree.commit(message='later change')
173
self.build_tree_contents([('a/foo', 'a third change')])
174
self.build_tree_contents([('a/foo', b'a third change')])
174
175
a_tree.commit(message='a third change')
176
177
self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
189
190
# Make sure pull --overwrite sets the revision-history
190
191
# to be identical to the pull source, even if we have convergence
191
192
a_tree = self.make_branch_and_tree('a')
192
self.build_tree_contents([('a/foo', 'original\n')])
193
self.build_tree_contents([('a/foo', b'original\n')])
193
194
a_tree.add('foo')
194
195
a_tree.commit(message='initial commit')
196
197
b_tree = a_tree.controldir.sprout('b').open_workingtree()
198
self.build_tree_contents([('a/foo', 'changed\n')])
199
self.build_tree_contents([('a/foo', b'changed\n')])
199
200
a_tree.commit(message='later change')
201
self.build_tree_contents([('a/foo', 'a third change')])
202
self.build_tree_contents([('a/foo', b'a third change')])
202
203
a_tree.commit(message='a third change')
204
205
self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
252
253
out = self.run_bzr('pull ../branch_a', retcode=3,
253
254
working_dir='branch_b')
254
255
self.assertEqual(out,
255
('', 'brz: ERROR: These branches have diverged.'
256
' Use the missing command to see how.\n'
257
'Use the merge command to reconcile them.\n'))
256
('', 'brz: ERROR: These branches have diverged.'
257
' Use the missing command to see how.\n'
258
'Use the merge command to reconcile them.\n'))
258
259
tree_b = tree_b.controldir.open_workingtree()
259
260
branch_b = tree_b.branch
260
261
self.assertEqual(parent, branch_b.get_parent())
348
349
source.commit('commit 1')
349
350
target = source.controldir.sprout('target').open_workingtree()
350
351
source_last = source.commit('commit 2')
351
353
class FooService(object):
352
354
"""A directory service that always returns source"""
354
def look_up(self, name, url):
356
def look_up(self, name, url, purpose=None):
356
358
directories.register('foo:', FooService, 'Testing directory service')
357
359
self.addCleanup(directories.remove, 'foo:')
405
407
empty = self.make_branch_and_tree('empty', format='1.9')
406
408
self.reset_smart_call_log()
407
409
self.run_bzr(['pull', '-r', '1', self.get_url('stacked')],
409
411
# This figure represent the amount of work to perform this use case. It
410
412
# is entirely ok to reduce this number if a test fails due to rpc_count
411
413
# being too low. If rpc_count increases, more network roundtrips have
412
414
# become necessary for this use case. Please do not adjust this number
413
415
# upwards without agreement from bzr's network support maintainers.
414
self.assertLength(19, self.hpss_calls)
416
self.assertLength(20, self.hpss_calls)
415
417
self.assertLength(1, self.hpss_connections)
416
418
remote = branch.Branch.open('stacked')
417
419
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
450
452
self.assertIsInstance(from_tree.branch, remote.RemoteBranch)
451
453
from_tree.commit(message='first commit')
452
454
out, err = self.run_bzr(['pull', '-d', 'to',
453
from_tree.branch.controldir.root_transport.base])
455
from_tree.branch.controldir.root_transport.base])
454
456
self.assertContainsRe(err,
455
"(?m)Doing on-the-fly conversion")
457
"(?m)Doing on-the-fly conversion")
457
459
def test_pull_to_experimental_format_warning(self):
458
460
"""You get a warning for pulling into experimental formats.
460
from_tree = self.make_branch_and_tree('from', format='development-subtree')
462
from_tree = self.make_branch_and_tree(
463
'from', format='development-subtree')
461
464
to_tree = self.make_branch_and_tree('to', format='development-subtree')
462
465
from_tree.commit(message='first commit')
463
466
out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
464
467
self.assertContainsRe(err,
465
"(?m)Fetching into experimental format")
468
"(?m)Fetching into experimental format")
467
470
def test_pull_cross_to_experimental_format_warning(self):
468
471
"""You get a warning for pulling into experimental formats.
517
520
"""pulling tags with conflicts will change the exit code"""
518
521
# create a branch, see that --show-base fails
519
522
from_tree = self.make_branch_and_tree('from')
520
from_tree.branch.tags.set_tag("mytag", "somerevid")
523
from_tree.branch.tags.set_tag("mytag", b"somerevid")
521
524
to_tree = self.make_branch_and_tree('to')
522
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
525
to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
523
526
out = self.run_bzr(['pull', '-d', 'to', 'from'], retcode=1)
524
527
self.assertEqual(out,
525
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
528
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
527
530
def test_pull_tag_notification(self):
528
531
"""pulling tags with conflicts will change the exit code"""
529
532
# create a branch, see that --show-base fails
530
533
from_tree = self.make_branch_and_tree('from')
531
from_tree.branch.tags.set_tag("mytag", "somerevid")
534
from_tree.branch.tags.set_tag("mytag", b"somerevid")
532
535
to_tree = self.make_branch_and_tree('to')
533
536
out = self.run_bzr(['pull', '-d', 'to', 'from'])
534
537
self.assertEqual(out,
535
('1 tag(s) updated.\n', ''))
538
('1 tag(s) updated.\n', ''))
537
540
def test_overwrite_tags(self):
538
541
"""--overwrite-tags only overwrites tags, not revisions."""
539
542
from_tree = self.make_branch_and_tree('from')
540
from_tree.branch.tags.set_tag("mytag", "somerevid")
543
from_tree.branch.tags.set_tag("mytag", b"somerevid")
541
544
to_tree = self.make_branch_and_tree('to')
542
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
545
to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
543
546
revid1 = to_tree.commit('my commit')
544
547
out = self.run_bzr(['pull', '-d', 'to', 'from'], retcode=1)
545
548
self.assertEqual(out,
546
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
549
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
547
550
out = self.run_bzr(['pull', '-d', 'to', '--overwrite-tags', 'from'])
548
551
self.assertEqual(out, ('1 tag(s) updated.\n', ''))
550
553
self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
552
555
self.assertEqual(to_tree.branch.last_revision(), revid1)
554
557
def test_pull_tag_overwrite(self):
555
558
"""pulling tags with --overwrite only reports changed tags."""
556
559
# create a branch, see that --show-base fails
557
560
from_tree = self.make_branch_and_tree('from')
558
from_tree.branch.tags.set_tag("mytag", "somerevid")
561
from_tree.branch.tags.set_tag("mytag", b"somerevid")
559
562
to_tree = self.make_branch_and_tree('to')
560
to_tree.branch.tags.set_tag("mytag", "somerevid")
563
to_tree.branch.tags.set_tag("mytag", b"somerevid")
561
564
out = self.run_bzr(['pull', '--overwrite', '-d', 'to', 'from'])
562
565
self.assertEqual(out,
563
('No revisions or tags to pull.\n', ''))
566
('No revisions or tags to pull.\n', ''))
566
569
class TestPullOutput(script.TestCaseWithTransportAndScript):