1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""Black-box tests for bzr pull.
25
from bzrlib.branch import Branch
26
from bzrlib.osutils import abspath
27
from bzrlib.tests.blackbox import ExternalBase
28
from bzrlib.uncommit import uncommit
31
class TestPull(ExternalBase):
33
def example_branch(test):
35
file('hello', 'wt').write('foo')
36
test.runbzr('add hello')
37
test.runbzr('commit -m setup hello')
38
file('goodbye', 'wt').write('baz')
39
test.runbzr('add goodbye')
40
test.runbzr('commit -m setup goodbye')
43
"""Pull changes from one branch to another."""
48
self.runbzr('pull', retcode=3)
49
self.runbzr('missing', retcode=3)
50
self.runbzr('missing .')
51
self.runbzr('missing')
52
if sys.platform not in ('win32', 'cygwin'):
53
# This is equivalent to doing "bzr pull ."
54
# Which means that bzr creates 2 branches grabbing
55
# the same location, and tries to pull.
56
# However, 2 branches mean 2 locks on the same file
57
# which ultimately implies a deadlock.
58
# (non windows platforms allow multiple locks on the
59
# same file by the same calling process)
61
self.runbzr('pull /', retcode=3)
62
if sys.platform not in ('win32', 'cygwin'):
66
self.runbzr('branch a b')
70
self.runbzr('add subdir')
71
self.runbzr('commit -m blah --unchanged')
74
b = Branch.open('../b')
75
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
76
self.runbzr('pull ../b')
77
self.assertEquals(a.revision_history(), b.revision_history())
78
self.runbzr('commit -m blah2 --unchanged')
80
self.runbzr('commit -m blah3 --unchanged')
82
self.runbzr('pull ../a', retcode=3)
84
self.runbzr('branch b overwriteme')
85
os.chdir('overwriteme')
86
self.runbzr('pull --overwrite ../a')
87
overwritten = Branch.open('.')
88
self.assertEqual(overwritten.revision_history(),
91
self.runbzr('merge ../b')
92
self.runbzr('commit -m blah4 --unchanged')
93
os.chdir('../b/subdir')
94
self.runbzr('pull ../../a')
95
self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
96
self.runbzr('commit -m blah5 --unchanged')
97
self.runbzr('commit -m blah6 --unchanged')
99
self.runbzr('pull ../a')
101
self.runbzr('commit -m blah7 --unchanged')
102
self.runbzr('merge ../b')
103
self.runbzr('commit -m blah8 --unchanged')
104
self.runbzr('pull ../b')
105
self.runbzr('pull ../b')
107
def test_pull_revision(self):
108
"""Pull some changes from one branch to another."""
112
self.example_branch()
113
file('hello2', 'wt').write('foo')
114
self.runbzr('add hello2')
115
self.runbzr('commit -m setup hello2')
116
file('goodbye2', 'wt').write('baz')
117
self.runbzr('add goodbye2')
118
self.runbzr('commit -m setup goodbye2')
121
self.runbzr('branch -r 1 a b')
123
self.runbzr('pull -r 2')
124
a = Branch.open('../a')
126
self.assertEquals(a.revno(),4)
127
self.assertEquals(b.revno(),2)
128
self.runbzr('pull -r 3')
129
self.assertEquals(b.revno(),3)
130
self.runbzr('pull -r 4')
131
self.assertEquals(a.revision_history(), b.revision_history())
134
def test_overwrite_uptodate(self):
135
# Make sure pull --overwrite overwrites
136
# even if the target branch has merged
137
# everything already.
140
def get_rh(expected_len):
141
rh = self.capture('revision-history')
142
# Make sure we don't have trailing empty revisions
143
rh = rh.strip().split('\n')
144
self.assertEqual(len(rh), expected_len)
150
open('foo', 'wb').write('original\n')
152
bzr('commit', '-m', 'initial commit')
155
bzr('branch', 'a', 'b')
158
open('foo', 'wb').write('changed\n')
159
bzr('commit', '-m', 'later change')
161
open('foo', 'wb').write('another\n')
162
bzr('commit', '-m', 'a third change')
164
rev_history_a = get_rh(3)
168
bzr('commit', '-m', 'merge')
170
rev_history_b = get_rh(2)
172
bzr('pull', '--overwrite', '../a')
173
rev_history_b = get_rh(3)
175
self.assertEqual(rev_history_b, rev_history_a)
177
def test_overwrite_children(self):
178
# Make sure pull --overwrite sets the revision-history
179
# to be identical to the pull source, even if we have convergence
182
def get_rh(expected_len):
183
rh = self.capture('revision-history')
184
# Make sure we don't have trailing empty revisions
185
rh = rh.strip().split('\n')
186
self.assertEqual(len(rh), expected_len)
192
open('foo', 'wb').write('original\n')
194
bzr('commit', '-m', 'initial commit')
197
bzr('branch', 'a', 'b')
200
open('foo', 'wb').write('changed\n')
201
bzr('commit', '-m', 'later change')
203
open('foo', 'wb').write('another\n')
204
bzr('commit', '-m', 'a third change')
206
rev_history_a = get_rh(3)
210
bzr('commit', '-m', 'merge')
212
rev_history_b = get_rh(2)
215
open('foo', 'wb').write('a fourth change\n')
216
bzr('commit', '-m', 'a fourth change')
218
rev_history_a = get_rh(4)
220
# With convergence, we could just pull over the
221
# new change, but with --overwrite, we want to switch our history
223
bzr('pull', '--overwrite', '../a')
224
rev_history_b = get_rh(4)
226
self.assertEqual(rev_history_b, rev_history_a)
228
def test_pull_remember(self):
229
"""Pull changes from one branch to another and test parent location."""
230
transport = self.get_transport()
231
tree_a = self.make_branch_and_tree('branch_a')
232
branch_a = tree_a.branch
233
self.build_tree(['branch_a/a'])
235
tree_a.commit('commit a')
236
branch_b = branch_a.bzrdir.sprout('branch_b').open_branch()
237
tree_b = branch_b.bzrdir.open_workingtree()
238
branch_c = branch_a.bzrdir.sprout('branch_c').open_branch()
239
tree_c = branch_c.bzrdir.open_workingtree()
240
self.build_tree(['branch_a/b'])
242
tree_a.commit('commit b')
244
parent = branch_b.get_parent()
245
branch_b.set_parent(None)
246
self.assertEqual(None, branch_b.get_parent())
247
# test pull for failure without parent set
249
out = self.runbzr('pull', retcode=3)
250
self.assertEquals(out,
251
('','bzr: ERROR: No pull location known or specified.\n'))
252
# test implicit --remember when no parent set, this pull conflicts
253
self.build_tree(['d'])
255
tree_b.commit('commit d')
256
out = self.runbzr('pull ../branch_a', retcode=3)
257
self.assertEquals(out,
258
('','bzr: ERROR: These branches have diverged. Try merge.\n'))
259
self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
260
# test implicit --remember after resolving previous failure
261
uncommit(branch=branch_b, tree=tree_b)
262
transport.delete('branch_b/d')
264
self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
265
# test explicit --remember
266
self.runbzr('pull ../branch_c --remember')
267
self.assertEquals(abspath(branch_b.get_parent()),
268
abspath(branch_c.bzrdir.root_transport.base))