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."""
24
from bzrlib.branch import Branch
25
from bzrlib.osutils import abspath
26
from bzrlib.tests.blackbox import ExternalBase
27
from bzrlib.uncommit import uncommit
30
class TestPull(ExternalBase):
32
def example_branch(test):
34
file('hello', 'wt').write('foo')
35
test.runbzr('add hello')
36
test.runbzr('commit -m setup hello')
37
file('goodbye', 'wt').write('baz')
38
test.runbzr('add goodbye')
39
test.runbzr('commit -m setup goodbye')
42
"""Pull changes from one branch to another."""
47
self.runbzr('pull', retcode=3)
48
self.runbzr('missing', retcode=3)
49
self.runbzr('missing .')
50
self.runbzr('missing')
51
# this will work on windows because we check for the same branch
52
# in pull - if it fails, it is a regression
54
self.runbzr('pull /', retcode=3)
55
if sys.platform not in ('win32', 'cygwin'):
59
self.runbzr('branch a b')
63
self.runbzr('add subdir')
64
self.runbzr('commit -m blah --unchanged')
67
b = Branch.open('../b')
68
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
69
self.runbzr('pull ../b')
70
self.assertEquals(a.revision_history(), b.revision_history())
71
self.runbzr('commit -m blah2 --unchanged')
73
self.runbzr('commit -m blah3 --unchanged')
75
self.runbzr('pull ../a', retcode=3)
77
self.runbzr('branch b overwriteme')
78
os.chdir('overwriteme')
79
self.runbzr('pull --overwrite ../a')
80
overwritten = Branch.open('.')
81
self.assertEqual(overwritten.revision_history(),
84
self.runbzr('merge ../b')
85
self.runbzr('commit -m blah4 --unchanged')
86
os.chdir('../b/subdir')
87
self.runbzr('pull ../../a')
88
self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
89
self.runbzr('commit -m blah5 --unchanged')
90
self.runbzr('commit -m blah6 --unchanged')
92
self.runbzr('pull ../a')
94
self.runbzr('commit -m blah7 --unchanged')
95
self.runbzr('merge ../b')
96
self.runbzr('commit -m blah8 --unchanged')
97
self.runbzr('pull ../b')
98
self.runbzr('pull ../b')
100
def test_pull_revision(self):
101
"""Pull some changes from one branch to another."""
105
self.example_branch()
106
file('hello2', 'wt').write('foo')
107
self.runbzr('add hello2')
108
self.runbzr('commit -m setup hello2')
109
file('goodbye2', 'wt').write('baz')
110
self.runbzr('add goodbye2')
111
self.runbzr('commit -m setup goodbye2')
114
self.runbzr('branch -r 1 a b')
116
self.runbzr('pull -r 2')
117
a = Branch.open('../a')
119
self.assertEquals(a.revno(),4)
120
self.assertEquals(b.revno(),2)
121
self.runbzr('pull -r 3')
122
self.assertEquals(b.revno(),3)
123
self.runbzr('pull -r 4')
124
self.assertEquals(a.revision_history(), b.revision_history())
127
def test_overwrite_uptodate(self):
128
# Make sure pull --overwrite overwrites
129
# even if the target branch has merged
130
# everything already.
133
def get_rh(expected_len):
134
rh = self.capture('revision-history')
135
# Make sure we don't have trailing empty revisions
136
rh = rh.strip().split('\n')
137
self.assertEqual(len(rh), expected_len)
143
open('foo', 'wb').write('original\n')
145
bzr('commit', '-m', 'initial commit')
148
bzr('branch', 'a', 'b')
151
open('foo', 'wb').write('changed\n')
152
bzr('commit', '-m', 'later change')
154
open('foo', 'wb').write('another\n')
155
bzr('commit', '-m', 'a third change')
157
rev_history_a = get_rh(3)
161
bzr('commit', '-m', 'merge')
163
rev_history_b = get_rh(2)
165
bzr('pull', '--overwrite', '../a')
166
rev_history_b = get_rh(3)
168
self.assertEqual(rev_history_b, rev_history_a)
170
def test_overwrite_children(self):
171
# Make sure pull --overwrite sets the revision-history
172
# to be identical to the pull source, even if we have convergence
175
def get_rh(expected_len):
176
rh = self.capture('revision-history')
177
# Make sure we don't have trailing empty revisions
178
rh = rh.strip().split('\n')
179
self.assertEqual(len(rh), expected_len)
185
open('foo', 'wb').write('original\n')
187
bzr('commit', '-m', 'initial commit')
190
bzr('branch', 'a', 'b')
193
open('foo', 'wb').write('changed\n')
194
bzr('commit', '-m', 'later change')
196
open('foo', 'wb').write('another\n')
197
bzr('commit', '-m', 'a third change')
199
rev_history_a = get_rh(3)
203
bzr('commit', '-m', 'merge')
205
rev_history_b = get_rh(2)
208
open('foo', 'wb').write('a fourth change\n')
209
bzr('commit', '-m', 'a fourth change')
211
rev_history_a = get_rh(4)
213
# With convergence, we could just pull over the
214
# new change, but with --overwrite, we want to switch our history
216
bzr('pull', '--overwrite', '../a')
217
rev_history_b = get_rh(4)
219
self.assertEqual(rev_history_b, rev_history_a)
221
def test_pull_remember(self):
222
"""Pull changes from one branch to another and test parent location."""
223
transport = self.get_transport()
224
tree_a = self.make_branch_and_tree('branch_a')
225
branch_a = tree_a.branch
226
self.build_tree(['branch_a/a'])
228
tree_a.commit('commit a')
229
tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
230
branch_b = tree_b.branch
231
tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
232
branch_c = tree_c.branch
233
self.build_tree(['branch_a/b'])
235
tree_a.commit('commit b')
237
parent = branch_b.get_parent()
238
branch_b.set_parent(None)
239
self.assertEqual(None, branch_b.get_parent())
240
# test pull for failure without parent set
242
out = self.runbzr('pull', retcode=3)
243
self.assertEquals(out,
244
('','bzr: ERROR: No pull location known or specified.\n'))
245
# test implicit --remember when no parent set, this pull conflicts
246
self.build_tree(['d'])
248
tree_b.commit('commit d')
249
out = self.runbzr('pull ../branch_a', retcode=3)
250
self.assertEquals(out,
251
('','bzr: ERROR: These branches have diverged. Try merge.\n'))
252
self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
253
# test implicit --remember after resolving previous failure
254
uncommit(branch=branch_b, tree=tree_b)
255
transport.delete('branch_b/d')
257
self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
258
# test explicit --remember
259
self.runbzr('pull ../branch_c --remember')
260
self.assertEquals(abspath(branch_b.get_parent()),
261
abspath(branch_c.bzrdir.root_transport.base))