Merge branch 'jc/graduate-remote-hg-bzr' (early part)
[git/git.git] / contrib / remote-helpers / test-hg-hg-git.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2012 Felipe Contreras
4 #
5 # Base commands from hg-git tests:
6 # https://bitbucket.org/durin42/hg-git/src
7 #
8
9 test_description='Test remote-hg output compared to hg-git'
10
11 test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
12 . "$TEST_DIRECTORY"/test-lib.sh
13
14 if ! test_have_prereq PYTHON
15 then
16 skip_all='skipping remote-hg tests; python not available'
17 test_done
18 fi
19
20 if ! python -c 'import mercurial'
21 then
22 skip_all='skipping remote-hg tests; mercurial not available'
23 test_done
24 fi
25
26 if ! python -c 'import hggit'
27 then
28 skip_all='skipping remote-hg tests; hg-git not available'
29 test_done
30 fi
31
32 # clone to a git repo with git
33 git_clone_git () {
34 git clone -q "hg::$1" $2 &&
35 (cd $2 && git checkout master && git branch -D default)
36 }
37
38 # clone to an hg repo with git
39 hg_clone_git () {
40 (
41 hg init $2 &&
42 hg -R $2 bookmark -i master &&
43 cd $1 &&
44 git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
45 ) &&
46
47 (cd $2 && hg -q update)
48 }
49
50 # clone to a git repo with hg
51 git_clone_hg () {
52 (
53 git init -q $2 &&
54 cd $1 &&
55 hg bookmark -i -f -r tip master &&
56 hg -q push -r master ../$2 || true
57 )
58 }
59
60 # clone to an hg repo with hg
61 hg_clone_hg () {
62 hg -q clone $1 $2
63 }
64
65 # push an hg repo with git
66 hg_push_git () {
67 (
68 cd $2
69 git checkout -q -b tmp &&
70 git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
71 git branch -D default &&
72 git checkout -q @{-1} &&
73 git branch -q -D tmp 2>/dev/null || true
74 )
75 }
76
77 # push an hg git repo with hg
78 hg_push_hg () {
79 (
80 cd $1 &&
81 hg -q push ../$2 || true
82 )
83 }
84
85 hg_log () {
86 hg -R $1 log --graph --debug >log &&
87 grep -v 'tag: *default/' log
88 }
89
90 git_log () {
91 git --git-dir=$1/.git fast-export --branches
92 }
93
94 setup () {
95 (
96 echo "[ui]"
97 echo "username = A U Thor <author@example.com>"
98 echo "[defaults]"
99 echo "backout = -d \"0 0\""
100 echo "commit = -d \"0 0\""
101 echo "debugrawcommit = -d \"0 0\""
102 echo "tag = -d \"0 0\""
103 echo "[extensions]"
104 echo "hgext.bookmarks ="
105 echo "hggit ="
106 echo "graphlog ="
107 ) >>"$HOME"/.hgrc &&
108 git config --global receive.denycurrentbranch warn
109 git config --global remote-hg.hg-git-compat true
110 git config --global remote-hg.track-branches false
111
112 HGEDITOR=true
113 HGMERGE=true
114
115 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
116 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
117 export HGEDITOR HGMERGE GIT_AUTHOR_DATE GIT_COMMITTER_DATE
118 }
119
120 setup
121
122 test_expect_success 'executable bit' '
123 test_when_finished "rm -rf gitrepo* hgrepo*" &&
124
125 (
126 git init -q gitrepo &&
127 cd gitrepo &&
128 echo alpha >alpha &&
129 chmod 0644 alpha &&
130 git add alpha &&
131 git commit -m "add alpha" &&
132 chmod 0755 alpha &&
133 git add alpha &&
134 git commit -m "set executable bit" &&
135 chmod 0644 alpha &&
136 git add alpha &&
137 git commit -m "clear executable bit"
138 ) &&
139
140 for x in hg git
141 do
142 (
143 hg_clone_$x gitrepo hgrepo-$x &&
144 cd hgrepo-$x &&
145 hg_log . &&
146 hg manifest -r 1 -v &&
147 hg manifest -v
148 ) >"output-$x" &&
149
150 git_clone_$x hgrepo-$x gitrepo2-$x &&
151 git_log gitrepo2-$x >"log-$x"
152 done &&
153
154 test_cmp output-hg output-git &&
155 test_cmp log-hg log-git
156 '
157
158 test_expect_success 'symlink' '
159 test_when_finished "rm -rf gitrepo* hgrepo*" &&
160
161 (
162 git init -q gitrepo &&
163 cd gitrepo &&
164 echo alpha >alpha &&
165 git add alpha &&
166 git commit -m "add alpha" &&
167 ln -s alpha beta &&
168 git add beta &&
169 git commit -m "add beta"
170 ) &&
171
172 for x in hg git
173 do
174 (
175 hg_clone_$x gitrepo hgrepo-$x &&
176 cd hgrepo-$x &&
177 hg_log . &&
178 hg manifest -v
179 ) >"output-$x" &&
180
181 git_clone_$x hgrepo-$x gitrepo2-$x &&
182 git_log gitrepo2-$x >"log-$x"
183 done &&
184
185 test_cmp output-hg output-git &&
186 test_cmp log-hg log-git
187 '
188
189 test_expect_success 'merge conflict 1' '
190 test_when_finished "rm -rf gitrepo* hgrepo*" &&
191
192 (
193 hg init hgrepo1 &&
194 cd hgrepo1 &&
195 echo A >afile &&
196 hg add afile &&
197 hg ci -m "origin" &&
198
199 echo B >afile &&
200 hg ci -m "A->B" &&
201
202 hg up -r0 &&
203 echo C >afile &&
204 hg ci -m "A->C" &&
205
206 hg merge -r1 &&
207 echo C >afile &&
208 hg resolve -m afile &&
209 hg ci -m "merge to C"
210 ) &&
211
212 for x in hg git
213 do
214 git_clone_$x hgrepo1 gitrepo-$x &&
215 hg_clone_$x gitrepo-$x hgrepo2-$x &&
216 hg_log hgrepo2-$x >"hg-log-$x" &&
217 git_log gitrepo-$x >"git-log-$x"
218 done &&
219
220 test_cmp hg-log-hg hg-log-git &&
221 test_cmp git-log-hg git-log-git
222 '
223
224 test_expect_success 'merge conflict 2' '
225 test_when_finished "rm -rf gitrepo* hgrepo*" &&
226
227 (
228 hg init hgrepo1 &&
229 cd hgrepo1 &&
230 echo A >afile &&
231 hg add afile &&
232 hg ci -m "origin" &&
233
234 echo B >afile &&
235 hg ci -m "A->B" &&
236
237 hg up -r0 &&
238 echo C >afile &&
239 hg ci -m "A->C" &&
240
241 hg merge -r1 || true &&
242 echo B >afile &&
243 hg resolve -m afile &&
244 hg ci -m "merge to B"
245 ) &&
246
247 for x in hg git
248 do
249 git_clone_$x hgrepo1 gitrepo-$x &&
250 hg_clone_$x gitrepo-$x hgrepo2-$x &&
251 hg_log hgrepo2-$x >"hg-log-$x" &&
252 git_log gitrepo-$x >"git-log-$x"
253 done &&
254
255 test_cmp hg-log-hg hg-log-git &&
256 test_cmp git-log-hg git-log-git
257 '
258
259 test_expect_success 'converged merge' '
260 test_when_finished "rm -rf gitrepo* hgrepo*" &&
261
262 (
263 hg init hgrepo1 &&
264 cd hgrepo1 &&
265 echo A >afile &&
266 hg add afile &&
267 hg ci -m "origin" &&
268
269 echo B >afile &&
270 hg ci -m "A->B" &&
271
272 echo C >afile &&
273 hg ci -m "B->C" &&
274
275 hg up -r0 &&
276 echo C >afile &&
277 hg ci -m "A->C" &&
278
279 hg merge -r2 || true &&
280 hg ci -m "merge"
281 ) &&
282
283 for x in hg git
284 do
285 git_clone_$x hgrepo1 gitrepo-$x &&
286 hg_clone_$x gitrepo-$x hgrepo2-$x &&
287 hg_log hgrepo2-$x >"hg-log-$x" &&
288 git_log gitrepo-$x >"git-log-$x"
289 done &&
290
291 test_cmp hg-log-hg hg-log-git &&
292 test_cmp git-log-hg git-log-git
293 '
294
295 test_expect_success 'encoding' '
296 test_when_finished "rm -rf gitrepo* hgrepo*" &&
297
298 (
299 git init -q gitrepo &&
300 cd gitrepo &&
301
302 echo alpha >alpha &&
303 git add alpha &&
304 git commit -m "add älphà" &&
305
306 GIT_AUTHOR_NAME="tést èncödîng" &&
307 export GIT_AUTHOR_NAME &&
308 echo beta >beta &&
309 git add beta &&
310 git commit -m "add beta" &&
311
312 echo gamma >gamma &&
313 git add gamma &&
314 git commit -m "add gämmâ" &&
315
316 : TODO git config i18n.commitencoding latin-1 &&
317 echo delta >delta &&
318 git add delta &&
319 git commit -m "add déltà"
320 ) &&
321
322 for x in hg git
323 do
324 hg_clone_$x gitrepo hgrepo-$x &&
325 git_clone_$x hgrepo-$x gitrepo2-$x &&
326
327 HGENCODING=utf-8 hg_log hgrepo-$x >"hg-log-$x" &&
328 git_log gitrepo2-$x >"git-log-$x"
329 done &&
330
331 test_cmp hg-log-hg hg-log-git &&
332 test_cmp git-log-hg git-log-git
333 '
334
335 test_expect_success 'file removal' '
336 test_when_finished "rm -rf gitrepo* hgrepo*" &&
337
338 (
339 git init -q gitrepo &&
340 cd gitrepo &&
341 echo alpha >alpha &&
342 git add alpha &&
343 git commit -m "add alpha" &&
344 echo beta >beta &&
345 git add beta &&
346 git commit -m "add beta"
347 mkdir foo &&
348 echo blah >foo/bar &&
349 git add foo &&
350 git commit -m "add foo" &&
351 git rm alpha &&
352 git commit -m "remove alpha" &&
353 git rm foo/bar &&
354 git commit -m "remove foo/bar"
355 ) &&
356
357 for x in hg git
358 do
359 (
360 hg_clone_$x gitrepo hgrepo-$x &&
361 cd hgrepo-$x &&
362 hg_log . &&
363 hg manifest -r 3 &&
364 hg manifest
365 ) >"output-$x" &&
366
367 git_clone_$x hgrepo-$x gitrepo2-$x &&
368 git_log gitrepo2-$x >"log-$x"
369 done &&
370
371 test_cmp output-hg output-git &&
372 test_cmp log-hg log-git
373 '
374
375 test_expect_success 'git tags' '
376 test_when_finished "rm -rf gitrepo* hgrepo*" &&
377
378 (
379 git init -q gitrepo &&
380 cd gitrepo &&
381 git config receive.denyCurrentBranch ignore &&
382 echo alpha >alpha &&
383 git add alpha &&
384 git commit -m "add alpha" &&
385 git tag alpha &&
386
387 echo beta >beta &&
388 git add beta &&
389 git commit -m "add beta" &&
390 git tag -a -m "added tag beta" beta
391 ) &&
392
393 for x in hg git
394 do
395 hg_clone_$x gitrepo hgrepo-$x &&
396 hg_log hgrepo-$x >"log-$x"
397 done &&
398
399 test_cmp log-hg log-git
400 '
401
402 test_expect_success 'hg author' '
403 test_when_finished "rm -rf gitrepo* hgrepo*" &&
404
405 for x in hg git
406 do
407 (
408 git init -q gitrepo-$x &&
409 cd gitrepo-$x &&
410
411 echo alpha >alpha &&
412 git add alpha &&
413 git commit -m "add alpha" &&
414 git checkout -q -b not-master
415 ) &&
416
417 (
418 hg_clone_$x gitrepo-$x hgrepo-$x &&
419 cd hgrepo-$x &&
420
421 hg co master &&
422 echo beta >beta &&
423 hg add beta &&
424 hg commit -u "test" -m "add beta" &&
425
426 echo gamma >>beta &&
427 hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
428
429 echo gamma >gamma &&
430 hg add gamma &&
431 hg commit -u "<test@example.com>" -m "add gamma" &&
432
433 echo delta >delta &&
434 hg add delta &&
435 hg commit -u "name<test@example.com>" -m "add delta" &&
436
437 echo epsilon >epsilon &&
438 hg add epsilon &&
439 hg commit -u "name <test@example.com" -m "add epsilon" &&
440
441 echo zeta >zeta &&
442 hg add zeta &&
443 hg commit -u " test " -m "add zeta" &&
444
445 echo eta >eta &&
446 hg add eta &&
447 hg commit -u "test < test@example.com >" -m "add eta" &&
448
449 echo theta >theta &&
450 hg add theta &&
451 hg commit -u "test >test@example.com>" -m "add theta" &&
452
453 echo iota >iota &&
454 hg add iota &&
455 hg commit -u "test <test <at> example <dot> com>" -m "add iota"
456 ) &&
457
458 hg_push_$x hgrepo-$x gitrepo-$x &&
459 hg_clone_$x gitrepo-$x hgrepo2-$x &&
460
461 hg_log hgrepo2-$x >"hg-log-$x" &&
462 git_log gitrepo-$x >"git-log-$x"
463 done &&
464
465 test_cmp hg-log-hg hg-log-git &&
466 test_cmp git-log-hg git-log-git
467 '
468
469 test_expect_success 'hg branch' '
470 test_when_finished "rm -rf gitrepo* hgrepo*" &&
471
472 for x in hg git
473 do
474 (
475 git init -q gitrepo-$x &&
476 cd gitrepo-$x &&
477
478 echo alpha >alpha &&
479 git add alpha &&
480 git commit -q -m "add alpha" &&
481 git checkout -q -b not-master
482 ) &&
483
484 (
485 hg_clone_$x gitrepo-$x hgrepo-$x &&
486
487 cd hgrepo-$x &&
488 hg -q co master &&
489 hg mv alpha beta &&
490 hg -q commit -m "rename alpha to beta" &&
491 hg branch gamma | grep -v "permanent and global" &&
492 hg -q commit -m "started branch gamma"
493 ) &&
494
495 hg_push_$x hgrepo-$x gitrepo-$x &&
496 hg_clone_$x gitrepo-$x hgrepo2-$x &&
497
498 hg_log hgrepo2-$x >"hg-log-$x" &&
499 git_log gitrepo-$x >"git-log-$x"
500 done &&
501
502 test_cmp hg-log-hg hg-log-git &&
503 test_cmp git-log-hg git-log-git
504 '
505
506 test_expect_success 'hg tags' '
507 test_when_finished "rm -rf gitrepo* hgrepo*" &&
508
509 for x in hg git
510 do
511 (
512 git init -q gitrepo-$x &&
513 cd gitrepo-$x &&
514
515 echo alpha >alpha &&
516 git add alpha &&
517 git commit -m "add alpha" &&
518 git checkout -q -b not-master
519 ) &&
520
521 (
522 hg_clone_$x gitrepo-$x hgrepo-$x &&
523
524 cd hgrepo-$x &&
525 hg co master &&
526 hg tag alpha
527 ) &&
528
529 hg_push_$x hgrepo-$x gitrepo-$x &&
530 hg_clone_$x gitrepo-$x hgrepo2-$x &&
531
532 (
533 git --git-dir=gitrepo-$x/.git tag -l &&
534 hg_log hgrepo2-$x &&
535 cat hgrepo2-$x/.hgtags
536 ) >"output-$x"
537 done &&
538
539 test_cmp output-hg output-git
540 '
541
542 test_done