68
74
self.run_bzr('pull')
70
76
b_tree.add('subdir')
71
b_tree.commit(message='blah', allow_pointless=True)
77
new_rev = b_tree.commit(message='blah', allow_pointless=True)
74
80
a = Branch.open('a')
75
81
b = Branch.open('b')
76
self.assertEqual(a.revision_history(), b.revision_history()[:-1])
82
self.assertEqual(a.last_revision(), base_rev)
83
self.assertEqual(b.last_revision(), new_rev)
79
86
self.run_bzr('pull ../b')
80
self.assertEqual(a.revision_history(), b.revision_history())
87
self.assertEqual(a.last_revision(), b.last_revision())
81
88
a_tree.commit(message='blah2', allow_pointless=True)
82
89
b_tree.commit(message='blah3', allow_pointless=True)
88
95
os.chdir('overwriteme')
89
96
self.run_bzr('pull --overwrite ../a')
90
97
overwritten = Branch.open('.')
91
self.assertEqual(overwritten.revision_history(),
98
self.assertEqual(overwritten.last_revision(),
93
100
a_tree.merge_from_branch(b_tree.branch)
94
101
a_tree.commit(message="blah4", allow_pointless=True)
95
102
os.chdir('../b/subdir')
96
103
self.run_bzr('pull ../../a')
97
self.assertEqual(a.revision_history()[-1], b.revision_history()[-1])
104
self.assertEqual(a.last_revision(), b.last_revision())
98
105
sub_tree = WorkingTree.open_containing('.')[0]
99
106
sub_tree.commit(message="blah5", allow_pointless=True)
100
107
sub_tree.commit(message="blah6", allow_pointless=True)
140
147
self.run_bzr('pull -r 3')
141
148
self.assertEqual(b.revno(),3)
142
149
self.run_bzr('pull -r 4')
143
self.assertEqual(a.revision_history(), b.revision_history())
150
self.assertEqual(a.last_revision(), b.last_revision())
152
def test_pull_tags(self):
153
"""Tags are updated by pull, and revisions named in those tags are
156
# Make a source, sprout a target off it
157
builder = self.make_branch_builder('source')
158
source = fixtures.build_branch_with_non_ancestral_rev(builder)
159
source.get_config().set_user_option('branch.fetch_tags', 'True')
160
target_bzrdir = source.bzrdir.sprout('target')
161
source.tags.set_tag('tag-a', 'rev-2')
163
self.run_bzr('pull -d target source')
164
target = target_bzrdir.open_branch()
165
# The tag is present, and so is its revision.
166
self.assertEqual('rev-2', target.tags.lookup_tag('tag-a'))
167
target.repository.get_revision('rev-2')
146
169
def test_overwrite_uptodate(self):
147
170
# Make sure pull --overwrite overwrites
160
183
self.build_tree_contents([('a/foo', 'a third change')])
161
184
a_tree.commit(message='a third change')
163
rev_history_a = a_tree.branch.revision_history()
164
self.assertEqual(len(rev_history_a), 3)
186
self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
166
188
b_tree.merge_from_branch(a_tree.branch)
167
189
b_tree.commit(message='merge')
169
self.assertEqual(len(b_tree.branch.revision_history()), 2)
191
self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
172
194
self.run_bzr('pull --overwrite ../a')
173
rev_history_b = b_tree.branch.revision_history()
174
self.assertEqual(len(rev_history_b), 3)
176
self.assertEqual(rev_history_b, rev_history_a)
195
(last_revinfo_b) = b_tree.branch.last_revision_info()
196
self.assertEqual(last_revinfo_b[0], 3)
197
self.assertEqual(last_revinfo_b[1], a_tree.branch.last_revision())
178
199
def test_overwrite_children(self):
179
200
# Make sure pull --overwrite sets the revision-history
191
212
self.build_tree_contents([('a/foo', 'a third change')])
192
213
a_tree.commit(message='a third change')
194
self.assertEqual(len(a_tree.branch.revision_history()), 3)
215
self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
196
217
b_tree.merge_from_branch(a_tree.branch)
197
218
b_tree.commit(message='merge')
199
self.assertEqual(len(b_tree.branch.revision_history()), 2)
220
self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
201
222
self.build_tree_contents([('a/foo', 'a fourth change\n')])
202
223
a_tree.commit(message='a fourth change')
204
rev_history_a = a_tree.branch.revision_history()
205
self.assertEqual(len(rev_history_a), 4)
225
rev_info_a = a_tree.branch.last_revision_info()
226
self.assertEqual(rev_info_a[0], 4)
207
228
# With convergence, we could just pull over the
208
229
# new change, but with --overwrite, we want to switch our history
210
231
self.run_bzr('pull --overwrite ../a')
211
rev_history_b = b_tree.branch.revision_history()
212
self.assertEqual(len(rev_history_b), 4)
214
self.assertEqual(rev_history_b, rev_history_a)
232
rev_info_b = b_tree.branch.last_revision_info()
233
self.assertEqual(rev_info_b[0], 4)
234
self.assertEqual(rev_info_b, rev_info_a)
216
236
def test_pull_remember(self):
217
237
"""Pull changes from one branch to another and test parent location."""
230
250
tree_a.commit('commit b')
232
252
parent = branch_b.get_parent()
253
branch_b = branch.Branch.open('branch_b')
254
branch_b.lock_write()
233
255
branch_b.set_parent(None)
234
257
self.assertEqual(None, branch_b.get_parent())
235
258
# test pull for failure without parent set
237
out = self.run_bzr('pull', retcode=3)
259
out = self.run_bzr('pull', retcode=3, working_dir='branch_b')
238
260
self.assertEqual(out,
239
261
('','bzr: ERROR: No pull location known or specified.\n'))
240
262
# test implicit --remember when no parent set, this pull conflicts
241
self.build_tree(['d'])
263
self.build_tree(['branch_b/d'])
243
265
tree_b.commit('commit d')
244
out = self.run_bzr('pull ../branch_a', retcode=3)
266
out = self.run_bzr('pull ../branch_a', retcode=3,
267
working_dir='branch_b')
245
268
self.assertEqual(out,
246
269
('','bzr: ERROR: These branches have diverged.'
247
270
' Use the missing command to see how.\n'
248
271
'Use the merge command to reconcile them.\n'))
249
self.assertEqual(branch_b.get_parent(), parent)
272
branch_b = branch.Branch.open('branch_b')
273
self.assertEqual(parent, branch_b.get_parent())
250
274
# test implicit --remember after resolving previous failure
251
uncommit(branch=branch_b, tree=tree_b)
275
uncommit(branch=tree_b.branch, tree=tree_b)
252
276
transport.delete('branch_b/d')
277
self.run_bzr('pull', working_dir='branch_b')
278
branch_b = branch.Branch.open('branch_b')
254
279
self.assertEqual(branch_b.get_parent(), parent)
255
280
# test explicit --remember
256
self.run_bzr('pull ../branch_c --remember')
257
self.assertEqual(branch_b.get_parent(),
258
branch_c.bzrdir.root_transport.base)
281
self.run_bzr('pull ../branch_c --remember', working_dir='branch_b')
282
branch_b = branch.Branch.open('branch_b')
283
self.assertEqual(branch_c.bzrdir.root_transport.base,
284
branch_b.get_parent())
260
286
def test_pull_bundle(self):
261
287
from bzrlib.testament import Testament
365
391
self.assertNotContainsRe(
366
392
out, r'revno: 1\ncommitter: .*\nbranch nick: source')
394
def test_pull_smart_bound_branch(self):
395
self.setup_smart_server_with_call_log()
396
parent = self.make_branch_and_tree('parent')
397
parent.commit(message='first commit')
398
child = parent.bzrdir.sprout('child').open_workingtree()
399
child.commit(message='second commit')
400
checkout = parent.branch.create_checkout('checkout')
401
self.run_bzr(['pull', self.get_url('child')], working_dir='checkout')
368
403
def test_pull_smart_stacked_streaming_acceptance(self):
369
404
"""'bzr pull -r 123' works on stacked, smart branches, even when the
370
405
revision specified by the revno is only present in the fallback
453
488
out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
454
489
self.assertContainsRe(err,
455
490
"(?m)Fetching into experimental format")
492
def test_pull_show_base(self):
493
"""bzr pull supports --show-base
495
see https://bugs.launchpad.net/bzr/+bug/202374"""
496
# create two trees with conflicts, setup conflict, check that
497
# conflicted file looks correct
498
a_tree = self.example_branch('a')
499
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
501
f = open(pathjoin('a', 'hello'),'wt')
506
f = open(pathjoin('b', 'hello'),'wt')
510
out,err=self.run_bzr(['pull','-d','b','a','--show-base'])
512
# check for message here
513
self.assertEqual(err,
514
' M hello\nText conflict in hello\n1 conflicts encountered.\n')
516
self.assertEqualDiff('<<<<<<< TREE\n'
517
'fie||||||| BASE-REVISION\n'
519
'fee>>>>>>> MERGE-SOURCE\n',
520
open(pathjoin('b', 'hello')).read())
522
def test_pull_show_base_working_tree_only(self):
523
"""--show-base only allowed if there's a working tree
525
see https://bugs.launchpad.net/bzr/+bug/202374"""
526
# create a branch, see that --show-base fails
527
self.make_branch('from')
528
self.make_branch('to')
529
out=self.run_bzr(['pull','-d','to','from','--show-base'],retcode=3)
530
self.assertEqual(out,
531
('','bzr: ERROR: Need working tree for --show-base.\n'))
533
def test_pull_tag_conflicts(self):
534
"""pulling tags with conflicts will change the exit code"""
535
# create a branch, see that --show-base fails
536
from_tree = self.make_branch_and_tree('from')
537
from_tree.branch.tags.set_tag("mytag", "somerevid")
538
to_tree = self.make_branch_and_tree('to')
539
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
540
out = self.run_bzr(['pull','-d','to','from'],retcode=1)
541
self.assertEqual(out,
542
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
544
def test_pull_tag_notification(self):
545
"""pulling tags with conflicts will change the exit code"""
546
# create a branch, see that --show-base fails
547
from_tree = self.make_branch_and_tree('from')
548
from_tree.branch.tags.set_tag("mytag", "somerevid")
549
to_tree = self.make_branch_and_tree('to')
550
out = self.run_bzr(['pull', '-d', 'to', 'from'])
551
self.assertEqual(out,
552
('1 tag(s) updated.\n', ''))
554
def test_pull_tag_overwrite(self):
555
"""pulling tags with --overwrite only reports changed tags."""
556
# create a branch, see that --show-base fails
557
from_tree = self.make_branch_and_tree('from')
558
from_tree.branch.tags.set_tag("mytag", "somerevid")
559
to_tree = self.make_branch_and_tree('to')
560
to_tree.branch.tags.set_tag("mytag", "somerevid")
561
out = self.run_bzr(['pull', '--overwrite', '-d', 'to', 'from'])
562
self.assertEqual(out,
563
('No revisions or tags to pull.\n', ''))
566
class TestPullOutput(script.TestCaseWithTransportAndScript):
568
def test_pull_log_format(self):
571
Created a standalone tree (format: 2a)
576
$ bzr commit -m 'we need some foo'
577
2>Committing to:...trunk/
579
2>Committed revision 1.
582
Created a standalone tree (format: 2a)
584
$ bzr pull -v ../trunk -Olog_format=line
587
1: jrandom@example.com ...we need some foo
589
2>All changes applied successfully.