1#!/bin/sh
2#
3# Copyright (c) 2012 Felipe Contreras
4#
5
6test_description='Test remote-bzr'
7
8. ./test-lib.sh
9
10if ! test_have_prereq PYTHON; then
11 skip_all='skipping remote-bzr tests; python not available'
12 test_done
13fi
14
15if ! python -c 'import bzrlib'; then
16 skip_all='skipping remote-bzr tests; bzr not available'
17 test_done
18fi
19
20check () {
21 (
22 cd $1 &&
23 git log --format='%s' -1 &&
24 git symbolic-ref HEAD
25 ) > actual &&
26 (
27 echo $2 &&
28 echo "refs/heads/$3"
29 ) > expected &&
30 test_cmp expected actual
31}
32
33bzr whoami "A U Thor <author@example.com>"
34
35test_expect_success 'cloning' '
36 (
37 bzr init bzrrepo &&
38 cd bzrrepo &&
39 echo one > content &&
40 bzr add content &&
41 bzr commit -m one
42 ) &&
43
44 git clone "bzr::bzrrepo" gitrepo &&
45 check gitrepo one master
46'
47
48test_expect_success 'pulling' '
49 (
50 cd bzrrepo &&
51 echo two > content &&
52 bzr commit -m two
53 ) &&
54
55 (cd gitrepo && git pull) &&
56
57 check gitrepo two master
58'
59
60test_expect_success 'pushing' '
61 (
62 cd gitrepo &&
63 echo three > content &&
64 git commit -a -m three &&
65 git push
66 ) &&
67
68 echo three > expected &&
69 cat bzrrepo/content > actual &&
70 test_cmp expected actual
71'
72
73test_expect_success 'roundtrip' '
74 (
75 cd gitrepo &&
76 git pull &&
77 git log --format="%s" -1 origin/master > actual
78 ) &&
79 echo three > expected &&
80 test_cmp expected actual &&
81
82 (cd gitrepo && git push && git pull) &&
83
84 (
85 cd bzrrepo &&
86 echo four > content &&
87 bzr commit -m four
88 ) &&
89
90 (cd gitrepo && git pull && git push) &&
91
92 check gitrepo four master &&
93
94 (
95 cd gitrepo &&
96 echo five > content &&
97 git commit -a -m five &&
98 git push && git pull
99 ) &&
100
101 (cd bzrrepo && bzr revert) &&
102
103 echo five > expected &&
104 cat bzrrepo/content > actual &&
105 test_cmp expected actual
106'
107
108cat > expected <<EOF
109100644 blob 54f9d6da5c91d556e6b54340b1327573073030af content
110100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb executable
111120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea link
112EOF
113
114test_expect_success 'special modes' '
115 (
116 cd bzrrepo &&
117 echo exec > executable
118 chmod +x executable &&
119 bzr add executable
120 bzr commit -m exec &&
121 ln -s content link
122 bzr add link
123 bzr commit -m link &&
124 mkdir dir &&
125 bzr add dir &&
126 bzr commit -m dir
127 ) &&
128
129 (
130 cd gitrepo &&
131 git pull
132 git ls-tree HEAD > ../actual
133 ) &&
134
135 test_cmp expected actual &&
136
137 (
138 cd gitrepo &&
139 git cat-file -p HEAD:link > ../actual
140 ) &&
141
142 printf content > expected &&
143 test_cmp expected actual
144'
145
146cat > expected <<EOF
147100644 blob 54f9d6da5c91d556e6b54340b1327573073030af content
148100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb executable
149120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea link
150040000 tree 35c0caa46693cef62247ac89a680f0c5ce32b37b movedir-new
151EOF
152
153test_expect_success 'moving directory' '
154 (
155 cd bzrrepo &&
156 mkdir movedir &&
157 echo one > movedir/one &&
158 echo two > movedir/two &&
159 bzr add movedir &&
160 bzr commit -m movedir &&
161 bzr mv movedir movedir-new &&
162 bzr commit -m movedir-new
163 ) &&
164
165 (
166 cd gitrepo &&
167 git pull &&
168 git ls-tree HEAD > ../actual
169 ) &&
170
171 test_cmp expected actual
172'
173
174test_expect_success 'different authors' '
175 (
176 cd bzrrepo &&
177 echo john >> content &&
178 bzr commit -m john \
179 --author "Jane Rey <jrey@example.com>" \
180 --author "John Doe <jdoe@example.com>"
181 ) &&
182
183 (
184 cd gitrepo &&
185 git pull &&
186 git show --format="%an <%ae>, %cn <%ce>" --quiet > ../actual
187 ) &&
188
189 echo "Jane Rey <jrey@example.com>, A U Thor <author@example.com>" > expected &&
190 test_cmp expected actual
191'
192
193# cleanup previous stuff
194rm -rf bzrrepo gitrepo
195
196test_expect_success 'fetch utf-8 filenames' '
197 test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C" &&
198
199 LC_ALL=en_US.UTF-8
200 export LC_ALL
201
202 (
203 bzr init bzrrepo &&
204 cd bzrrepo &&
205
206 echo test >> "ærø" &&
207 bzr add "ærø" &&
208 echo test >> "ø~?" &&
209 bzr add "ø~?" &&
210 bzr commit -m add-utf-8 &&
211 echo test >> "ærø" &&
212 bzr commit -m test-utf-8 &&
213 bzr rm "ø~?" &&
214 bzr mv "ærø" "ø~?" &&
215 bzr commit -m bzr-mv-utf-8
216 ) &&
217
218 (
219 git clone "bzr::bzrrepo" gitrepo &&
220 cd gitrepo &&
221 git -c core.quotepath=false ls-files > ../actual
222 ) &&
223 echo "ø~?" > expected &&
224 test_cmp expected actual
225'
226
227test_expect_success 'push utf-8 filenames' '
228 test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C" &&
229
230 mkdir -p tmp && cd tmp &&
231
232 LC_ALL=en_US.UTF-8
233 export LC_ALL
234
235 (
236 bzr init bzrrepo &&
237 cd bzrrepo &&
238
239 echo one >> content &&
240 bzr add content &&
241 bzr commit -m one
242 ) &&
243
244 (
245 git clone "bzr::bzrrepo" gitrepo &&
246 cd gitrepo &&
247
248 echo test >> "ærø" &&
249 git add "ærø" &&
250 git commit -m utf-8 &&
251
252 git push
253 ) &&
254
255 (cd bzrrepo && bzr ls > ../actual) &&
256 printf "content\nærø\n" > expected &&
257 test_cmp expected actual
258'
259
260test_expect_success 'pushing a merge' '
261 test_when_finished "rm -rf bzrrepo gitrepo" &&
262
263 (
264 bzr init bzrrepo &&
265 cd bzrrepo &&
266 echo one > content &&
267 bzr add content &&
268 bzr commit -m one
269 ) &&
270
271 git clone "bzr::bzrrepo" gitrepo &&
272
273 (
274 cd bzrrepo &&
275 echo two > content &&
276 bzr commit -m two
277 ) &&
278
279 (
280 cd gitrepo &&
281 echo three > content &&
282 git commit -a -m three &&
283 git fetch &&
284 git merge origin/master || true &&
285 echo three > content &&
286 git commit -a --no-edit &&
287 git push
288 ) &&
289
290 echo three > expected &&
291 cat bzrrepo/content > actual &&
292 test_cmp expected actual
293'
294
295cat > expected <<EOF
296origin/HEAD
297origin/branch
298origin/trunk
299EOF
300
301test_expect_success 'proper bzr repo' '
302 test_when_finished "rm -rf bzrrepo gitrepo" &&
303
304 bzr init-repo bzrrepo &&
305
306 (
307 bzr init bzrrepo/trunk &&
308 cd bzrrepo/trunk &&
309 echo one >> content &&
310 bzr add content &&
311 bzr commit -m one
312 ) &&
313
314 (
315 bzr branch bzrrepo/trunk bzrrepo/branch &&
316 cd bzrrepo/branch &&
317 echo two >> content &&
318 bzr commit -m one
319 ) &&
320
321 (
322 git clone "bzr::bzrrepo" gitrepo &&
323 cd gitrepo &&
324 git for-each-ref --format "%(refname:short)" refs/remotes/origin > ../actual
325 ) &&
326
327 test_cmp expected actual
328'
329
330test_expect_success 'strip' '
331 test_when_finished "rm -rf bzrrepo gitrepo" &&
332
333 (
334 bzr init bzrrepo &&
335 cd bzrrepo &&
336
337 echo one >> content &&
338 bzr add content &&
339 bzr commit -m one &&
340
341 echo two >> content &&
342 bzr commit -m two
343 ) &&
344
345 git clone "bzr::bzrrepo" gitrepo &&
346
347 (
348 cd bzrrepo &&
349 bzr uncommit --force &&
350
351 echo three >> content &&
352 bzr commit -m three &&
353
354 echo four >> content &&
355 bzr commit -m four &&
356 bzr log --line | sed -e "s/^[0-9][0-9]*: //" > ../expected
357 ) &&
358
359 (
360 cd gitrepo &&
361 git fetch &&
362 git log --format="%an %ad %s" --date=short origin/master > ../actual
363 ) &&
364
365 test_cmp expected actual
366'
367
368test_done