Merge branch 'jc/graduate-remote-hg-bzr' (early part)
[git.git] / contrib / remote-helpers / test-hg-hg-git.sh
blobb23909ae6ccc9cc5b2169c2898ea8de292bd0d22
1 #!/bin/sh
3 # Copyright (c) 2012 Felipe Contreras
5 # Base commands from hg-git tests:
6 # https://bitbucket.org/durin42/hg-git/src
9 test_description='Test remote-hg output compared to hg-git'
11 test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
12 . "$TEST_DIRECTORY"/test-lib.sh
14 if ! test_have_prereq PYTHON
15 then
16 skip_all='skipping remote-hg tests; python not available'
17 test_done
20 if ! python -c 'import mercurial'
21 then
22 skip_all='skipping remote-hg tests; mercurial not available'
23 test_done
26 if ! python -c 'import hggit'
27 then
28 skip_all='skipping remote-hg tests; hg-git not available'
29 test_done
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)
38 # clone to an hg repo with git
39 hg_clone_git () {
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 ) &&
47 (cd $2 && hg -q update)
50 # clone to a git repo with hg
51 git_clone_hg () {
53 git init -q $2 &&
54 cd $1 &&
55 hg bookmark -i -f -r tip master &&
56 hg -q push -r master ../$2 || true
60 # clone to an hg repo with hg
61 hg_clone_hg () {
62 hg -q clone $1 $2
65 # push an hg repo with git
66 hg_push_git () {
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
77 # push an hg git repo with hg
78 hg_push_hg () {
80 cd $1 &&
81 hg -q push ../$2 || true
85 hg_log () {
86 hg -R $1 log --graph --debug >log &&
87 grep -v 'tag: *default/' log
90 git_log () {
91 git --git-dir=$1/.git fast-export --branches
94 setup () {
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
112 HGEDITOR=true
113 HGMERGE=true
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
120 setup
122 test_expect_success 'executable bit' '
123 test_when_finished "rm -rf gitrepo* hgrepo*" &&
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 ) &&
140 for x in hg git
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" &&
150 git_clone_$x hgrepo-$x gitrepo2-$x &&
151 git_log gitrepo2-$x >"log-$x"
152 done &&
154 test_cmp output-hg output-git &&
155 test_cmp log-hg log-git
158 test_expect_success 'symlink' '
159 test_when_finished "rm -rf gitrepo* hgrepo*" &&
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 ) &&
172 for x in hg git
175 hg_clone_$x gitrepo hgrepo-$x &&
176 cd hgrepo-$x &&
177 hg_log . &&
178 hg manifest -v
179 ) >"output-$x" &&
181 git_clone_$x hgrepo-$x gitrepo2-$x &&
182 git_log gitrepo2-$x >"log-$x"
183 done &&
185 test_cmp output-hg output-git &&
186 test_cmp log-hg log-git
189 test_expect_success 'merge conflict 1' '
190 test_when_finished "rm -rf gitrepo* hgrepo*" &&
193 hg init hgrepo1 &&
194 cd hgrepo1 &&
195 echo A >afile &&
196 hg add afile &&
197 hg ci -m "origin" &&
199 echo B >afile &&
200 hg ci -m "A->B" &&
202 hg up -r0 &&
203 echo C >afile &&
204 hg ci -m "A->C" &&
206 hg merge -r1 &&
207 echo C >afile &&
208 hg resolve -m afile &&
209 hg ci -m "merge to C"
210 ) &&
212 for x in hg git
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 &&
220 test_cmp hg-log-hg hg-log-git &&
221 test_cmp git-log-hg git-log-git
224 test_expect_success 'merge conflict 2' '
225 test_when_finished "rm -rf gitrepo* hgrepo*" &&
228 hg init hgrepo1 &&
229 cd hgrepo1 &&
230 echo A >afile &&
231 hg add afile &&
232 hg ci -m "origin" &&
234 echo B >afile &&
235 hg ci -m "A->B" &&
237 hg up -r0 &&
238 echo C >afile &&
239 hg ci -m "A->C" &&
241 hg merge -r1 || true &&
242 echo B >afile &&
243 hg resolve -m afile &&
244 hg ci -m "merge to B"
245 ) &&
247 for x in hg git
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 &&
255 test_cmp hg-log-hg hg-log-git &&
256 test_cmp git-log-hg git-log-git
259 test_expect_success 'converged merge' '
260 test_when_finished "rm -rf gitrepo* hgrepo*" &&
263 hg init hgrepo1 &&
264 cd hgrepo1 &&
265 echo A >afile &&
266 hg add afile &&
267 hg ci -m "origin" &&
269 echo B >afile &&
270 hg ci -m "A->B" &&
272 echo C >afile &&
273 hg ci -m "B->C" &&
275 hg up -r0 &&
276 echo C >afile &&
277 hg ci -m "A->C" &&
279 hg merge -r2 || true &&
280 hg ci -m "merge"
281 ) &&
283 for x in hg git
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 &&
291 test_cmp hg-log-hg hg-log-git &&
292 test_cmp git-log-hg git-log-git
295 test_expect_success 'encoding' '
296 test_when_finished "rm -rf gitrepo* hgrepo*" &&
299 git init -q gitrepo &&
300 cd gitrepo &&
302 echo alpha >alpha &&
303 git add alpha &&
304 git commit -m "add älphà" &&
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" &&
312 echo gamma >gamma &&
313 git add gamma &&
314 git commit -m "add gämmâ" &&
316 : TODO git config i18n.commitencoding latin-1 &&
317 echo delta >delta &&
318 git add delta &&
319 git commit -m "add déltà"
320 ) &&
322 for x in hg git
324 hg_clone_$x gitrepo hgrepo-$x &&
325 git_clone_$x hgrepo-$x gitrepo2-$x &&
327 HGENCODING=utf-8 hg_log hgrepo-$x >"hg-log-$x" &&
328 git_log gitrepo2-$x >"git-log-$x"
329 done &&
331 test_cmp hg-log-hg hg-log-git &&
332 test_cmp git-log-hg git-log-git
335 test_expect_success 'file removal' '
336 test_when_finished "rm -rf gitrepo* hgrepo*" &&
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 ) &&
357 for x in hg git
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" &&
367 git_clone_$x hgrepo-$x gitrepo2-$x &&
368 git_log gitrepo2-$x >"log-$x"
369 done &&
371 test_cmp output-hg output-git &&
372 test_cmp log-hg log-git
375 test_expect_success 'git tags' '
376 test_when_finished "rm -rf gitrepo* hgrepo*" &&
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 &&
387 echo beta >beta &&
388 git add beta &&
389 git commit -m "add beta" &&
390 git tag -a -m "added tag beta" beta
391 ) &&
393 for x in hg git
395 hg_clone_$x gitrepo hgrepo-$x &&
396 hg_log hgrepo-$x >"log-$x"
397 done &&
399 test_cmp log-hg log-git
402 test_expect_success 'hg author' '
403 test_when_finished "rm -rf gitrepo* hgrepo*" &&
405 for x in hg git
408 git init -q gitrepo-$x &&
409 cd gitrepo-$x &&
411 echo alpha >alpha &&
412 git add alpha &&
413 git commit -m "add alpha" &&
414 git checkout -q -b not-master
415 ) &&
418 hg_clone_$x gitrepo-$x hgrepo-$x &&
419 cd hgrepo-$x &&
421 hg co master &&
422 echo beta >beta &&
423 hg add beta &&
424 hg commit -u "test" -m "add beta" &&
426 echo gamma >>beta &&
427 hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
429 echo gamma >gamma &&
430 hg add gamma &&
431 hg commit -u "<test@example.com>" -m "add gamma" &&
433 echo delta >delta &&
434 hg add delta &&
435 hg commit -u "name<test@example.com>" -m "add delta" &&
437 echo epsilon >epsilon &&
438 hg add epsilon &&
439 hg commit -u "name <test@example.com" -m "add epsilon" &&
441 echo zeta >zeta &&
442 hg add zeta &&
443 hg commit -u " test " -m "add zeta" &&
445 echo eta >eta &&
446 hg add eta &&
447 hg commit -u "test < test@example.com >" -m "add eta" &&
449 echo theta >theta &&
450 hg add theta &&
451 hg commit -u "test >test@example.com>" -m "add theta" &&
453 echo iota >iota &&
454 hg add iota &&
455 hg commit -u "test <test <at> example <dot> com>" -m "add iota"
456 ) &&
458 hg_push_$x hgrepo-$x gitrepo-$x &&
459 hg_clone_$x gitrepo-$x hgrepo2-$x &&
461 hg_log hgrepo2-$x >"hg-log-$x" &&
462 git_log gitrepo-$x >"git-log-$x"
463 done &&
465 test_cmp hg-log-hg hg-log-git &&
466 test_cmp git-log-hg git-log-git
469 test_expect_success 'hg branch' '
470 test_when_finished "rm -rf gitrepo* hgrepo*" &&
472 for x in hg git
475 git init -q gitrepo-$x &&
476 cd gitrepo-$x &&
478 echo alpha >alpha &&
479 git add alpha &&
480 git commit -q -m "add alpha" &&
481 git checkout -q -b not-master
482 ) &&
485 hg_clone_$x gitrepo-$x hgrepo-$x &&
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 ) &&
495 hg_push_$x hgrepo-$x gitrepo-$x &&
496 hg_clone_$x gitrepo-$x hgrepo2-$x &&
498 hg_log hgrepo2-$x >"hg-log-$x" &&
499 git_log gitrepo-$x >"git-log-$x"
500 done &&
502 test_cmp hg-log-hg hg-log-git &&
503 test_cmp git-log-hg git-log-git
506 test_expect_success 'hg tags' '
507 test_when_finished "rm -rf gitrepo* hgrepo*" &&
509 for x in hg git
512 git init -q gitrepo-$x &&
513 cd gitrepo-$x &&
515 echo alpha >alpha &&
516 git add alpha &&
517 git commit -m "add alpha" &&
518 git checkout -q -b not-master
519 ) &&
522 hg_clone_$x gitrepo-$x hgrepo-$x &&
524 cd hgrepo-$x &&
525 hg co master &&
526 hg tag alpha
527 ) &&
529 hg_push_$x hgrepo-$x gitrepo-$x &&
530 hg_clone_$x gitrepo-$x hgrepo2-$x &&
533 git --git-dir=gitrepo-$x/.git tag -l &&
534 hg_log hgrepo2-$x &&
535 cat hgrepo2-$x/.hgtags
536 ) >"output-$x"
537 done &&
539 test_cmp output-hg output-git
542 test_done