1
# Copyright (C) 2005, 2006 Canonical Ltd
1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
5
6
# the Free Software Foundation; either version 2 of the License, or
6
7
# (at your option) any later version.
8
9
# This program is distributed in the hope that it will be useful,
9
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
12
# GNU General Public License for more details.
13
14
# You should have received a copy of the GNU General Public License
14
15
# along with this program; if not, write to the Free Software
15
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
"""Black-box tests for bzr pull."""
19
"""Black-box tests for bzr pull.
23
25
from bzrlib.branch import Branch
24
26
from bzrlib.tests.blackbox import ExternalBase
25
from bzrlib.uncommit import uncommit
26
from bzrlib import urlutils
29
28
class TestPull(ExternalBase):
31
30
def example_branch(test):
33
32
file('hello', 'wt').write('foo')
34
test.run_bzr('add hello')
35
test.run_bzr('commit -m setup hello')
33
test.runbzr('add hello')
34
test.runbzr('commit -m setup hello')
36
35
file('goodbye', 'wt').write('baz')
37
test.run_bzr('add goodbye')
38
test.run_bzr('commit -m setup goodbye')
36
test.runbzr('add goodbye')
37
test.runbzr('commit -m setup goodbye')
40
39
def test_pull(self):
41
40
"""Pull changes from one branch to another."""
45
44
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')
50
# this will work on windows because we check for the same branch
51
# in pull - if it fails, it is a regression
53
self.run_bzr('pull /', retcode=3)
54
if sys.platform not in ('win32', 'cygwin'):
45
self.runbzr('pull', retcode=3)
46
self.runbzr('missing', retcode=3)
47
self.runbzr('missing .')
48
self.runbzr('missing')
49
if sys.platform not in ('win32', 'cygwin'):
50
# This is equivalent to doing "bzr pull ."
51
# Which means that bzr creates 2 branches grabbing
52
# the same location, and tries to pull.
53
# However, 2 branches mean 2 locks on the same file
54
# which ultimately implies a deadlock.
55
# (non windows platforms allow multiple locks on the
56
# same file by the same calling process)
58
self.runbzr('pull /', retcode=3)
59
if sys.platform not in ('win32', 'cygwin'):
58
self.run_bzr('branch a b')
63
self.runbzr('branch a b')
62
self.run_bzr('add subdir')
63
self.run_bzr('commit -m blah --unchanged')
67
self.runbzr('add subdir')
68
self.runbzr('commit -m blah --unchanged')
65
70
a = Branch.open('.')
66
71
b = Branch.open('../b')
67
72
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
68
self.run_bzr('pull ../b')
73
self.runbzr('pull ../b')
69
74
self.assertEquals(a.revision_history(), b.revision_history())
70
self.run_bzr('commit -m blah2 --unchanged')
75
self.runbzr('commit -m blah2 --unchanged')
72
self.run_bzr('commit -m blah3 --unchanged')
77
self.runbzr('commit -m blah3 --unchanged')
74
self.run_bzr('pull ../a', retcode=3)
79
self.runbzr('pull ../a', retcode=3)
76
self.run_bzr('branch b overwriteme')
81
self.runbzr('branch b overwriteme')
77
82
os.chdir('overwriteme')
78
self.run_bzr('pull --overwrite ../a')
83
self.runbzr('pull --overwrite ../a')
79
84
overwritten = Branch.open('.')
80
85
self.assertEqual(overwritten.revision_history(),
81
86
a.revision_history())
83
self.run_bzr('merge ../b')
84
self.run_bzr('commit -m blah4 --unchanged')
88
self.runbzr('merge ../b')
89
self.runbzr('commit -m blah4 --unchanged')
85
90
os.chdir('../b/subdir')
86
self.run_bzr('pull ../../a')
91
self.runbzr('pull ../../a')
87
92
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')
93
self.runbzr('commit -m blah5 --unchanged')
94
self.runbzr('commit -m blah6 --unchanged')
91
self.run_bzr('pull ../a')
96
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)
98
self.runbzr('commit -m blah7 --unchanged')
99
self.runbzr('merge ../b')
100
self.runbzr('commit -m blah8 --unchanged')
101
self.runbzr('pull ../b')
102
self.runbzr('pull ../b')
112
104
def test_pull_revision(self):
113
105
"""Pull some changes from one branch to another."""
117
109
self.example_branch()
118
110
file('hello2', 'wt').write('foo')
119
self.run_bzr('add hello2')
120
self.run_bzr('commit -m setup hello2')
111
self.runbzr('add hello2')
112
self.runbzr('commit -m setup hello2')
121
113
file('goodbye2', 'wt').write('baz')
122
self.run_bzr('add goodbye2')
123
self.run_bzr('commit -m setup goodbye2')
114
self.runbzr('add goodbye2')
115
self.runbzr('commit -m setup goodbye2')
126
self.run_bzr('branch -r 1 a b')
118
self.runbzr('branch -r 1 a b')
128
self.run_bzr('pull -r 2')
120
self.runbzr('pull -r 2')
129
121
a = Branch.open('../a')
130
122
b = Branch.open('.')
131
123
self.assertEquals(a.revno(),4)
132
124
self.assertEquals(b.revno(),2)
133
self.run_bzr('pull -r 3')
125
self.runbzr('pull -r 3')
134
126
self.assertEquals(b.revno(),3)
135
self.run_bzr('pull -r 4')
127
self.runbzr('pull -r 4')
136
128
self.assertEquals(a.revision_history(), b.revision_history())
155
147
open('foo', 'wb').write('original\n')
157
bzr(['commit', '-m', 'initial commit'])
149
bzr('commit', '-m', 'initial commit')
152
bzr('branch', 'a', 'b')
163
155
open('foo', 'wb').write('changed\n')
164
bzr(['commit', '-m', 'later change'])
156
bzr('commit', '-m', 'later change')
166
158
open('foo', 'wb').write('another\n')
167
bzr(['commit', '-m', 'a third change'])
159
bzr('commit', '-m', 'a third change')
169
161
rev_history_a = get_rh(3)
173
bzr('commit -m merge')
165
bzr('commit', '-m', 'merge')
175
167
rev_history_b = get_rh(2)
177
bzr('pull --overwrite ../a')
169
bzr('pull', '--overwrite', '../a')
178
170
rev_history_b = get_rh(3)
180
172
self.assertEqual(rev_history_b, rev_history_a)
197
189
open('foo', 'wb').write('original\n')
199
bzr(['commit', '-m', 'initial commit'])
191
bzr('commit', '-m', 'initial commit')
194
bzr('branch', 'a', 'b')
205
197
open('foo', 'wb').write('changed\n')
206
bzr(['commit', '-m', 'later change'])
198
bzr('commit', '-m', 'later change')
208
200
open('foo', 'wb').write('another\n')
209
bzr(['commit', '-m', 'a third change'])
201
bzr('commit', '-m', 'a third change')
211
203
rev_history_a = get_rh(3)
215
bzr('commit -m merge')
207
bzr('commit', '-m', 'merge')
217
209
rev_history_b = get_rh(2)
220
212
open('foo', 'wb').write('a fourth change\n')
221
bzr(['commit', '-m', 'a fourth change'])
213
bzr('commit', '-m', 'a fourth change')
223
215
rev_history_a = get_rh(4)
225
217
# With convergence, we could just pull over the
226
218
# new change, but with --overwrite, we want to switch our history
228
bzr('pull --overwrite ../a')
220
bzr('pull', '--overwrite', '../a')
229
221
rev_history_b = get_rh(4)
231
223
self.assertEqual(rev_history_b, rev_history_a)
233
def test_pull_remember(self):
234
"""Pull changes from one branch to another and test parent location."""
235
transport = self.get_transport()
236
tree_a = self.make_branch_and_tree('branch_a')
237
branch_a = tree_a.branch
238
self.build_tree(['branch_a/a'])
240
tree_a.commit('commit a')
241
tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
242
branch_b = tree_b.branch
243
tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
244
branch_c = tree_c.branch
245
self.build_tree(['branch_a/b'])
247
tree_a.commit('commit b')
249
parent = branch_b.get_parent()
250
branch_b.set_parent(None)
251
self.assertEqual(None, branch_b.get_parent())
252
# test pull for failure without parent set
254
out = self.run_bzr('pull', retcode=3)
255
self.assertEquals(out,
256
('','bzr: ERROR: No pull location known or specified.\n'))
257
# test implicit --remember when no parent set, this pull conflicts
258
self.build_tree(['d'])
260
tree_b.commit('commit d')
261
out = self.run_bzr('pull ../branch_a', retcode=3)
262
self.assertEquals(out,
263
('','bzr: ERROR: These branches have diverged.'
264
' Use the merge command to reconcile them.\n'))
265
self.assertEquals(branch_b.get_parent(), parent)
266
# test implicit --remember after resolving previous failure
267
uncommit(branch=branch_b, tree=tree_b)
268
transport.delete('branch_b/d')
270
self.assertEquals(branch_b.get_parent(), parent)
271
# test explicit --remember
272
self.run_bzr('pull ../branch_c --remember')
273
self.assertEquals(branch_b.get_parent(),
274
branch_c.bzrdir.root_transport.base)
276
def test_pull_bundle(self):
277
from bzrlib.testament import Testament
278
# Build up 2 trees and prepare for a pull
279
tree_a = self.make_branch_and_tree('branch_a')
280
f = open('branch_a/a', 'wb')
284
tree_a.commit('message')
286
tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree()
288
# Make a change to 'a' that 'b' can pull
289
f = open('branch_a/a', 'wb')
292
tree_a.commit('message')
294
# Create the bundle for 'b' to pull
296
bundle_file = open('../bundle', 'wb')
297
bundle_file.write(self.run_bzr('bundle ../branch_b')[0])
300
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')
307
self.assertEqualDiff(tree_a.branch.revision_history(),
308
tree_b.branch.revision_history())
310
testament_a = Testament.from_revision(tree_a.branch.repository,
311
tree_a.get_parent_ids()[0])
312
testament_b = Testament.from_revision(tree_b.branch.repository,
313
tree_b.get_parent_ids()[0])
314
self.assertEqualDiff(testament_a.as_text(),
315
testament_b.as_text())
317
# 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')