23
23
from bzrlib import (
29
from bzrlib.branch import Branch
34
30
from bzrlib.directory_service import directories
31
from bzrlib.osutils import pathjoin
35
32
from bzrlib.tests import (
34
TestCaseWithTransport,
41
class TestPull(tests.TestCaseWithTransport):
36
from bzrlib.uncommit import uncommit
37
from bzrlib.workingtree import WorkingTree
40
class TestPull(TestCaseWithTransport):
43
42
def example_branch(self, path='.'):
44
43
tree = self.make_branch_and_tree(path)
45
44
self.build_tree_contents([
46
(osutils.pathjoin(path, 'hello'), 'foo'),
47
(osutils.pathjoin(path, 'goodbye'), 'baz')])
45
(pathjoin(path, 'hello'), 'foo'),
46
(pathjoin(path, 'goodbye'), 'baz')])
49
48
tree.commit(message='setup')
50
49
tree.add('goodbye')
54
53
def test_pull(self):
55
54
"""Pull changes from one branch to another."""
56
55
a_tree = self.example_branch('a')
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')
57
self.run_bzr('pull', retcode=3)
58
self.run_bzr('missing', retcode=3)
59
self.run_bzr('missing .')
60
self.run_bzr('missing')
62
61
# this will work on windows because we check for the same branch
63
62
# in pull - if it fails, it is a regression
64
self.run_bzr('pull', working_dir='a')
65
self.run_bzr('pull /', retcode=3, working_dir='a')
64
self.run_bzr('pull /', retcode=3)
66
65
if sys.platform not in ('win32', 'cygwin'):
67
self.run_bzr('pull', working_dir='a')
69
69
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
70
self.run_bzr('pull', working_dir='b')
72
73
b_tree.add('subdir')
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())
74
b_tree.commit(message='blah', allow_pointless=True)
79
self.assertEqual(a.revision_history(), b.revision_history()[:-1])
82
self.run_bzr('pull ../b')
83
self.assertEqual(a.revision_history(), b.revision_history())
82
84
a_tree.commit(message='blah2', allow_pointless=True)
83
85
b_tree.commit(message='blah3', allow_pointless=True)
85
self.run_bzr('pull ../a', retcode=3, working_dir='b')
88
self.run_bzr('pull ../a', retcode=3)
86
90
b_tree.bzrdir.sprout('overwriteme')
87
self.run_bzr('pull --overwrite ../a', working_dir='overwriteme')
88
overwritten = branch.Branch.open('overwriteme')
89
self.assertEqual(overwritten.last_revision(),
91
os.chdir('overwriteme')
92
self.run_bzr('pull --overwrite ../a')
93
overwritten = Branch.open('.')
94
self.assertEqual(overwritten.revision_history(),
91
96
a_tree.merge_from_branch(b_tree.branch)
92
97
a_tree.commit(message="blah4", allow_pointless=True)
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]
98
os.chdir('../b/subdir')
99
self.run_bzr('pull ../../a')
100
self.assertEqual(a.revision_history()[-1], b.revision_history()[-1])
101
sub_tree = WorkingTree.open_containing('.')[0]
97
102
sub_tree.commit(message="blah5", allow_pointless=True)
98
103
sub_tree.commit(message="blah6", allow_pointless=True)
99
self.run_bzr('pull ../a', working_dir='b')
105
self.run_bzr('pull ../a')
100
107
a_tree.commit(message="blah7", allow_pointless=True)
101
108
a_tree.merge_from_branch(b_tree.branch)
102
109
a_tree.commit(message="blah8", allow_pointless=True)
103
self.run_bzr('pull ../b', working_dir='a')
104
self.run_bzr('pull ../b', working_dir='a')
110
self.run_bzr('pull ../b')
111
self.run_bzr('pull ../b')
106
113
def test_pull_dash_d(self):
107
114
self.example_branch('a')
128
135
b_tree = a_tree.bzrdir.sprout('b',
129
136
revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
130
self.run_bzr('pull -r 2', working_dir='b')
131
a = branch.Branch.open('a')
132
b = branch.Branch.open('b')
138
self.run_bzr('pull -r 2')
139
a = Branch.open('../a')
133
141
self.assertEqual(a.revno(),4)
134
142
self.assertEqual(b.revno(),2)
135
self.run_bzr('pull -r 3', working_dir='b')
143
self.run_bzr('pull -r 3')
136
144
self.assertEqual(b.revno(),3)
137
self.run_bzr('pull -r 4', working_dir='b')
138
self.assertEqual(a.last_revision(), b.last_revision())
145
self.run_bzr('pull -r 4')
146
self.assertEqual(a.revision_history(), b.revision_history())
140
148
def test_pull_tags(self):
141
149
"""Tags are updated by pull, and revisions named in those tags are
171
178
self.build_tree_contents([('a/foo', 'a third change')])
172
179
a_tree.commit(message='a third change')
174
self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
181
rev_history_a = a_tree.branch.revision_history()
182
self.assertEqual(len(rev_history_a), 3)
176
184
b_tree.merge_from_branch(a_tree.branch)
177
185
b_tree.commit(message='merge')
179
self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
181
self.run_bzr('pull --overwrite ../a', working_dir='b')
182
(last_revinfo_b) = b_tree.branch.last_revision_info()
183
self.assertEqual(last_revinfo_b[0], 3)
184
self.assertEqual(last_revinfo_b[1], a_tree.branch.last_revision())
187
self.assertEqual(len(b_tree.branch.revision_history()), 2)
190
self.run_bzr('pull --overwrite ../a')
191
rev_history_b = b_tree.branch.revision_history()
192
self.assertEqual(len(rev_history_b), 3)
194
self.assertEqual(rev_history_b, rev_history_a)
186
196
def test_overwrite_children(self):
187
197
# Make sure pull --overwrite sets the revision-history
199
209
self.build_tree_contents([('a/foo', 'a third change')])
200
210
a_tree.commit(message='a third change')
202
self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
212
self.assertEqual(len(a_tree.branch.revision_history()), 3)
204
214
b_tree.merge_from_branch(a_tree.branch)
205
215
b_tree.commit(message='merge')
207
self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
217
self.assertEqual(len(b_tree.branch.revision_history()), 2)
209
219
self.build_tree_contents([('a/foo', 'a fourth change\n')])
210
220
a_tree.commit(message='a fourth change')
212
rev_info_a = a_tree.branch.last_revision_info()
213
self.assertEqual(rev_info_a[0], 4)
222
rev_history_a = a_tree.branch.revision_history()
223
self.assertEqual(len(rev_history_a), 4)
215
225
# With convergence, we could just pull over the
216
226
# new change, but with --overwrite, we want to switch our history
217
self.run_bzr('pull --overwrite ../a', working_dir='b')
218
rev_info_b = b_tree.branch.last_revision_info()
219
self.assertEqual(rev_info_b[0], 4)
220
self.assertEqual(rev_info_b, rev_info_a)
228
self.run_bzr('pull --overwrite ../a')
229
rev_history_b = b_tree.branch.revision_history()
230
self.assertEqual(len(rev_history_b), 4)
232
self.assertEqual(rev_history_b, rev_history_a)
222
234
def test_pull_remember(self):
223
235
"""Pull changes from one branch to another and test parent location."""
224
t = self.get_transport()
236
transport = self.get_transport()
225
237
tree_a = self.make_branch_and_tree('branch_a')
226
238
branch_a = tree_a.branch
227
239
self.build_tree(['branch_a/a'])
236
248
tree_a.commit('commit b')
238
250
parent = branch_b.get_parent()
239
branch_b = branch.Branch.open('branch_b')
240
251
branch_b.set_parent(None)
241
252
self.assertEqual(None, branch_b.get_parent())
242
253
# test pull for failure without parent set
243
out = self.run_bzr('pull', retcode=3, working_dir='branch_b')
255
out = self.run_bzr('pull', retcode=3)
244
256
self.assertEqual(out,
245
257
('','bzr: ERROR: No pull location known or specified.\n'))
246
258
# test implicit --remember when no parent set, this pull conflicts
247
self.build_tree(['branch_b/d'])
259
self.build_tree(['d'])
249
261
tree_b.commit('commit d')
250
out = self.run_bzr('pull ../branch_a', retcode=3,
251
working_dir='branch_b')
262
out = self.run_bzr('pull ../branch_a', retcode=3)
252
263
self.assertEqual(out,
253
264
('','bzr: ERROR: These branches have diverged.'
254
265
' Use the missing command to see how.\n'
255
266
'Use the merge command to reconcile them.\n'))
256
tree_b = tree_b.bzrdir.open_workingtree()
257
branch_b = tree_b.branch
258
self.assertEqual(parent, branch_b.get_parent())
267
self.assertEqual(branch_b.get_parent(), parent)
259
268
# test implicit --remember after resolving previous failure
260
uncommit.uncommit(branch=branch_b, tree=tree_b)
261
t.delete('branch_b/d')
262
self.run_bzr('pull', working_dir='branch_b')
263
# Refresh the branch object as 'pull' modified it
264
branch_b = branch_b.bzrdir.open_branch()
269
uncommit(branch=branch_b, tree=tree_b)
270
transport.delete('branch_b/d')
265
272
self.assertEqual(branch_b.get_parent(), parent)
266
273
# test explicit --remember
267
self.run_bzr('pull ../branch_c --remember', working_dir='branch_b')
268
# Refresh the branch object as 'pull' modified it
269
branch_b = branch_b.bzrdir.open_branch()
270
self.assertEqual(branch_c.bzrdir.root_transport.base,
271
branch_b.get_parent())
274
self.run_bzr('pull ../branch_c --remember')
275
self.assertEqual(branch_b.get_parent(),
276
branch_c.bzrdir.root_transport.base)
273
278
def test_pull_bundle(self):
274
279
from bzrlib.testament import Testament
275
280
# Build up 2 trees and prepare for a pull
276
281
tree_a = self.make_branch_and_tree('branch_a')
277
with open('branch_a/a', 'wb') as f:
282
f = open('branch_a/a', 'wb')
280
286
tree_a.commit('message')
282
288
tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
284
290
# Make a change to 'a' that 'b' can pull
285
with open('branch_a/a', 'wb') as f:
291
f = open('branch_a/a', 'wb')
287
294
tree_a.commit('message')
289
296
# Create the bundle for 'b' to pull
290
self.run_bzr('bundle ../branch_b -o ../bundle', working_dir='branch_a')
298
self.run_bzr('bundle ../branch_b -o ../bundle')
292
out, err = self.run_bzr('pull ../bundle', working_dir='branch_b')
300
os.chdir('../branch_b')
301
out, err = self.run_bzr('pull ../bundle')
293
302
self.assertEqual(out,
294
303
'Now on revision 2.\n')
295
304
self.assertEqual(err,
296
305
' M a\nAll changes applied successfully.\n')
298
self.assertEqualDiff(tree_a.branch.last_revision(),
299
tree_b.branch.last_revision())
307
self.assertEqualDiff(tree_a.branch.revision_history(),
308
tree_b.branch.revision_history())
301
310
testament_a = Testament.from_revision(tree_a.branch.repository,
302
311
tree_a.get_parent_ids()[0])
367
376
def test_pull_verbose_uses_default_log(self):
368
377
tree = self.example_branch('source')
369
378
target = self.make_branch_and_tree('target')
370
target.branch.get_config_stack().set('log_format', 'short')
379
target_config = target.branch.get_config()
380
target_config.set_user_option('log_format', 'short')
371
381
out = self.run_bzr('pull -v source -d target')[0]
372
382
self.assertContainsRe(out, r'\n {4}1 .*\n {6}setup\n')
373
383
self.assertNotContainsRe(
374
384
out, r'revno: 1\ncommitter: .*\nbranch nick: source')
376
def test_pull_smart_bound_branch(self):
377
self.setup_smart_server_with_call_log()
378
parent = self.make_branch_and_tree('parent')
379
parent.commit(message='first commit')
380
child = parent.bzrdir.sprout('child').open_workingtree()
381
child.commit(message='second commit')
382
checkout = parent.branch.create_checkout('checkout')
383
self.run_bzr(['pull', self.get_url('child')], working_dir='checkout')
385
386
def test_pull_smart_stacked_streaming_acceptance(self):
386
387
"""'bzr pull -r 123' works on stacked, smart branches, even when the
387
388
revision specified by the revno is only present in the fallback
409
410
# being too low. If rpc_count increases, more network roundtrips have
410
411
# become necessary for this use case. Please do not adjust this number
411
412
# upwards without agreement from bzr's network support maintainers.
412
self.assertLength(19, self.hpss_calls)
413
self.assertLength(1, self.hpss_connections)
414
remote = branch.Branch.open('stacked')
413
self.assertLength(18, self.hpss_calls)
414
remote = Branch.open('stacked')
415
415
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
417
417
def test_pull_cross_format_warning(self):
418
418
"""You get a warning for probably slow cross-format pulls.
481
481
a_tree = self.example_branch('a')
482
482
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
484
with open(osutils.pathjoin('a', 'hello'),'wt') as f:
484
f = open(pathjoin('a', 'hello'),'wt')
486
487
a_tree.commit('fee')
488
with open(osutils.pathjoin('b', 'hello'),'wt') as f:
489
f = open(pathjoin('b', 'hello'),'wt')
491
493
out,err=self.run_bzr(['pull','-d','b','a','--show-base'])
493
495
# check for message here
496
' M hello\nText conflict in hello\n1 conflicts encountered.\n')
496
self.assertEqual(err,
497
' M hello\nText conflict in hello\n1 conflicts encountered.\n')
498
499
self.assertEqualDiff('<<<<<<< TREE\n'
499
500
'fie||||||| BASE-REVISION\n'
501
502
'fee>>>>>>> MERGE-SOURCE\n',
502
open(osutils.pathjoin('b', 'hello')).read())
504
def test_pull_warns_about_show_base_when_no_working_tree(self):
505
"""--show-base is useless if there's no working tree
507
see https://bugs.launchpad.net/bzr/+bug/1022160"""
503
open(pathjoin('b', 'hello')).read())
505
def test_pull_show_base_working_tree_only(self):
506
"""--show-base only allowed if there's a working tree
508
see https://bugs.launchpad.net/bzr/+bug/202374"""
509
# create a branch, see that --show-base fails
508
510
self.make_branch('from')
509
511
self.make_branch('to')
510
out = self.run_bzr(['pull','-d','to','from','--show-base'])
511
self.assertEqual(out, ('No revisions or tags to pull.\n',
512
'No working tree, ignoring --show-base\n'))
512
out=self.run_bzr(['pull','-d','to','from','--show-base'],retcode=3)
513
self.assertEqual(out,
514
('','bzr: ERROR: Need working tree for --show-base.\n'))
514
516
def test_pull_tag_conflicts(self):
515
517
"""pulling tags with conflicts will change the exit code"""
521
523
out = self.run_bzr(['pull','-d','to','from'],retcode=1)
522
524
self.assertEqual(out,
523
525
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
525
def test_pull_tag_notification(self):
526
"""pulling tags with conflicts will change the exit code"""
527
# create a branch, see that --show-base fails
528
from_tree = self.make_branch_and_tree('from')
529
from_tree.branch.tags.set_tag("mytag", "somerevid")
530
to_tree = self.make_branch_and_tree('to')
531
out = self.run_bzr(['pull', '-d', 'to', 'from'])
532
self.assertEqual(out,
533
('1 tag(s) updated.\n', ''))
535
def test_overwrite_tags(self):
536
"""--overwrite-tags only overwrites tags, not revisions."""
537
from_tree = self.make_branch_and_tree('from')
538
from_tree.branch.tags.set_tag("mytag", "somerevid")
539
to_tree = self.make_branch_and_tree('to')
540
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
541
revid1 = to_tree.commit('my commit')
542
out = self.run_bzr(['pull', '-d', 'to', 'from'], retcode=1)
543
self.assertEquals(out,
544
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
545
out = self.run_bzr(['pull', '-d', 'to', '--overwrite-tags', 'from'])
546
self.assertEquals(out, ('1 tag(s) updated.\n', ''))
548
self.assertEquals(to_tree.branch.tags.lookup_tag('mytag'),
550
self.assertEquals(to_tree.branch.last_revision(), revid1)
552
def test_pull_tag_overwrite(self):
553
"""pulling tags with --overwrite only reports changed tags."""
554
# create a branch, see that --show-base fails
555
from_tree = self.make_branch_and_tree('from')
556
from_tree.branch.tags.set_tag("mytag", "somerevid")
557
to_tree = self.make_branch_and_tree('to')
558
to_tree.branch.tags.set_tag("mytag", "somerevid")
559
out = self.run_bzr(['pull', '--overwrite', '-d', 'to', 'from'])
560
self.assertEqual(out,
561
('No revisions or tags to pull.\n', ''))
564
class TestPullOutput(script.TestCaseWithTransportAndScript):
566
def test_pull_log_format(self):
569
Created a standalone tree (format: 2a)
574
$ bzr commit -m 'we need some foo'
575
2>Committing to:...trunk/
577
2>Committed revision 1.
580
Created a standalone tree (format: 2a)
582
$ bzr pull -v ../trunk -Olog_format=line
585
1: jrandom@example.com ...we need some foo
587
2>All changes applied successfully.