Merge branch 'jc/graduate-remote-hg-bzr' (early part)
[git/git.git] / contrib / remote-helpers / test-bzr.sh
CommitLineData
77b71edf
FC
1#!/bin/sh
2#
3# Copyright (c) 2012 Felipe Contreras
4#
5
6test_description='Test remote-bzr'
7
d3243d73
FC
8test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
9. "$TEST_DIRECTORY"/test-lib.sh
77b71edf 10
ff867963
JH
11if ! test_have_prereq PYTHON
12then
77b71edf
FC
13 skip_all='skipping remote-bzr tests; python not available'
14 test_done
15fi
16
ff867963
JH
17if ! python -c 'import bzrlib'
18then
77b71edf
FC
19 skip_all='skipping remote-bzr tests; bzr not available'
20 test_done
21fi
22
77b71edf 23check () {
ff867963
JH
24 echo $3 >expected &&
25 git --git-dir=$1/.git log --format='%s' -1 $2 >actual
77b71edf
FC
26 test_cmp expected actual
27}
28
29bzr whoami "A U Thor <author@example.com>"
30
31test_expect_success 'cloning' '
dde67d79
FC
32 (
33 bzr init bzrrepo &&
4080ac81 34 cd bzrrepo &&
ff867963 35 echo one >content &&
4080ac81
FC
36 bzr add content &&
37 bzr commit -m one
38 ) &&
39
5f5e92fb 40 git clone "bzr::bzrrepo" gitrepo &&
0067ecc8 41 check gitrepo HEAD one
77b71edf
FC
42'
43
44test_expect_success 'pulling' '
dde67d79
FC
45 (
46 cd bzrrepo &&
ff867963 47 echo two >content &&
4080ac81
FC
48 bzr commit -m two
49 ) &&
77b71edf 50
4080ac81 51 (cd gitrepo && git pull) &&
77b71edf 52
0067ecc8 53 check gitrepo HEAD two
77b71edf
FC
54'
55
56test_expect_success 'pushing' '
dde67d79
FC
57 (
58 cd gitrepo &&
ff867963 59 echo three >content &&
4080ac81
FC
60 git commit -a -m three &&
61 git push
62 ) &&
63
ff867963
JH
64 echo three >expected &&
65 cat bzrrepo/content >actual &&
4080ac81 66 test_cmp expected actual
77b71edf
FC
67'
68
a7cb1276
RH
69test_expect_success 'forced pushing' '
70 (
71 cd gitrepo &&
72 echo three-new >content &&
73 git commit -a --amend -m three-new &&
74 git push -f
75 ) &&
76
77 (
78 cd bzrrepo &&
79 # the forced update overwrites the bzr branch but not the bzr
80 # working directory (it tries to merge instead)
81 bzr revert
82 ) &&
83
84 echo three-new >expected &&
85 cat bzrrepo/content >actual &&
86 test_cmp expected actual
87'
88
77b71edf 89test_expect_success 'roundtrip' '
dde67d79
FC
90 (
91 cd gitrepo &&
4080ac81 92 git pull &&
ff867963 93 git log --format="%s" -1 origin/master >actual
dde67d79 94 ) &&
a7cb1276 95 echo three-new >expected &&
4080ac81 96 test_cmp expected actual &&
77b71edf 97
4080ac81 98 (cd gitrepo && git push && git pull) &&
77b71edf 99
dde67d79
FC
100 (
101 cd bzrrepo &&
ff867963 102 echo four >content &&
4080ac81
FC
103 bzr commit -m four
104 ) &&
77b71edf 105
4080ac81 106 (cd gitrepo && git pull && git push) &&
77b71edf 107
0067ecc8 108 check gitrepo HEAD four &&
77b71edf 109
dde67d79
FC
110 (
111 cd gitrepo &&
ff867963 112 echo five >content &&
4080ac81
FC
113 git commit -a -m five &&
114 git push && git pull
115 ) &&
77b71edf 116
4080ac81 117 (cd bzrrepo && bzr revert) &&
77b71edf 118
ff867963
JH
119 echo five >expected &&
120 cat bzrrepo/content >actual &&
4080ac81 121 test_cmp expected actual
77b71edf
FC
122'
123
ff867963 124cat >expected <<\EOF
bdeeb809
FC
125100644 blob 54f9d6da5c91d556e6b54340b1327573073030af content
126100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb executable
127120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea link
128EOF
129
130test_expect_success 'special modes' '
dde67d79
FC
131 (
132 cd bzrrepo &&
ff867963 133 echo exec >executable
4080ac81
FC
134 chmod +x executable &&
135 bzr add executable
136 bzr commit -m exec &&
137 ln -s content link
138 bzr add link
139 bzr commit -m link &&
140 mkdir dir &&
141 bzr add dir &&
dde67d79
FC
142 bzr commit -m dir
143 ) &&
4080ac81 144
dde67d79
FC
145 (
146 cd gitrepo &&
4080ac81 147 git pull
ff867963 148 git ls-tree HEAD >../actual
dde67d79 149 ) &&
4080ac81
FC
150
151 test_cmp expected actual &&
152
dde67d79
FC
153 (
154 cd gitrepo &&
ff867963 155 git cat-file -p HEAD:link >../actual
dde67d79 156 ) &&
4080ac81 157
ff867963 158 printf content >expected &&
4080ac81 159 test_cmp expected actual
bdeeb809
FC
160'
161
ff867963 162cat >expected <<\EOF
82447e33
CS
163100644 blob 54f9d6da5c91d556e6b54340b1327573073030af content
164100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb executable
165120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea link
166040000 tree 35c0caa46693cef62247ac89a680f0c5ce32b37b movedir-new
167EOF
168
169test_expect_success 'moving directory' '
dde67d79
FC
170 (
171 cd bzrrepo &&
4080ac81 172 mkdir movedir &&
ff867963
JH
173 echo one >movedir/one &&
174 echo two >movedir/two &&
4080ac81
FC
175 bzr add movedir &&
176 bzr commit -m movedir &&
177 bzr mv movedir movedir-new &&
dde67d79
FC
178 bzr commit -m movedir-new
179 ) &&
4080ac81 180
dde67d79
FC
181 (
182 cd gitrepo &&
4080ac81 183 git pull &&
ff867963 184 git ls-tree HEAD >../actual
dde67d79 185 ) &&
4080ac81
FC
186
187 test_cmp expected actual
82447e33
CS
188'
189
9d9d698c 190test_expect_success 'different authors' '
dde67d79
FC
191 (
192 cd bzrrepo &&
ff867963 193 echo john >>content &&
4080ac81
FC
194 bzr commit -m john \
195 --author "Jane Rey <jrey@example.com>" \
dde67d79
FC
196 --author "John Doe <jdoe@example.com>"
197 ) &&
4080ac81 198
dde67d79
FC
199 (
200 cd gitrepo &&
4080ac81 201 git pull &&
ff867963 202 git show --format="%an <%ae>, %cn <%ce>" --quiet >../actual
dde67d79 203 ) &&
4080ac81 204
ff867963 205 echo "Jane Rey <jrey@example.com>, A U Thor <author@example.com>" >expected &&
4080ac81 206 test_cmp expected actual
9d9d698c
DE
207'
208
531594e5
FC
209# cleanup previous stuff
210rm -rf bzrrepo gitrepo
211
5445b24e 212test_expect_success 'fetch utf-8 filenames' '
531594e5 213 test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C" &&
4080ac81
FC
214
215 LC_ALL=en_US.UTF-8
216 export LC_ALL
dde67d79 217
4080ac81
FC
218 (
219 bzr init bzrrepo &&
220 cd bzrrepo &&
221
ff867963 222 echo test >>"ærø" &&
4080ac81 223 bzr add "ærø" &&
ff867963 224 echo test >>"ø~?" &&
4080ac81
FC
225 bzr add "ø~?" &&
226 bzr commit -m add-utf-8 &&
ff867963 227 echo test >>"ærø" &&
4080ac81
FC
228 bzr commit -m test-utf-8 &&
229 bzr rm "ø~?" &&
230 bzr mv "ærø" "ø~?" &&
231 bzr commit -m bzr-mv-utf-8
232 ) &&
233
234 (
5f5e92fb 235 git clone "bzr::bzrrepo" gitrepo &&
4080ac81 236 cd gitrepo &&
ff867963 237 git -c core.quotepath=false ls-files >../actual
4080ac81 238 ) &&
ff867963 239 echo "ø~?" >expected &&
4080ac81 240 test_cmp expected actual
5445b24e
TP
241'
242
6ff8d4e7 243test_expect_success 'push utf-8 filenames' '
531594e5
FC
244 test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C" &&
245
4080ac81 246 mkdir -p tmp && cd tmp &&
6ff8d4e7 247
4080ac81
FC
248 LC_ALL=en_US.UTF-8
249 export LC_ALL
6ff8d4e7 250
4080ac81
FC
251 (
252 bzr init bzrrepo &&
253 cd bzrrepo &&
6ff8d4e7 254
ff867963 255 echo one >>content &&
4080ac81
FC
256 bzr add content &&
257 bzr commit -m one
258 ) &&
6ff8d4e7 259
4080ac81 260 (
5f5e92fb 261 git clone "bzr::bzrrepo" gitrepo &&
4080ac81 262 cd gitrepo &&
6ff8d4e7 263
ff867963 264 echo test >>"ærø" &&
4080ac81
FC
265 git add "ærø" &&
266 git commit -m utf-8 &&
6ff8d4e7 267
4080ac81
FC
268 git push
269 ) &&
6ff8d4e7 270
ff867963
JH
271 (cd bzrrepo && bzr ls >../actual) &&
272 printf "content\nærø\n" >expected &&
4080ac81 273 test_cmp expected actual
6ff8d4e7
FC
274'
275
f38dfc4c 276test_expect_success 'pushing a merge' '
531594e5 277 test_when_finished "rm -rf bzrrepo gitrepo" &&
4080ac81
FC
278
279 (
280 bzr init bzrrepo &&
281 cd bzrrepo &&
ff867963 282 echo one >content &&
4080ac81
FC
283 bzr add content &&
284 bzr commit -m one
285 ) &&
286
5f5e92fb 287 git clone "bzr::bzrrepo" gitrepo &&
4080ac81
FC
288
289 (
290 cd bzrrepo &&
ff867963 291 echo two >content &&
4080ac81
FC
292 bzr commit -m two
293 ) &&
294
295 (
296 cd gitrepo &&
ff867963 297 echo three >content &&
4080ac81
FC
298 git commit -a -m three &&
299 git fetch &&
300 git merge origin/master || true &&
ff867963 301 echo three >content &&
4080ac81
FC
302 git commit -a --no-edit &&
303 git push
304 ) &&
305
ff867963
JH
306 echo three >expected &&
307 cat bzrrepo/content >actual &&
4080ac81 308 test_cmp expected actual
f38dfc4c
FC
309'
310
ff867963 311cat >expected <<\EOF
95b0c608
FC
312origin/HEAD
313origin/branch
314origin/trunk
315EOF
316
317test_expect_success 'proper bzr repo' '
531594e5 318 test_when_finished "rm -rf bzrrepo gitrepo" &&
4080ac81
FC
319
320 bzr init-repo bzrrepo &&
321
4080ac81 322 (
dde67d79 323 bzr init bzrrepo/trunk &&
4080ac81 324 cd bzrrepo/trunk &&
ff867963 325 echo one >>content &&
4080ac81
FC
326 bzr add content &&
327 bzr commit -m one
328 ) &&
329
4080ac81 330 (
dde67d79 331 bzr branch bzrrepo/trunk bzrrepo/branch &&
4080ac81 332 cd bzrrepo/branch &&
ff867963 333 echo two >>content &&
4080ac81
FC
334 bzr commit -m one
335 ) &&
336
4080ac81 337 (
5f5e92fb 338 git clone "bzr::bzrrepo" gitrepo &&
4080ac81 339 cd gitrepo &&
ff867963 340 git for-each-ref --format "%(refname:short)" refs/remotes/origin >../actual
4080ac81
FC
341 ) &&
342
531594e5 343 test_cmp expected actual
95b0c608
FC
344'
345
435f39a3 346test_expect_success 'strip' '
531594e5 347 test_when_finished "rm -rf bzrrepo gitrepo" &&
435f39a3 348
4080ac81
FC
349 (
350 bzr init bzrrepo &&
351 cd bzrrepo &&
435f39a3 352
ff867963 353 echo one >>content &&
4080ac81
FC
354 bzr add content &&
355 bzr commit -m one &&
435f39a3 356
ff867963 357 echo two >>content &&
4080ac81
FC
358 bzr commit -m two
359 ) &&
435f39a3 360
5f5e92fb 361 git clone "bzr::bzrrepo" gitrepo &&
435f39a3 362
4080ac81
FC
363 (
364 cd bzrrepo &&
365 bzr uncommit --force &&
435f39a3 366
ff867963 367 echo three >>content &&
4080ac81 368 bzr commit -m three &&
435f39a3 369
ff867963 370 echo four >>content &&
4080ac81 371 bzr commit -m four &&
ff867963 372 bzr log --line | sed -e "s/^[0-9][0-9]*: //" >../expected
4080ac81 373 ) &&
435f39a3 374
dde67d79
FC
375 (
376 cd gitrepo &&
4080ac81 377 git fetch &&
ff867963 378 git log --format="%an %ad %s" --date=short origin/master >../actual
dde67d79 379 ) &&
435f39a3 380
4080ac81 381 test_cmp expected actual
435f39a3
FC
382'
383
a8c0b747 384test_expect_success 'export utf-8 authors' '
7569accf 385 test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C && GIT_COMMITTER_NAME=\"C O Mitter\""
a8c0b747
FC
386
387 LC_ALL=en_US.UTF-8
388 export LC_ALL
389
390 GIT_COMMITTER_NAME="Grégoire"
391 export GIT_COMMITTER_NAME
392
393 bzr init bzrrepo &&
394
395 (
396 git init gitrepo &&
397 cd gitrepo &&
ff867963 398 echo greg >>content &&
a8c0b747
FC
399 git add content &&
400 git commit -m one &&
401 git remote add bzr "bzr::../bzrrepo" &&
4945725c 402 git push bzr master
a8c0b747
FC
403 ) &&
404
405 (
406 cd bzrrepo &&
ff867963 407 bzr log | grep "^committer: " >../actual
a8c0b747
FC
408 ) &&
409
ff867963 410 echo "committer: Grégoire <committer@example.com>" >expected &&
a8c0b747
FC
411 test_cmp expected actual
412'
413
62210887 414test_expect_success 'push different author' '
415 test_when_finished "rm -rf bzrrepo gitrepo" &&
416
417 bzr init bzrrepo &&
418
419 (
420 git init gitrepo &&
421 cd gitrepo &&
422 echo john >> content &&
423 git add content &&
424 git commit -m john --author "John Doe <jdoe@example.com>" &&
425 git remote add bzr "bzr::../bzrrepo" &&
426 git push bzr master
427 ) &&
428
429 (
430 cd bzrrepo &&
431 bzr log | grep "^author: " > ../actual
432 ) &&
433
434 echo "author: John Doe <jdoe@example.com>" > expected &&
435 test_cmp expected actual
436'
437
77b71edf 438test_done