bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
1185.50.5
by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer) |
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
|
|
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.
|
|
8 |
||
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.
|
|
13 |
||
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
|
|
17 |
||
18 |
||
|
1185.50.8
by John Arbash Meinel
Cleanup of test_pull.py headers |
19 |
"""Black-box tests for bzr pull.
|
|
1185.50.5
by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer) |
20 |
"""
|
21 |
||
22 |
import os |
|
23 |
import sys |
|
24 |
||
25 |
from bzrlib.branch import Branch |
|
26 |
from bzrlib.tests.blackbox import ExternalBase |
|
|
1614.2.8
by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to |
27 |
from bzrlib.osutils import abspath |
28 |
||
|
1185.50.5
by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer) |
29 |
|
|
1185.50.7
by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull |
30 |
class TestPull(ExternalBase): |
31 |
||
32 |
def example_branch(test): |
|
33 |
test.runbzr('init') |
|
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') |
|
|
1185.50.5
by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer) |
40 |
|
41 |
def test_pull(self): |
|
42 |
"""Pull changes from one branch to another.""" |
|
43 |
os.mkdir('a') |
|
44 |
os.chdir('a') |
|
45 |
||
46 |
self.example_branch() |
|
47 |
self.runbzr('pull', retcode=3) |
|
48 |
self.runbzr('missing', retcode=3) |
|
49 |
self.runbzr('missing .') |
|
50 |
self.runbzr('missing') |
|
|
1185.31.31
by John Arbash Meinel
avoiding 'bzr pull .' means all tests pass under cygwin |
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)
|
|
59 |
self.runbzr('pull') |
|
|
1185.50.5
by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer) |
60 |
self.runbzr('pull /', retcode=3) |
|
1185.31.31
by John Arbash Meinel
avoiding 'bzr pull .' means all tests pass under cygwin |
61 |
if sys.platform not in ('win32', 'cygwin'): |
62 |
self.runbzr('pull') |
|
|
1185.50.5
by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer) |
63 |
|
64 |
os.chdir('..') |
|
65 |
self.runbzr('branch a b') |
|
66 |
os.chdir('b') |
|
67 |
self.runbzr('pull') |
|
68 |
os.mkdir('subdir') |
|
69 |
self.runbzr('add subdir') |
|
70 |
self.runbzr('commit -m blah --unchanged') |
|
71 |
os.chdir('../a') |
|
72 |
a = Branch.open('.') |
|
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') |
|
78 |
os.chdir('../b') |
|
79 |
self.runbzr('commit -m blah3 --unchanged') |
|
80 |
# no overwrite
|
|
81 |
self.runbzr('pull ../a', retcode=3) |
|
82 |
os.chdir('..') |
|
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(), |
|
88 |
a.revision_history()) |
|
89 |
os.chdir('../a') |
|
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') |
|
97 |
os.chdir('..') |
|
98 |
self.runbzr('pull ../a') |
|
99 |
os.chdir('../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') |
|
105 |
||
|
1185.76.2
by Erik Bågfors
test for pull --revision |
106 |
def test_pull_revision(self): |
107 |
"""Pull some changes from one branch to another.""" |
|
108 |
os.mkdir('a') |
|
109 |
os.chdir('a') |
|
110 |
||
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') |
|
118 |
||
119 |
os.chdir('..') |
|
120 |
self.runbzr('branch -r 1 a b') |
|
121 |
os.chdir('b') |
|
122 |
self.runbzr('pull -r 2') |
|
123 |
a = Branch.open('../a') |
|
124 |
b = Branch.open('.') |
|
|
1185.76.4
by Erik Bågfors
expanded tabs |
125 |
self.assertEquals(a.revno(),4) |
126 |
self.assertEquals(b.revno(),2) |
|
|
1185.76.2
by Erik Bågfors
test for pull --revision |
127 |
self.runbzr('pull -r 3') |
|
1185.76.4
by Erik Bågfors
expanded tabs |
128 |
self.assertEquals(b.revno(),3) |
|
1185.76.2
by Erik Bågfors
test for pull --revision |
129 |
self.runbzr('pull -r 4') |
130 |
self.assertEquals(a.revision_history(), b.revision_history()) |
|
131 |
||
132 |
||
|
1185.50.7
by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull |
133 |
def test_overwrite_uptodate(self): |
|
1185.50.5
by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer) |
134 |
# Make sure pull --overwrite overwrites
|
135 |
# even if the target branch has merged
|
|
136 |
# everything already.
|
|
137 |
bzr = self.run_bzr |
|
138 |
||
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) |
|
144 |
return rh |
|
145 |
||
146 |
os.mkdir('a') |
|
147 |
os.chdir('a') |
|
148 |
bzr('init') |
|
149 |
open('foo', 'wb').write('original\n') |
|
150 |
bzr('add', 'foo') |
|
151 |
bzr('commit', '-m', 'initial commit') |
|
152 |
||
153 |
os.chdir('..') |
|
154 |
bzr('branch', 'a', 'b') |
|
155 |
||
156 |
os.chdir('a') |
|
157 |
open('foo', 'wb').write('changed\n') |
|
158 |
bzr('commit', '-m', 'later change') |
|
159 |
||
160 |
open('foo', 'wb').write('another\n') |
|
161 |
bzr('commit', '-m', 'a third change') |
|
162 |
||
163 |
rev_history_a = get_rh(3) |
|
164 |
||
165 |
os.chdir('../b') |
|
166 |
bzr('merge', '../a') |
|
167 |
bzr('commit', '-m', 'merge') |
|
168 |
||
169 |
rev_history_b = get_rh(2) |
|
170 |
||
171 |
bzr('pull', '--overwrite', '../a') |
|
172 |
rev_history_b = get_rh(3) |
|
173 |
||
174 |
self.assertEqual(rev_history_b, rev_history_a) |
|
175 |
||
|
1185.50.7
by John Arbash Meinel
Fix broken test from refactoring blackbox/test_pull |
176 |
def test_overwrite_children(self): |
|
1185.50.5
by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer) |
177 |
# Make sure pull --overwrite sets the revision-history
|
178 |
# to be identical to the pull source, even if we have convergence
|
|
179 |
bzr = self.run_bzr |
|
180 |
||
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) |
|
186 |
return rh |
|
187 |
||
188 |
os.mkdir('a') |
|
189 |
os.chdir('a') |
|
190 |
bzr('init') |
|
191 |
open('foo', 'wb').write('original\n') |
|
192 |
bzr('add', 'foo') |
|
193 |
bzr('commit', '-m', 'initial commit') |
|
194 |
||
195 |
os.chdir('..') |
|
196 |
bzr('branch', 'a', 'b') |
|
197 |
||
198 |
os.chdir('a') |
|
199 |
open('foo', 'wb').write('changed\n') |
|
200 |
bzr('commit', '-m', 'later change') |
|
201 |
||
202 |
open('foo', 'wb').write('another\n') |
|
203 |
bzr('commit', '-m', 'a third change') |
|
204 |
||
205 |
rev_history_a = get_rh(3) |
|
206 |
||
207 |
os.chdir('../b') |
|
208 |
bzr('merge', '../a') |
|
209 |
bzr('commit', '-m', 'merge') |
|
210 |
||
211 |
rev_history_b = get_rh(2) |
|
212 |
||
213 |
os.chdir('../a') |
|
214 |
open('foo', 'wb').write('a fourth change\n') |
|
215 |
bzr('commit', '-m', 'a fourth change') |
|
216 |
||
217 |
rev_history_a = get_rh(4) |
|
218 |
||
219 |
# With convergence, we could just pull over the
|
|
220 |
# new change, but with --overwrite, we want to switch our history
|
|
221 |
os.chdir('../b') |
|
222 |
bzr('pull', '--overwrite', '../a') |
|
223 |
rev_history_b = get_rh(4) |
|
224 |
||
225 |
self.assertEqual(rev_history_b, rev_history_a) |
|
226 |
||
|
1614.2.8
by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to |
227 |
def test_pull_remember(self): |
228 |
"""Pull changes from one branch to another and test parent location.""" |
|
229 |
os.mkdir('a') |
|
230 |
os.chdir('a') |
|
|
1185.50.5
by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer) |
231 |
|
|
1614.2.8
by Olaf Conradi
Added testcases for using pull with --remember. Moved remember code to |
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') |
|
238 |
os.chdir('../b') |
|
239 |
b = Branch.open('') |
|
240 |
parent = b.get_parent() |
|
241 |
# reset parent
|
|
242 |
b.set_parent(None) |
|
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') |
|
258 |
self.runbzr('pull') |
|
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')) |