120
118
"""Pull some changes from one branch to another."""
121
119
a_tree = self.example_branch('a')
122
120
self.build_tree_contents([
123
('a/hello2', b'foo'),
124
('a/goodbye2', b'baz')])
122
('a/goodbye2', 'baz')])
125
123
a_tree.add('hello2')
126
124
a_tree.commit(message="setup")
127
125
a_tree.add('goodbye2')
128
126
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()
128
b_tree = a_tree.bzrdir.sprout('b',
129
revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
132
130
self.run_bzr('pull -r 2', working_dir='b')
133
131
a = branch.Branch.open('a')
134
132
b = branch.Branch.open('b')
135
self.assertEqual(a.revno(), 4)
136
self.assertEqual(b.revno(), 2)
133
self.assertEqual(a.revno(),4)
134
self.assertEqual(b.revno(),2)
137
135
self.run_bzr('pull -r 3', working_dir='b')
138
self.assertEqual(b.revno(), 3)
136
self.assertEqual(b.revno(),3)
139
137
self.run_bzr('pull -r 4', working_dir='b')
140
138
self.assertEqual(a.last_revision(), b.last_revision())
146
144
# Make a source, sprout a target off it
147
145
builder = self.make_branch_builder('source')
148
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(
146
source = fixtures.build_branch_with_non_ancestral_rev(builder)
150
147
source.get_config_stack().set('branch.fetch_tags', True)
151
target_bzrdir = source.controldir.sprout('target')
152
source.tags.set_tag('tag-a', rev2)
148
target_bzrdir = source.bzrdir.sprout('target')
149
source.tags.set_tag('tag-a', 'rev-2')
153
150
# Pull from source
154
151
self.run_bzr('pull -d target source')
155
152
target = target_bzrdir.open_branch()
156
153
# 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)
154
self.assertEqual('rev-2', target.tags.lookup_tag('tag-a'))
155
target.repository.get_revision('rev-2')
160
157
def test_overwrite_uptodate(self):
161
158
# Make sure pull --overwrite overwrites
162
159
# even if the target branch has merged
163
160
# everything already.
164
161
a_tree = self.make_branch_and_tree('a')
165
self.build_tree_contents([('a/foo', b'original\n')])
162
self.build_tree_contents([('a/foo', 'original\n')])
166
163
a_tree.add('foo')
167
164
a_tree.commit(message='initial commit')
169
b_tree = a_tree.controldir.sprout('b').open_workingtree()
166
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
171
self.build_tree_contents([('a/foo', b'changed\n')])
168
self.build_tree_contents([('a/foo', 'changed\n')])
172
169
a_tree.commit(message='later change')
174
self.build_tree_contents([('a/foo', b'a third change')])
171
self.build_tree_contents([('a/foo', 'a third change')])
175
172
a_tree.commit(message='a third change')
177
174
self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
190
187
# Make sure pull --overwrite sets the revision-history
191
188
# to be identical to the pull source, even if we have convergence
192
189
a_tree = self.make_branch_and_tree('a')
193
self.build_tree_contents([('a/foo', b'original\n')])
190
self.build_tree_contents([('a/foo', 'original\n')])
194
191
a_tree.add('foo')
195
192
a_tree.commit(message='initial commit')
197
b_tree = a_tree.controldir.sprout('b').open_workingtree()
194
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
199
self.build_tree_contents([('a/foo', b'changed\n')])
196
self.build_tree_contents([('a/foo', 'changed\n')])
200
197
a_tree.commit(message='later change')
202
self.build_tree_contents([('a/foo', b'a third change')])
199
self.build_tree_contents([('a/foo', 'a third change')])
203
200
a_tree.commit(message='a third change')
205
202
self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
264
261
t.delete('branch_b/d')
265
262
self.run_bzr('pull', working_dir='branch_b')
266
263
# Refresh the branch object as 'pull' modified it
267
branch_b = branch_b.controldir.open_branch()
264
branch_b = branch_b.bzrdir.open_branch()
268
265
self.assertEqual(branch_b.get_parent(), parent)
269
266
# test explicit --remember
270
267
self.run_bzr('pull ../branch_c --remember', working_dir='branch_b')
271
268
# Refresh the branch object as 'pull' modified it
272
branch_b = branch_b.controldir.open_branch()
273
self.assertEqual(branch_c.controldir.root_transport.base,
269
branch_b = branch_b.bzrdir.open_branch()
270
self.assertEqual(branch_c.bzrdir.root_transport.base,
274
271
branch_b.get_parent())
276
273
def test_pull_bundle(self):
277
from breezy.bzr.testament import Testament
274
from brzlib.testament import Testament
278
275
# Build up 2 trees and prepare for a pull
279
276
tree_a = self.make_branch_and_tree('branch_a')
280
277
with open('branch_a/a', 'wb') as f:
283
280
tree_a.commit('message')
285
tree_b = tree_a.controldir.sprout('branch_b').open_workingtree()
282
tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
287
284
# Make a change to 'a' that 'b' can pull
288
285
with open('branch_a/a', 'wb') as f:
289
f.write(b'hey there')
290
287
tree_a.commit('message')
292
289
# Create the bundle for 'b' to pull
326
323
self.assertNotContainsRe(out, 'foo')
328
325
def test_pull_quiet(self):
329
"""Check that brz pull --quiet does not print anything"""
326
"""Check that bzr pull --quiet does not print anything"""
330
327
tree_a = self.make_branch_and_tree('tree_a')
331
328
self.build_tree(['tree_a/foo'])
332
329
tree_a.add('foo')
333
330
revision_id = tree_a.commit('bar')
334
tree_b = tree_a.controldir.sprout('tree_b').open_workingtree()
331
tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
335
332
out, err = self.run_bzr('pull --quiet -d tree_b')
336
333
self.assertEqual(out, '')
337
334
self.assertEqual(err, '')
347
344
def test_pull_from_directory_service(self):
348
345
source = self.make_branch_and_tree('source')
349
346
source.commit('commit 1')
350
target = source.controldir.sprout('target').open_workingtree()
347
target = source.bzrdir.sprout('target').open_workingtree()
351
348
source_last = source.commit('commit 2')
353
349
class FooService(object):
354
350
"""A directory service that always returns source"""
356
def look_up(self, name, url, purpose=None):
352
def look_up(self, name, url):
358
354
directories.register('foo:', FooService, 'Testing directory service')
359
355
self.addCleanup(directories.remove, 'foo:')
381
377
self.setup_smart_server_with_call_log()
382
378
parent = self.make_branch_and_tree('parent')
383
379
parent.commit(message='first commit')
384
child = parent.controldir.sprout('child').open_workingtree()
380
child = parent.bzrdir.sprout('child').open_workingtree()
385
381
child.commit(message='second commit')
386
382
checkout = parent.branch.create_checkout('checkout')
387
383
self.run_bzr(['pull', self.get_url('child')], working_dir='checkout')
389
385
def test_pull_smart_stacked_streaming_acceptance(self):
390
"""'brz pull -r 123' works on stacked, smart branches, even when the
386
"""'bzr pull -r 123' works on stacked, smart branches, even when the
391
387
revision specified by the revno is only present in the fallback
400
396
parent = self.make_branch_and_tree('parent', format='1.9')
401
397
parent.commit(message='first commit')
402
398
parent.commit(message='second commit')
403
local = parent.controldir.sprout('local').open_workingtree()
399
local = parent.bzrdir.sprout('local').open_workingtree()
404
400
local.commit(message='local commit')
405
401
local.branch.create_clone_on_transport(
406
402
self.get_transport('stacked'), stacked_on=self.get_url('parent'))
407
403
empty = self.make_branch_and_tree('empty', format='1.9')
408
404
self.reset_smart_call_log()
409
405
self.run_bzr(['pull', '-r', '1', self.get_url('stacked')],
411
407
# This figure represent the amount of work to perform this use case. It
412
408
# is entirely ok to reduce this number if a test fails due to rpc_count
413
409
# being too low. If rpc_count increases, more network roundtrips have
414
410
# become necessary for this use case. Please do not adjust this number
415
411
# upwards without agreement from bzr's network support maintainers.
416
self.assertLength(20, self.hpss_calls)
412
self.assertLength(19, self.hpss_calls)
417
413
self.assertLength(1, self.hpss_connections)
418
414
remote = branch.Branch.open('stacked')
419
415
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
452
448
self.assertIsInstance(from_tree.branch, remote.RemoteBranch)
453
449
from_tree.commit(message='first commit')
454
450
out, err = self.run_bzr(['pull', '-d', 'to',
455
from_tree.branch.controldir.root_transport.base])
451
from_tree.branch.bzrdir.root_transport.base])
456
452
self.assertContainsRe(err,
457
"(?m)Doing on-the-fly conversion")
453
"(?m)Doing on-the-fly conversion")
459
455
def test_pull_to_experimental_format_warning(self):
460
456
"""You get a warning for pulling into experimental formats.
462
from_tree = self.make_branch_and_tree(
463
'from', format='development-subtree')
458
from_tree = self.make_branch_and_tree('from', format='development-subtree')
464
459
to_tree = self.make_branch_and_tree('to', format='development-subtree')
465
460
from_tree.commit(message='first commit')
466
461
out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
467
462
self.assertContainsRe(err,
468
"(?m)Fetching into experimental format")
463
"(?m)Fetching into experimental format")
470
465
def test_pull_cross_to_experimental_format_warning(self):
471
466
"""You get a warning for pulling into experimental formats.
475
470
from_tree.commit(message='first commit')
476
471
out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
477
472
self.assertContainsRe(err,
478
"(?m)Fetching into experimental format")
473
"(?m)Fetching into experimental format")
480
475
def test_pull_show_base(self):
481
"""brz pull supports --show-base
476
"""bzr pull supports --show-base
483
478
see https://bugs.launchpad.net/bzr/+bug/202374"""
484
479
# create two trees with conflicts, setup conflict, check that
485
480
# conflicted file looks correct
486
481
a_tree = self.example_branch('a')
487
b_tree = a_tree.controldir.sprout('b').open_workingtree()
482
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
489
with open(osutils.pathjoin('a', 'hello'), 'wt') as f:
484
with open(osutils.pathjoin('a', 'hello'),'wt') as f:
491
486
a_tree.commit('fee')
493
with open(osutils.pathjoin('b', 'hello'), 'wt') as f:
488
with open(osutils.pathjoin('b', 'hello'),'wt') as f:
496
out, err = self.run_bzr(['pull', '-d', 'b', 'a', '--show-base'])
491
out,err=self.run_bzr(['pull','-d','b','a','--show-base'])
498
493
# check for message here
499
494
self.assertEqual(
520
515
"""pulling tags with conflicts will change the exit code"""
521
516
# create a branch, see that --show-base fails
522
517
from_tree = self.make_branch_and_tree('from')
523
from_tree.branch.tags.set_tag("mytag", b"somerevid")
518
from_tree.branch.tags.set_tag("mytag", "somerevid")
524
519
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)
520
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
521
out = self.run_bzr(['pull','-d','to','from'],retcode=1)
527
522
self.assertEqual(out,
528
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
523
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
530
525
def test_pull_tag_notification(self):
531
526
"""pulling tags with conflicts will change the exit code"""
532
527
# create a branch, see that --show-base fails
533
528
from_tree = self.make_branch_and_tree('from')
534
from_tree.branch.tags.set_tag("mytag", b"somerevid")
529
from_tree.branch.tags.set_tag("mytag", "somerevid")
535
530
to_tree = self.make_branch_and_tree('to')
536
531
out = self.run_bzr(['pull', '-d', 'to', 'from'])
537
532
self.assertEqual(out,
538
('1 tag(s) updated.\n', ''))
533
('1 tag(s) updated.\n', ''))
540
535
def test_overwrite_tags(self):
541
536
"""--overwrite-tags only overwrites tags, not revisions."""
542
537
from_tree = self.make_branch_and_tree('from')
543
from_tree.branch.tags.set_tag("mytag", b"somerevid")
538
from_tree.branch.tags.set_tag("mytag", "somerevid")
544
539
to_tree = self.make_branch_and_tree('to')
545
to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
540
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
546
541
revid1 = to_tree.commit('my commit')
547
542
out = self.run_bzr(['pull', '-d', 'to', 'from'], retcode=1)
548
543
self.assertEqual(out,
549
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
544
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
550
545
out = self.run_bzr(['pull', '-d', 'to', '--overwrite-tags', 'from'])
551
546
self.assertEqual(out, ('1 tag(s) updated.\n', ''))
553
548
self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
555
550
self.assertEqual(to_tree.branch.last_revision(), revid1)
557
552
def test_pull_tag_overwrite(self):
558
553
"""pulling tags with --overwrite only reports changed tags."""
559
554
# create a branch, see that --show-base fails
560
555
from_tree = self.make_branch_and_tree('from')
561
from_tree.branch.tags.set_tag("mytag", b"somerevid")
556
from_tree.branch.tags.set_tag("mytag", "somerevid")
562
557
to_tree = self.make_branch_and_tree('to')
563
to_tree.branch.tags.set_tag("mytag", b"somerevid")
558
to_tree.branch.tags.set_tag("mytag", "somerevid")
564
559
out = self.run_bzr(['pull', '--overwrite', '-d', 'to', 'from'])
565
560
self.assertEqual(out,
566
('No revisions or tags to pull.\n', ''))
561
('No revisions or tags to pull.\n', ''))
569
564
class TestPullOutput(script.TestCaseWithTransportAndScript):
571
566
def test_pull_log_format(self):
572
567
self.run_script("""
574
569
Created a standalone tree (format: 2a)
576
571
$ echo foo > file
579
$ brz commit -m 'we need some foo'
574
$ bzr commit -m 'we need some foo'
580
575
2>Committing to:...trunk/
582
577
2>Committed revision 1.
585
580
Created a standalone tree (format: 2a)
587
$ brz pull -v ../trunk -Olog_format=line
582
$ bzr pull -v ../trunk -Olog_format=line
588
583
Now on revision 1.
590
585
1: jrandom@example.com ...we need some foo