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.tests.blackbox import ExternalBase
27
from bzrlib.osutils import abspath
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
if sys.platform not in ('win32', 'cygwin'):
52
# This is equivalent to doing "bzr pull ."
53
# Which means that bzr creates 2 branches grabbing
54
# the same location, and tries to pull.
55
# However, 2 branches mean 2 locks on the same file
56
# which ultimately implies a deadlock.
57
# (non windows platforms allow multiple locks on the
58
# same file by the same calling process)
60
self.runbzr('pull /', retcode=3)
61
if sys.platform not in ('win32', 'cygwin'):
65
self.runbzr('branch a b')
69
self.runbzr('add subdir')
70
self.runbzr('commit -m blah --unchanged')
73
b = Branch.open('../b')
74
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
75
self.runbzr('pull ../b')
76
self.assertEquals(a.revision_history(), b.revision_history())
77
self.runbzr('commit -m blah2 --unchanged')
79
self.runbzr('commit -m blah3 --unchanged')
81
self.runbzr('pull ../a', retcode=3)
83
self.runbzr('branch b overwriteme')
84
os.chdir('overwriteme')
85
self.runbzr('pull --overwrite ../a')
86
overwritten = Branch.open('.')
87
self.assertEqual(overwritten.revision_history(),
90
self.runbzr('merge ../b')
91
self.runbzr('commit -m blah4 --unchanged')
92
os.chdir('../b/subdir')
93
self.runbzr('pull ../../a')
94
self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
95
self.runbzr('commit -m blah5 --unchanged')
96
self.runbzr('commit -m blah6 --unchanged')
98
self.runbzr('pull ../a')
100
self.runbzr('commit -m blah7 --unchanged')
101
self.runbzr('merge ../b')
102
self.runbzr('commit -m blah8 --unchanged')
103
self.runbzr('pull ../b')
104
self.runbzr('pull ../b')
106
def test_pull_revision(self):
107
"""Pull some changes from one branch to another."""
111
self.example_branch()
112
file('hello2', 'wt').write('foo')
113
self.runbzr('add hello2')
114
self.runbzr('commit -m setup hello2')
115
file('goodbye2', 'wt').write('baz')
116
self.runbzr('add goodbye2')
117
self.runbzr('commit -m setup goodbye2')
120
self.runbzr('branch -r 1 a b')
122
self.runbzr('pull -r 2')
123
a = Branch.open('../a')
125
self.assertEquals(a.revno(),4)
126
self.assertEquals(b.revno(),2)
127
self.runbzr('pull -r 3')
128
self.assertEquals(b.revno(),3)
129
self.runbzr('pull -r 4')
130
self.assertEquals(a.revision_history(), b.revision_history())
133
def test_overwrite_uptodate(self):
134
# Make sure pull --overwrite overwrites
135
# even if the target branch has merged
136
# everything already.
139
def get_rh(expected_len):
140
rh = self.capture('revision-history')
141
# Make sure we don't have trailing empty revisions
142
rh = rh.strip().split('\n')
143
self.assertEqual(len(rh), expected_len)
149
open('foo', 'wb').write('original\n')
151
bzr('commit', '-m', 'initial commit')
154
bzr('branch', 'a', 'b')
157
open('foo', 'wb').write('changed\n')
158
bzr('commit', '-m', 'later change')
160
open('foo', 'wb').write('another\n')
161
bzr('commit', '-m', 'a third change')
163
rev_history_a = get_rh(3)
167
bzr('commit', '-m', 'merge')
169
rev_history_b = get_rh(2)
171
bzr('pull', '--overwrite', '../a')
172
rev_history_b = get_rh(3)
174
self.assertEqual(rev_history_b, rev_history_a)
176
def test_overwrite_children(self):
177
# Make sure pull --overwrite sets the revision-history
178
# to be identical to the pull source, even if we have convergence
181
def get_rh(expected_len):
182
rh = self.capture('revision-history')
183
# Make sure we don't have trailing empty revisions
184
rh = rh.strip().split('\n')
185
self.assertEqual(len(rh), expected_len)
191
open('foo', 'wb').write('original\n')
193
bzr('commit', '-m', 'initial commit')
196
bzr('branch', 'a', 'b')
199
open('foo', 'wb').write('changed\n')
200
bzr('commit', '-m', 'later change')
202
open('foo', 'wb').write('another\n')
203
bzr('commit', '-m', 'a third change')
205
rev_history_a = get_rh(3)
209
bzr('commit', '-m', 'merge')
211
rev_history_b = get_rh(2)
214
open('foo', 'wb').write('a fourth change\n')
215
bzr('commit', '-m', 'a fourth change')
217
rev_history_a = get_rh(4)
219
# With convergence, we could just pull over the
220
# new change, but with --overwrite, we want to switch our history
222
bzr('pull', '--overwrite', '../a')
223
rev_history_b = get_rh(4)
225
self.assertEqual(rev_history_b, rev_history_a)
227
def test_pull_remember(self):
228
"""Pull changes from one branch to another and test parent location."""
232
self.example_branch()
233
self.runbzr('branch . ../b')
234
self.runbzr('branch . ../c')
235
file('bottles', 'wt').write('99 bottles of beer on the wall')
236
self.runbzr('add bottles')
237
self.runbzr('commit -m 99_bottles')
240
parent = b.get_parent()
243
self.assertEqual(None, b.get_parent())
244
# test pull for failure without parent set
245
out = self.runbzr('pull', retcode=3)
246
self.assertEquals(out,
247
('','bzr: ERROR: No pull location known or specified.\n'))
248
# test implicit --remember when no parent set, this pull conflicts
249
file('bottles', 'wt').write('98 bottles of beer on the wall')
250
self.runbzr('add bottles')
251
self.runbzr('commit -m 98_bottles')
252
out = self.runbzr('pull ../a', retcode=3)
253
self.assertEquals(out,
254
('','bzr: ERROR: These branches have diverged. Try merge.\n'))
255
self.assertEquals(abspath(b.get_parent()), abspath(parent))
256
# test implicit --remember after resolving previous failure
257
self.runbzr('uncommit --force')
259
self.assertEquals(abspath(b.get_parent()), abspath(parent))
260
# test explicit --remember
261
self.runbzr('pull ../c --remember')
262
self.assertEquals(abspath(b.get_parent()), abspath('../c'))