remote-hg: activate graphlog extension for hg_log()
[git/mingw.git] / contrib / remote-helpers / test-hg-hg-git.sh
blob5daad6b961faadb72eecabf5cd196ac3f0f56c96
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-lib.sh
13 if ! test_have_prereq PYTHON; then
14 skip_all='skipping remote-hg tests; python not available'
15 test_done
18 if ! "$PYTHON_PATH" -c 'import mercurial'; then
19 skip_all='skipping remote-hg tests; mercurial not available'
20 test_done
23 if ! "$PYTHON_PATH" -c 'import hggit'; then
24 skip_all='skipping remote-hg tests; hg-git not available'
25 test_done
28 # clone to a git repo with git
29 git_clone_git () {
30 git clone -q "hg::$PWD/$1" $2
33 # clone to an hg repo with git
34 hg_clone_git () {
36 hg init $2 &&
37 hg -R $2 bookmark -i master &&
38 cd $1 &&
39 git push -q "hg::$PWD/../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
40 ) &&
42 (cd $2 && hg -q update)
45 # clone to a git repo with hg
46 git_clone_hg () {
48 git init -q $2 &&
49 cd $1 &&
50 hg bookmark -i -f -r tip master &&
51 hg -q push -r master ../$2 || true
55 # clone to an hg repo with hg
56 hg_clone_hg () {
57 hg -q clone $1 $2
60 # push an hg repo with git
61 hg_push_git () {
63 cd $2
64 old=$(git symbolic-ref --short HEAD)
65 git checkout -q -b tmp &&
66 git fetch -q "hg::$PWD/../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
67 git checkout -q $old &&
68 git branch -q -D tmp 2> /dev/null || true
72 # push an hg git repo with hg
73 hg_push_hg () {
75 cd $1 &&
76 hg -q push ../$2 || true
80 hg_log () {
81 hg -R $1 log --graph --debug >log &&
82 grep -v 'tag: *default/' log
85 git_log () {
86 git --git-dir=$1/.git fast-export --branches
89 setup () {
91 echo "[ui]"
92 echo "username = A U Thor <author@example.com>"
93 echo "[defaults]"
94 echo "backout = -d \"0 0\""
95 echo "commit = -d \"0 0\""
96 echo "debugrawcommit = -d \"0 0\""
97 echo "tag = -d \"0 0\""
98 echo "[extensions]"
99 echo "hgext.bookmarks ="
100 echo "hggit ="
101 echo "graphlog ="
102 ) >> "$HOME"/.hgrc &&
103 git config --global receive.denycurrentbranch warn
104 git config --global remote-hg.hg-git-compat true
106 export HGEDITOR=/usr/bin/true
108 export GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
109 export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
112 setup
114 test_expect_success 'executable bit' '
115 mkdir -p tmp && cd tmp &&
116 test_when_finished "cd .. && rm -rf tmp" &&
119 git init -q gitrepo &&
120 cd gitrepo &&
121 echo alpha > alpha &&
122 chmod 0644 alpha &&
123 git add alpha &&
124 git commit -m "add alpha" &&
125 chmod 0755 alpha &&
126 git add alpha &&
127 git commit -m "set executable bit" &&
128 chmod 0644 alpha &&
129 git add alpha &&
130 git commit -m "clear executable bit"
131 ) &&
133 for x in hg git; do
135 hg_clone_$x gitrepo hgrepo-$x &&
136 cd hgrepo-$x &&
137 hg_log . &&
138 hg manifest -r 1 -v &&
139 hg manifest -v
140 ) > output-$x &&
142 git_clone_$x hgrepo-$x gitrepo2-$x &&
143 git_log gitrepo2-$x > log-$x
144 done &&
145 cp -r log-* output-* /tmp/foo/ &&
147 test_cmp output-hg output-git &&
148 test_cmp log-hg log-git
151 test_expect_success 'symlink' '
152 mkdir -p tmp && cd tmp &&
153 test_when_finished "cd .. && rm -rf tmp" &&
156 git init -q gitrepo &&
157 cd gitrepo &&
158 echo alpha > alpha &&
159 git add alpha &&
160 git commit -m "add alpha" &&
161 ln -s alpha beta &&
162 git add beta &&
163 git commit -m "add beta"
164 ) &&
166 for x in hg git; do
168 hg_clone_$x gitrepo hgrepo-$x &&
169 cd hgrepo-$x &&
170 hg_log . &&
171 hg manifest -v
172 ) > output-$x &&
174 git_clone_$x hgrepo-$x gitrepo2-$x &&
175 git_log gitrepo2-$x > log-$x
176 done &&
178 test_cmp output-hg output-git &&
179 test_cmp log-hg log-git
182 test_expect_success 'merge conflict 1' '
183 mkdir -p tmp && cd tmp &&
184 test_when_finished "cd .. && rm -rf tmp" &&
187 hg init hgrepo1 &&
188 cd hgrepo1 &&
189 echo A > afile &&
190 hg add afile &&
191 hg ci -m "origin" &&
193 echo B > afile &&
194 hg ci -m "A->B" &&
196 hg up -r0 &&
197 echo C > afile &&
198 hg ci -m "A->C" &&
200 hg merge -r1 || true &&
201 echo C > afile &&
202 hg resolve -m afile &&
203 hg ci -m "merge to C"
204 ) &&
206 for x in hg git; do
207 git_clone_$x hgrepo1 gitrepo-$x &&
208 hg_clone_$x gitrepo-$x hgrepo2-$x &&
209 hg_log hgrepo2-$x > hg-log-$x &&
210 git_log gitrepo-$x > git-log-$x
211 done &&
213 test_cmp hg-log-hg hg-log-git &&
214 test_cmp git-log-hg git-log-git
217 test_expect_success 'merge conflict 2' '
218 mkdir -p tmp && cd tmp &&
219 test_when_finished "cd .. && rm -rf tmp" &&
222 hg init hgrepo1 &&
223 cd hgrepo1 &&
224 echo A > afile &&
225 hg add afile &&
226 hg ci -m "origin" &&
228 echo B > afile &&
229 hg ci -m "A->B" &&
231 hg up -r0 &&
232 echo C > afile &&
233 hg ci -m "A->C" &&
235 hg merge -r1 || true &&
236 echo B > afile &&
237 hg resolve -m afile &&
238 hg ci -m "merge to B"
239 ) &&
241 for x in hg git; do
242 git_clone_$x hgrepo1 gitrepo-$x &&
243 hg_clone_$x gitrepo-$x hgrepo2-$x &&
244 hg_log hgrepo2-$x > hg-log-$x &&
245 git_log gitrepo-$x > git-log-$x
246 done &&
248 test_cmp hg-log-hg hg-log-git &&
249 test_cmp git-log-hg git-log-git
252 test_expect_success 'converged merge' '
253 mkdir -p tmp && cd tmp &&
254 test_when_finished "cd .. && rm -rf tmp" &&
257 hg init hgrepo1 &&
258 cd hgrepo1 &&
259 echo A > afile &&
260 hg add afile &&
261 hg ci -m "origin" &&
263 echo B > afile &&
264 hg ci -m "A->B" &&
266 echo C > afile &&
267 hg ci -m "B->C" &&
269 hg up -r0 &&
270 echo C > afile &&
271 hg ci -m "A->C" &&
273 hg merge -r2 || true &&
274 hg ci -m "merge"
275 ) &&
277 for x in hg git; do
278 git_clone_$x hgrepo1 gitrepo-$x &&
279 hg_clone_$x gitrepo-$x hgrepo2-$x &&
280 hg_log hgrepo2-$x > hg-log-$x &&
281 git_log gitrepo-$x > git-log-$x
282 done &&
284 test_cmp hg-log-hg hg-log-git &&
285 test_cmp git-log-hg git-log-git
288 test_expect_success 'encoding' '
289 mkdir -p tmp && cd tmp &&
290 test_when_finished "cd .. && rm -rf tmp" &&
293 git init -q gitrepo &&
294 cd gitrepo &&
296 echo alpha > alpha &&
297 git add alpha &&
298 git commit -m "add älphà" &&
300 export GIT_AUTHOR_NAME="tést èncödîng" &&
301 echo beta > beta &&
302 git add beta &&
303 git commit -m "add beta" &&
305 echo gamma > gamma &&
306 git add gamma &&
307 git commit -m "add gämmâ" &&
309 : TODO git config i18n.commitencoding latin-1 &&
310 echo delta > delta &&
311 git add delta &&
312 git commit -m "add déltà"
313 ) &&
315 for x in hg git; do
316 hg_clone_$x gitrepo hgrepo-$x &&
317 git_clone_$x hgrepo-$x gitrepo2-$x &&
319 HGENCODING=utf-8 hg_log hgrepo-$x > hg-log-$x &&
320 git_log gitrepo2-$x > git-log-$x
321 done &&
323 test_cmp hg-log-hg hg-log-git &&
324 test_cmp git-log-hg git-log-git
327 test_expect_success 'file removal' '
328 mkdir -p tmp && cd tmp &&
329 test_when_finished "cd .. && rm -rf tmp" &&
332 git init -q gitrepo &&
333 cd gitrepo &&
334 echo alpha > alpha &&
335 git add alpha &&
336 git commit -m "add alpha" &&
337 echo beta > beta &&
338 git add beta &&
339 git commit -m "add beta"
340 mkdir foo &&
341 echo blah > foo/bar &&
342 git add foo &&
343 git commit -m "add foo" &&
344 git rm alpha &&
345 git commit -m "remove alpha" &&
346 git rm foo/bar &&
347 git commit -m "remove foo/bar"
348 ) &&
350 for x in hg git; do
352 hg_clone_$x gitrepo hgrepo-$x &&
353 cd hgrepo-$x &&
354 hg_log . &&
355 hg manifest -r 3 &&
356 hg manifest
357 ) > output-$x &&
359 git_clone_$x hgrepo-$x gitrepo2-$x &&
360 git_log gitrepo2-$x > log-$x
361 done &&
363 test_cmp output-hg output-git &&
364 test_cmp log-hg log-git
367 test_expect_success 'git tags' '
368 mkdir -p tmp && cd tmp &&
369 test_when_finished "cd .. && rm -rf tmp" &&
372 git init -q gitrepo &&
373 cd gitrepo &&
374 git config receive.denyCurrentBranch ignore &&
375 echo alpha > alpha &&
376 git add alpha &&
377 git commit -m "add alpha" &&
378 git tag alpha &&
380 echo beta > beta &&
381 git add beta &&
382 git commit -m "add beta" &&
383 git tag -a -m "added tag beta" beta
384 ) &&
386 for x in hg git; do
387 hg_clone_$x gitrepo hgrepo-$x &&
388 hg_log hgrepo-$x > log-$x
389 done &&
391 test_cmp log-hg log-git
394 test_expect_success 'hg author' '
395 mkdir -p tmp && cd tmp &&
396 test_when_finished "cd .. && rm -rf tmp" &&
398 for x in hg git; do
400 git init -q gitrepo-$x &&
401 cd gitrepo-$x &&
403 echo alpha > alpha &&
404 git add alpha &&
405 git commit -m "add alpha" &&
406 git checkout -q -b not-master
407 ) &&
410 hg_clone_$x gitrepo-$x hgrepo-$x &&
411 cd hgrepo-$x &&
413 hg co master &&
414 echo beta > beta &&
415 hg add beta &&
416 hg commit -u "test" -m "add beta" &&
418 echo gamma >> beta &&
419 hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
421 echo gamma > gamma &&
422 hg add gamma &&
423 hg commit -u "<test@example.com>" -m "add gamma" &&
425 echo delta > delta &&
426 hg add delta &&
427 hg commit -u "name<test@example.com>" -m "add delta" &&
429 echo epsilon > epsilon &&
430 hg add epsilon &&
431 hg commit -u "name <test@example.com" -m "add epsilon" &&
433 echo zeta > zeta &&
434 hg add zeta &&
435 hg commit -u " test " -m "add zeta" &&
437 echo eta > eta &&
438 hg add eta &&
439 hg commit -u "test < test@example.com >" -m "add eta" &&
441 echo theta > theta &&
442 hg add theta &&
443 hg commit -u "test >test@example.com>" -m "add theta" &&
445 echo iota > iota &&
446 hg add iota &&
447 hg commit -u "test <test <at> example <dot> com>" -m "add iota"
448 ) &&
450 hg_push_$x hgrepo-$x gitrepo-$x &&
451 hg_clone_$x gitrepo-$x hgrepo2-$x &&
453 hg_log hgrepo2-$x > hg-log-$x &&
454 git_log gitrepo-$x > git-log-$x
455 done &&
457 test_cmp git-log-hg git-log-git &&
459 test_cmp hg-log-hg hg-log-git &&
460 test_cmp git-log-hg git-log-git
463 test_expect_success 'hg branch' '
464 mkdir -p tmp && cd tmp &&
465 test_when_finished "cd .. && rm -rf tmp" &&
467 for x in hg git; do
469 git init -q gitrepo-$x &&
470 cd gitrepo-$x &&
472 echo alpha > alpha &&
473 git add alpha &&
474 git commit -q -m "add alpha" &&
475 git checkout -q -b not-master
476 ) &&
479 hg_clone_$x gitrepo-$x hgrepo-$x &&
481 cd hgrepo-$x &&
482 hg -q co master &&
483 hg mv alpha beta &&
484 hg -q commit -m "rename alpha to beta" &&
485 hg branch gamma | grep -v "permanent and global" &&
486 hg -q commit -m "started branch gamma"
487 ) &&
489 hg_push_$x hgrepo-$x gitrepo-$x &&
490 hg_clone_$x gitrepo-$x hgrepo2-$x &&
492 hg_log hgrepo2-$x > hg-log-$x &&
493 git_log gitrepo-$x > git-log-$x
494 done &&
496 test_cmp hg-log-hg hg-log-git &&
497 test_cmp git-log-hg git-log-git
500 test_expect_success 'hg tags' '
501 mkdir -p tmp && cd tmp &&
502 test_when_finished "cd .. && rm -rf tmp" &&
504 for x in hg git; do
506 git init -q gitrepo-$x &&
507 cd gitrepo-$x &&
509 echo alpha > alpha &&
510 git add alpha &&
511 git commit -m "add alpha" &&
512 git checkout -q -b not-master
513 ) &&
516 hg_clone_$x gitrepo-$x hgrepo-$x &&
518 cd hgrepo-$x &&
519 hg co master &&
520 hg tag alpha
521 ) &&
523 hg_push_$x hgrepo-$x gitrepo-$x &&
524 hg_clone_$x gitrepo-$x hgrepo2-$x &&
527 git --git-dir=gitrepo-$x/.git tag -l &&
528 hg_log hgrepo2-$x &&
529 cat hgrepo2-$x/.hgtags
530 ) > output-$x
531 done &&
533 test_cmp output-hg output-git
536 test_done