23
24
from bzrlib.branch import Branch
24
25
from bzrlib.tests.blackbox import ExternalBase
25
26
from bzrlib.uncommit import uncommit
26
from bzrlib import urlutils
29
29
class TestPull(ExternalBase):
31
31
def example_branch(test):
33
33
file('hello', 'wt').write('foo')
34
test.run_bzr('add hello')
35
test.run_bzr('commit -m setup hello')
34
test.runbzr('add hello')
35
test.runbzr('commit -m setup hello')
36
36
file('goodbye', 'wt').write('baz')
37
test.run_bzr('add goodbye')
38
test.run_bzr('commit -m setup goodbye')
37
test.runbzr('add goodbye')
38
test.runbzr('commit -m setup goodbye')
40
40
def test_pull(self):
41
41
"""Pull changes from one branch to another."""
45
45
self.example_branch()
46
self.run_bzr('pull', retcode=3)
47
self.run_bzr('missing', retcode=3)
48
self.run_bzr('missing .')
49
self.run_bzr('missing')
46
self.runbzr('pull', retcode=3)
47
self.runbzr('missing', retcode=3)
48
self.runbzr('missing .')
49
self.runbzr('missing')
50
50
# this will work on windows because we check for the same branch
51
51
# in pull - if it fails, it is a regression
53
self.run_bzr('pull /', retcode=3)
53
self.runbzr('pull /', retcode=3)
54
54
if sys.platform not in ('win32', 'cygwin'):
58
self.run_bzr('branch a b')
58
self.runbzr('branch a b')
62
self.run_bzr('add subdir')
63
self.run_bzr('commit -m blah --unchanged')
62
self.runbzr('add subdir')
63
self.runbzr('commit -m blah --unchanged')
65
65
a = Branch.open('.')
66
66
b = Branch.open('../b')
67
67
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
68
self.run_bzr('pull ../b')
68
self.runbzr('pull ../b')
69
69
self.assertEquals(a.revision_history(), b.revision_history())
70
self.run_bzr('commit -m blah2 --unchanged')
70
self.runbzr('commit -m blah2 --unchanged')
72
self.run_bzr('commit -m blah3 --unchanged')
72
self.runbzr('commit -m blah3 --unchanged')
74
self.run_bzr('pull ../a', retcode=3)
74
self.runbzr('pull ../a', retcode=3)
76
self.run_bzr('branch b overwriteme')
76
self.runbzr('branch b overwriteme')
77
77
os.chdir('overwriteme')
78
self.run_bzr('pull --overwrite ../a')
78
self.runbzr('pull --overwrite ../a')
79
79
overwritten = Branch.open('.')
80
80
self.assertEqual(overwritten.revision_history(),
81
81
a.revision_history())
83
self.run_bzr('merge ../b')
84
self.run_bzr('commit -m blah4 --unchanged')
83
self.runbzr('merge ../b')
84
self.runbzr('commit -m blah4 --unchanged')
85
85
os.chdir('../b/subdir')
86
self.run_bzr('pull ../../a')
86
self.runbzr('pull ../../a')
87
87
self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
88
self.run_bzr('commit -m blah5 --unchanged')
89
self.run_bzr('commit -m blah6 --unchanged')
88
self.runbzr('commit -m blah5 --unchanged')
89
self.runbzr('commit -m blah6 --unchanged')
91
self.run_bzr('pull ../a')
91
self.runbzr('pull ../a')
93
self.run_bzr('commit -m blah7 --unchanged')
94
self.run_bzr('merge ../b')
95
self.run_bzr('commit -m blah8 --unchanged')
96
self.run_bzr('pull ../b')
97
self.run_bzr('pull ../b')
99
def test_pull_dash_d(self):
102
self.example_branch()
103
self.run_bzr('init ../b')
104
self.run_bzr('init ../c')
105
# pull into that branch
106
self.run_bzr('pull -d ../b .')
107
# pull into a branch specified by a url
108
c_url = urlutils.local_path_to_url('../c')
109
self.assertStartsWith(c_url, 'file://')
110
self.run_bzr('pull -d %s .' % c_url)
93
self.runbzr('commit -m blah7 --unchanged')
94
self.runbzr('merge ../b')
95
self.runbzr('commit -m blah8 --unchanged')
96
self.runbzr('pull ../b')
97
self.runbzr('pull ../b')
112
99
def test_pull_revision(self):
113
100
"""Pull some changes from one branch to another."""
117
104
self.example_branch()
118
105
file('hello2', 'wt').write('foo')
119
self.run_bzr('add hello2')
120
self.run_bzr('commit -m setup hello2')
106
self.runbzr('add hello2')
107
self.runbzr('commit -m setup hello2')
121
108
file('goodbye2', 'wt').write('baz')
122
self.run_bzr('add goodbye2')
123
self.run_bzr('commit -m setup goodbye2')
109
self.runbzr('add goodbye2')
110
self.runbzr('commit -m setup goodbye2')
126
self.run_bzr('branch -r 1 a b')
113
self.runbzr('branch -r 1 a b')
128
self.run_bzr('pull -r 2')
115
self.runbzr('pull -r 2')
129
116
a = Branch.open('../a')
130
117
b = Branch.open('.')
131
118
self.assertEquals(a.revno(),4)
132
119
self.assertEquals(b.revno(),2)
133
self.run_bzr('pull -r 3')
120
self.runbzr('pull -r 3')
134
121
self.assertEquals(b.revno(),3)
135
self.run_bzr('pull -r 4')
122
self.runbzr('pull -r 4')
136
123
self.assertEquals(a.revision_history(), b.revision_history())
155
142
open('foo', 'wb').write('original\n')
157
bzr(['commit', '-m', 'initial commit'])
144
bzr('commit', '-m', 'initial commit')
147
bzr('branch', 'a', 'b')
163
150
open('foo', 'wb').write('changed\n')
164
bzr(['commit', '-m', 'later change'])
151
bzr('commit', '-m', 'later change')
166
153
open('foo', 'wb').write('another\n')
167
bzr(['commit', '-m', 'a third change'])
154
bzr('commit', '-m', 'a third change')
169
156
rev_history_a = get_rh(3)
173
bzr('commit -m merge')
160
bzr('commit', '-m', 'merge')
175
162
rev_history_b = get_rh(2)
177
bzr('pull --overwrite ../a')
164
bzr('pull', '--overwrite', '../a')
178
165
rev_history_b = get_rh(3)
180
167
self.assertEqual(rev_history_b, rev_history_a)
197
184
open('foo', 'wb').write('original\n')
199
bzr(['commit', '-m', 'initial commit'])
186
bzr('commit', '-m', 'initial commit')
189
bzr('branch', 'a', 'b')
205
192
open('foo', 'wb').write('changed\n')
206
bzr(['commit', '-m', 'later change'])
193
bzr('commit', '-m', 'later change')
208
195
open('foo', 'wb').write('another\n')
209
bzr(['commit', '-m', 'a third change'])
196
bzr('commit', '-m', 'a third change')
211
198
rev_history_a = get_rh(3)
215
bzr('commit -m merge')
202
bzr('commit', '-m', 'merge')
217
204
rev_history_b = get_rh(2)
220
207
open('foo', 'wb').write('a fourth change\n')
221
bzr(['commit', '-m', 'a fourth change'])
208
bzr('commit', '-m', 'a fourth change')
223
210
rev_history_a = get_rh(4)
225
212
# With convergence, we could just pull over the
226
213
# new change, but with --overwrite, we want to switch our history
228
bzr('pull --overwrite ../a')
215
bzr('pull', '--overwrite', '../a')
229
216
rev_history_b = get_rh(4)
231
218
self.assertEqual(rev_history_b, rev_history_a)
251
238
self.assertEqual(None, branch_b.get_parent())
252
239
# test pull for failure without parent set
253
240
os.chdir('branch_b')
254
out = self.run_bzr('pull', retcode=3)
241
out = self.runbzr('pull', retcode=3)
255
242
self.assertEquals(out,
256
243
('','bzr: ERROR: No pull location known or specified.\n'))
257
244
# test implicit --remember when no parent set, this pull conflicts
258
245
self.build_tree(['d'])
260
247
tree_b.commit('commit d')
261
out = self.run_bzr('pull ../branch_a', retcode=3)
248
out = self.runbzr('pull ../branch_a', retcode=3)
262
249
self.assertEquals(out,
263
('','bzr: ERROR: These branches have diverged.'
264
' Use the merge command to reconcile them.\n'))
250
('','bzr: ERROR: These branches have diverged. Use the merge command to reconcile them.\n'))
265
251
self.assertEquals(branch_b.get_parent(), parent)
266
252
# test implicit --remember after resolving previous failure
267
253
uncommit(branch=branch_b, tree=tree_b)
268
254
transport.delete('branch_b/d')
270
256
self.assertEquals(branch_b.get_parent(), parent)
271
257
# test explicit --remember
272
self.run_bzr('pull ../branch_c --remember')
258
self.runbzr('pull ../branch_c --remember')
273
259
self.assertEquals(branch_b.get_parent(),
274
260
branch_c.bzrdir.root_transport.base)
294
280
# Create the bundle for 'b' to pull
295
281
os.chdir('branch_a')
296
282
bundle_file = open('../bundle', 'wb')
297
bundle_file.write(self.run_bzr('bundle ../branch_b')[0])
283
bundle_file.write(self.run_bzr('bundle', '../branch_b')[0])
298
284
bundle_file.close()
300
286
os.chdir('../branch_b')
301
out, err = self.run_bzr('pull ../bundle')
302
self.assertEqual(out,
303
'Now on revision 2.\n')
304
self.assertEqual(err,
305
' M a\nAll changes applied successfully.\n')
287
output = self.run_bzr('pull', '../bundle')
288
self.assertEqual('', output[0])
289
self.assertEqual('All changes applied successfully.\n'
290
'1 revision(s) pulled.\n', output[1])
307
292
self.assertEqualDiff(tree_a.branch.revision_history(),
308
293
tree_b.branch.revision_history())
310
testament_a = Testament.from_revision(tree_a.branch.repository,
311
tree_a.get_parent_ids()[0])
295
testament_a = Testament.from_revision(tree_a.branch.repository,
296
tree_a.last_revision())
312
297
testament_b = Testament.from_revision(tree_b.branch.repository,
313
tree_b.get_parent_ids()[0])
298
tree_b.last_revision())
314
299
self.assertEqualDiff(testament_a.as_text(),
315
300
testament_b.as_text())
317
302
# it is legal to attempt to pull an already-merged bundle
318
out, err = self.run_bzr('pull ../bundle')
319
self.assertEqual(err, '')
320
self.assertEqual(out, 'No revisions to pull.\n')
303
output = self.run_bzr('pull', '../bundle')
304
self.assertEqual('', output[0])
305
self.assertEqual('0 revision(s) pulled.\n', output[1])