50
56
def test_pull(self):
51
57
"""Pull changes from one branch to another."""
52
58
a_tree = self.example_branch('a')
54
self.run_bzr('pull', retcode=3)
55
self.run_bzr('missing', retcode=3)
56
self.run_bzr('missing .')
57
self.run_bzr('missing')
59
base_rev = a_tree.branch.last_revision()
60
self.run_bzr('pull', retcode=3, working_dir='a')
61
self.run_bzr('missing', retcode=3, working_dir='a')
62
self.run_bzr('missing .', working_dir='a')
63
self.run_bzr('missing', working_dir='a')
58
64
# this will work on windows because we check for the same branch
59
65
# in pull - if it fails, it is a regression
61
self.run_bzr('pull /', retcode=3)
66
self.run_bzr('pull', working_dir='a')
67
self.run_bzr('pull /', retcode=3, working_dir='a')
62
68
if sys.platform not in ('win32', 'cygwin'):
69
self.run_bzr('pull', working_dir='a')
66
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
71
b_tree = a_tree.controldir.sprout('b').open_workingtree()
72
self.run_bzr('pull', working_dir='b')
70
74
b_tree.add('subdir')
71
b_tree.commit(message='blah', allow_pointless=True)
76
self.assertEqual(a.revision_history(), b.revision_history()[:-1])
79
self.run_bzr('pull ../b')
80
self.assertEqual(a.revision_history(), b.revision_history())
75
new_rev = b_tree.commit(message='blah', allow_pointless=True)
77
a = branch.Branch.open('a')
78
b = branch.Branch.open('b')
79
self.assertEqual(a.last_revision(), base_rev)
80
self.assertEqual(b.last_revision(), new_rev)
82
self.run_bzr('pull ../b', working_dir='a')
83
self.assertEqual(a.last_revision(), b.last_revision())
81
84
a_tree.commit(message='blah2', allow_pointless=True)
82
85
b_tree.commit(message='blah3', allow_pointless=True)
85
self.run_bzr('pull ../a', retcode=3)
87
b_tree.bzrdir.sprout('overwriteme')
88
os.chdir('overwriteme')
89
self.run_bzr('pull --overwrite ../a')
90
overwritten = Branch.open('.')
91
self.assertEqual(overwritten.revision_history(),
87
self.run_bzr('pull ../a', retcode=3, working_dir='b')
88
b_tree.controldir.sprout('overwriteme')
89
self.run_bzr('pull --overwrite ../a', working_dir='overwriteme')
90
overwritten = branch.Branch.open('overwriteme')
91
self.assertEqual(overwritten.last_revision(),
93
93
a_tree.merge_from_branch(b_tree.branch)
94
94
a_tree.commit(message="blah4", allow_pointless=True)
95
os.chdir('../b/subdir')
96
self.run_bzr('pull ../../a')
97
self.assertEqual(a.revision_history()[-1], b.revision_history()[-1])
98
sub_tree = WorkingTree.open_containing('.')[0]
96
self.run_bzr('pull ../../a', working_dir='b/subdir')
97
self.assertEqual(a.last_revision(), b.last_revision())
98
sub_tree = workingtree.WorkingTree.open_containing('b/subdir')[0]
99
99
sub_tree.commit(message="blah5", allow_pointless=True)
100
100
sub_tree.commit(message="blah6", allow_pointless=True)
102
self.run_bzr('pull ../a')
101
self.run_bzr('pull ../a', working_dir='b')
104
102
a_tree.commit(message="blah7", allow_pointless=True)
105
103
a_tree.merge_from_branch(b_tree.branch)
106
104
a_tree.commit(message="blah8", allow_pointless=True)
107
self.run_bzr('pull ../b')
108
self.run_bzr('pull ../b')
105
self.run_bzr('pull ../b', working_dir='a')
106
self.run_bzr('pull ../b', working_dir='a')
110
108
def test_pull_dash_d(self):
111
109
self.example_branch('a')
122
120
"""Pull some changes from one branch to another."""
123
121
a_tree = self.example_branch('a')
124
122
self.build_tree_contents([
126
('a/goodbye2', 'baz')])
123
('a/hello2', b'foo'),
124
('a/goodbye2', b'baz')])
127
125
a_tree.add('hello2')
128
126
a_tree.commit(message="setup")
129
127
a_tree.add('goodbye2')
130
128
a_tree.commit(message="setup")
132
b_tree = a_tree.bzrdir.sprout('b',
133
revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
135
self.run_bzr('pull -r 2')
136
a = Branch.open('../a')
138
self.assertEqual(a.revno(),4)
139
self.assertEqual(b.revno(),2)
140
self.run_bzr('pull -r 3')
141
self.assertEqual(b.revno(),3)
142
self.run_bzr('pull -r 4')
143
self.assertEqual(a.revision_history(), b.revision_history())
130
b_tree = a_tree.controldir.sprout(
131
'b', revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
132
self.run_bzr('pull -r 2', working_dir='b')
133
a = branch.Branch.open('a')
134
b = branch.Branch.open('b')
135
self.assertEqual(a.revno(), 4)
136
self.assertEqual(b.revno(), 2)
137
self.run_bzr('pull -r 3', working_dir='b')
138
self.assertEqual(b.revno(), 3)
139
self.run_bzr('pull -r 4', working_dir='b')
140
self.assertEqual(a.last_revision(), b.last_revision())
142
def test_pull_tags(self):
143
"""Tags are updated by pull, and revisions named in those tags are
146
# Make a source, sprout a target off it
147
builder = self.make_branch_builder('source')
148
source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(builder)
149
source.get_config_stack().set('branch.fetch_tags', True)
150
target_bzrdir = source.controldir.sprout('target')
151
source.tags.set_tag('tag-a', rev2)
153
self.run_bzr('pull -d target source')
154
target = target_bzrdir.open_branch()
155
# The tag is present, and so is its revision.
156
self.assertEqual(rev2, target.tags.lookup_tag('tag-a'))
157
target.repository.get_revision(rev2)
146
159
def test_overwrite_uptodate(self):
147
160
# Make sure pull --overwrite overwrites
148
161
# even if the target branch has merged
149
162
# everything already.
150
163
a_tree = self.make_branch_and_tree('a')
151
self.build_tree_contents([('a/foo', 'original\n')])
164
self.build_tree_contents([('a/foo', b'original\n')])
152
165
a_tree.add('foo')
153
166
a_tree.commit(message='initial commit')
155
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
168
b_tree = a_tree.controldir.sprout('b').open_workingtree()
157
self.build_tree_contents([('a/foo', 'changed\n')])
170
self.build_tree_contents([('a/foo', b'changed\n')])
158
171
a_tree.commit(message='later change')
160
self.build_tree_contents([('a/foo', 'a third change')])
173
self.build_tree_contents([('a/foo', b'a third change')])
161
174
a_tree.commit(message='a third change')
163
rev_history_a = a_tree.branch.revision_history()
164
self.assertEqual(len(rev_history_a), 3)
176
self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
166
178
b_tree.merge_from_branch(a_tree.branch)
167
179
b_tree.commit(message='merge')
169
self.assertEqual(len(b_tree.branch.revision_history()), 2)
172
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)
181
self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
183
self.run_bzr('pull --overwrite ../a', working_dir='b')
184
(last_revinfo_b) = b_tree.branch.last_revision_info()
185
self.assertEqual(last_revinfo_b[0], 3)
186
self.assertEqual(last_revinfo_b[1], a_tree.branch.last_revision())
178
188
def test_overwrite_children(self):
179
189
# Make sure pull --overwrite sets the revision-history
180
190
# to be identical to the pull source, even if we have convergence
181
191
a_tree = self.make_branch_and_tree('a')
182
self.build_tree_contents([('a/foo', 'original\n')])
192
self.build_tree_contents([('a/foo', b'original\n')])
183
193
a_tree.add('foo')
184
194
a_tree.commit(message='initial commit')
186
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
196
b_tree = a_tree.controldir.sprout('b').open_workingtree()
188
self.build_tree_contents([('a/foo', 'changed\n')])
198
self.build_tree_contents([('a/foo', b'changed\n')])
189
199
a_tree.commit(message='later change')
191
self.build_tree_contents([('a/foo', 'a third change')])
201
self.build_tree_contents([('a/foo', b'a third change')])
192
202
a_tree.commit(message='a third change')
194
self.assertEqual(len(a_tree.branch.revision_history()), 3)
204
self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
196
206
b_tree.merge_from_branch(a_tree.branch)
197
207
b_tree.commit(message='merge')
199
self.assertEqual(len(b_tree.branch.revision_history()), 2)
209
self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
201
self.build_tree_contents([('a/foo', 'a fourth change\n')])
211
self.build_tree_contents([('a/foo', b'a fourth change\n')])
202
212
a_tree.commit(message='a fourth change')
204
rev_history_a = a_tree.branch.revision_history()
205
self.assertEqual(len(rev_history_a), 4)
214
rev_info_a = a_tree.branch.last_revision_info()
215
self.assertEqual(rev_info_a[0], 4)
207
217
# With convergence, we could just pull over the
208
218
# new change, but with --overwrite, we want to switch our history
210
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)
219
self.run_bzr('pull --overwrite ../a', working_dir='b')
220
rev_info_b = b_tree.branch.last_revision_info()
221
self.assertEqual(rev_info_b[0], 4)
222
self.assertEqual(rev_info_b, rev_info_a)
216
224
def test_pull_remember(self):
217
225
"""Pull changes from one branch to another and test parent location."""
218
transport = self.get_transport()
226
t = self.get_transport()
219
227
tree_a = self.make_branch_and_tree('branch_a')
220
228
branch_a = tree_a.branch
221
229
self.build_tree(['branch_a/a'])
223
231
tree_a.commit('commit a')
224
tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
232
tree_b = branch_a.controldir.sprout('branch_b').open_workingtree()
225
233
branch_b = tree_b.branch
226
tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
234
tree_c = branch_a.controldir.sprout('branch_c').open_workingtree()
227
235
branch_c = tree_c.branch
228
236
self.build_tree(['branch_a/b'])
230
238
tree_a.commit('commit b')
232
240
parent = branch_b.get_parent()
241
branch_b = branch.Branch.open('branch_b')
233
242
branch_b.set_parent(None)
234
243
self.assertEqual(None, branch_b.get_parent())
235
244
# test pull for failure without parent set
237
out = self.run_bzr('pull', retcode=3)
245
out = self.run_bzr('pull', retcode=3, working_dir='branch_b')
238
246
self.assertEqual(out,
239
('','bzr: ERROR: No pull location known or specified.\n'))
247
('', 'brz: ERROR: No pull location known or specified.\n'))
240
248
# test implicit --remember when no parent set, this pull conflicts
241
self.build_tree(['d'])
249
self.build_tree(['branch_b/d'])
243
251
tree_b.commit('commit d')
244
out = self.run_bzr('pull ../branch_a', retcode=3)
252
out = self.run_bzr('pull ../branch_a', retcode=3,
253
working_dir='branch_b')
245
254
self.assertEqual(out,
246
('','bzr: ERROR: These branches have diverged.'
255
('', 'brz: ERROR: These branches have diverged.'
247
256
' Use the missing command to see how.\n'
248
257
'Use the merge command to reconcile them.\n'))
249
self.assertEqual(branch_b.get_parent(), parent)
258
tree_b = tree_b.controldir.open_workingtree()
259
branch_b = tree_b.branch
260
self.assertEqual(parent, branch_b.get_parent())
250
261
# test implicit --remember after resolving previous failure
251
uncommit(branch=branch_b, tree=tree_b)
252
transport.delete('branch_b/d')
262
uncommit.uncommit(branch=branch_b, tree=tree_b)
263
t.delete('branch_b/d')
264
self.run_bzr('pull', working_dir='branch_b')
265
# Refresh the branch object as 'pull' modified it
266
branch_b = branch_b.controldir.open_branch()
254
267
self.assertEqual(branch_b.get_parent(), parent)
255
268
# 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)
269
self.run_bzr('pull ../branch_c --remember', working_dir='branch_b')
270
# Refresh the branch object as 'pull' modified it
271
branch_b = branch_b.controldir.open_branch()
272
self.assertEqual(branch_c.controldir.root_transport.base,
273
branch_b.get_parent())
260
275
def test_pull_bundle(self):
261
from bzrlib.testament import Testament
276
from breezy.testament import Testament
262
277
# Build up 2 trees and prepare for a pull
263
278
tree_a = self.make_branch_and_tree('branch_a')
264
f = open('branch_a/a', 'wb')
279
with open('branch_a/a', 'wb') as f:
268
282
tree_a.commit('message')
270
tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
284
tree_b = tree_a.controldir.sprout('branch_b').open_workingtree()
272
286
# Make a change to 'a' that 'b' can pull
273
f = open('branch_a/a', 'wb')
287
with open('branch_a/a', 'wb') as f:
288
f.write(b'hey there')
276
289
tree_a.commit('message')
278
291
# Create the bundle for 'b' to pull
280
self.run_bzr('bundle ../branch_b -o ../bundle')
292
self.run_bzr('bundle ../branch_b -o ../bundle', working_dir='branch_a')
282
os.chdir('../branch_b')
283
out, err = self.run_bzr('pull ../bundle')
294
out, err = self.run_bzr('pull ../bundle', working_dir='branch_b')
284
295
self.assertEqual(out,
285
296
'Now on revision 2.\n')
286
297
self.assertEqual(err,
287
298
' M a\nAll changes applied successfully.\n')
289
self.assertEqualDiff(tree_a.branch.revision_history(),
290
tree_b.branch.revision_history())
300
self.assertEqualDiff(tree_a.branch.last_revision(),
301
tree_b.branch.last_revision())
292
303
testament_a = Testament.from_revision(tree_a.branch.repository,
293
304
tree_a.get_parent_ids()[0])
452
472
from_tree.commit(message='first commit')
453
473
out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
454
474
self.assertContainsRe(err,
455
"(?m)Fetching into experimental format")
475
b"(?m)Fetching into experimental format")
477
def test_pull_show_base(self):
478
"""brz pull supports --show-base
480
see https://bugs.launchpad.net/bzr/+bug/202374"""
481
# create two trees with conflicts, setup conflict, check that
482
# conflicted file looks correct
483
a_tree = self.example_branch('a')
484
b_tree = a_tree.controldir.sprout('b').open_workingtree()
486
with open(osutils.pathjoin('a', 'hello'), 'wt') as f:
490
with open(osutils.pathjoin('b', 'hello'), 'wt') as f:
493
out, err=self.run_bzr(['pull', '-d', 'b', 'a', '--show-base'])
495
# check for message here
498
' M hello\nText conflict in hello\n1 conflicts encountered.\n')
500
self.assertEqualDiff('<<<<<<< TREE\n'
501
'fie||||||| BASE-REVISION\n'
503
'fee>>>>>>> MERGE-SOURCE\n',
504
open(osutils.pathjoin('b', 'hello')).read())
506
def test_pull_warns_about_show_base_when_no_working_tree(self):
507
"""--show-base is useless if there's no working tree
509
see https://bugs.launchpad.net/bzr/+bug/1022160"""
510
self.make_branch('from')
511
self.make_branch('to')
512
out = self.run_bzr(['pull', '-d', 'to', 'from', '--show-base'])
513
self.assertEqual(out, ('No revisions or tags to pull.\n',
514
'No working tree, ignoring --show-base\n'))
516
def test_pull_tag_conflicts(self):
517
"""pulling tags with conflicts will change the exit code"""
518
# create a branch, see that --show-base fails
519
from_tree = self.make_branch_and_tree('from')
520
from_tree.branch.tags.set_tag("mytag", "somerevid")
521
to_tree = self.make_branch_and_tree('to')
522
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
523
out = self.run_bzr(['pull', '-d', 'to', 'from'], retcode=1)
524
self.assertEqual(out,
525
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
527
def test_pull_tag_notification(self):
528
"""pulling tags with conflicts will change the exit code"""
529
# create a branch, see that --show-base fails
530
from_tree = self.make_branch_and_tree('from')
531
from_tree.branch.tags.set_tag("mytag", "somerevid")
532
to_tree = self.make_branch_and_tree('to')
533
out = self.run_bzr(['pull', '-d', 'to', 'from'])
534
self.assertEqual(out,
535
('1 tag(s) updated.\n', ''))
537
def test_overwrite_tags(self):
538
"""--overwrite-tags only overwrites tags, not revisions."""
539
from_tree = self.make_branch_and_tree('from')
540
from_tree.branch.tags.set_tag("mytag", "somerevid")
541
to_tree = self.make_branch_and_tree('to')
542
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
543
revid1 = to_tree.commit('my commit')
544
out = self.run_bzr(['pull', '-d', 'to', 'from'], retcode=1)
545
self.assertEqual(out,
546
('No revisions to pull.\nConflicting tags:\n mytag\n', ''))
547
out = self.run_bzr(['pull', '-d', 'to', '--overwrite-tags', 'from'])
548
self.assertEqual(out, ('1 tag(s) updated.\n', ''))
550
self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
552
self.assertEqual(to_tree.branch.last_revision(), revid1)
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
$ brz commit -m 'we need some foo'
577
2>Committing to:...trunk/
579
2>Committed revision 1.
582
Created a standalone tree (format: 2a)
584
$ brz pull -v ../trunk -Olog_format=line
587
1: jrandom@example.com ...we need some foo
589
2>All changes applied successfully.