Merge branch 'nd/index-pack-threaded-fixes'
[git/gitweb.git] / contrib / remote-helpers / test-hg-hg-git.sh
blob7e3967f5b6f0c19939bf1c0c30be0d756ec6aa04
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 hg -R $1 bookmark -f -r tip master &&
31 git clone -q "hg::$PWD/$1" $2
34 # clone to an hg repo with git
35 hg_clone_git () {
37 hg init $2 &&
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 -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 | grep -v 'tag: *default/'
84 git_log () {
85 git --git-dir=$1/.git fast-export --branches
88 setup () {
90 echo "[ui]"
91 echo "username = A U Thor <author@example.com>"
92 echo "[defaults]"
93 echo "backout = -d \"0 0\""
94 echo "commit = -d \"0 0\""
95 echo "debugrawcommit = -d \"0 0\""
96 echo "tag = -d \"0 0\""
97 echo "[extensions]"
98 echo "hgext.bookmarks ="
99 echo "hggit ="
100 ) >> "$HOME"/.hgrc &&
101 git config --global receive.denycurrentbranch warn
102 git config --global remote-hg.hg-git-compat true
104 export HGEDITOR=/usr/bin/true
106 export GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
107 export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
110 setup
112 test_expect_success 'executable bit' '
113 mkdir -p tmp && cd tmp &&
114 test_when_finished "cd .. && rm -rf tmp" &&
117 git init -q gitrepo &&
118 cd gitrepo &&
119 echo alpha > alpha &&
120 chmod 0644 alpha &&
121 git add alpha &&
122 git commit -m "add alpha" &&
123 chmod 0755 alpha &&
124 git add alpha &&
125 git commit -m "set executable bit" &&
126 chmod 0644 alpha &&
127 git add alpha &&
128 git commit -m "clear executable bit"
129 ) &&
131 for x in hg git; do
133 hg_clone_$x gitrepo hgrepo-$x &&
134 cd hgrepo-$x &&
135 hg_log . &&
136 hg manifest -r 1 -v &&
137 hg manifest -v
138 ) > output-$x &&
140 git_clone_$x hgrepo-$x gitrepo2-$x &&
141 git_log gitrepo2-$x > log-$x
142 done &&
143 cp -r log-* output-* /tmp/foo/ &&
145 test_cmp output-hg output-git &&
146 test_cmp log-hg log-git
149 test_expect_success 'symlink' '
150 mkdir -p tmp && cd tmp &&
151 test_when_finished "cd .. && rm -rf tmp" &&
154 git init -q gitrepo &&
155 cd gitrepo &&
156 echo alpha > alpha &&
157 git add alpha &&
158 git commit -m "add alpha" &&
159 ln -s alpha beta &&
160 git add beta &&
161 git commit -m "add beta"
162 ) &&
164 for x in hg git; do
166 hg_clone_$x gitrepo hgrepo-$x &&
167 cd hgrepo-$x &&
168 hg_log . &&
169 hg manifest -v
170 ) > output-$x &&
172 git_clone_$x hgrepo-$x gitrepo2-$x &&
173 git_log gitrepo2-$x > log-$x
174 done &&
176 test_cmp output-hg output-git &&
177 test_cmp log-hg log-git
180 test_expect_success 'merge conflict 1' '
181 mkdir -p tmp && cd tmp &&
182 test_when_finished "cd .. && rm -rf tmp" &&
185 hg init hgrepo1 &&
186 cd hgrepo1 &&
187 echo A > afile &&
188 hg add afile &&
189 hg ci -m "origin" &&
191 echo B > afile &&
192 hg ci -m "A->B" &&
194 hg up -r0 &&
195 echo C > afile &&
196 hg ci -m "A->C" &&
198 hg merge -r1 || true &&
199 echo C > afile &&
200 hg resolve -m afile &&
201 hg ci -m "merge to C"
202 ) &&
204 for x in hg git; do
205 git_clone_$x hgrepo1 gitrepo-$x &&
206 hg_clone_$x gitrepo-$x hgrepo2-$x &&
207 hg_log hgrepo2-$x > hg-log-$x &&
208 git_log gitrepo-$x > git-log-$x
209 done &&
211 test_cmp hg-log-hg hg-log-git &&
212 test_cmp git-log-hg git-log-git
215 test_expect_success 'merge conflict 2' '
216 mkdir -p tmp && cd tmp &&
217 test_when_finished "cd .. && rm -rf tmp" &&
220 hg init hgrepo1 &&
221 cd hgrepo1 &&
222 echo A > afile &&
223 hg add afile &&
224 hg ci -m "origin" &&
226 echo B > afile &&
227 hg ci -m "A->B" &&
229 hg up -r0 &&
230 echo C > afile &&
231 hg ci -m "A->C" &&
233 hg merge -r1 || true &&
234 echo B > afile &&
235 hg resolve -m afile &&
236 hg ci -m "merge to B"
237 ) &&
239 for x in hg git; do
240 git_clone_$x hgrepo1 gitrepo-$x &&
241 hg_clone_$x gitrepo-$x hgrepo2-$x &&
242 hg_log hgrepo2-$x > hg-log-$x &&
243 git_log gitrepo-$x > git-log-$x
244 done &&
246 test_cmp hg-log-hg hg-log-git &&
247 test_cmp git-log-hg git-log-git
250 test_expect_success 'converged merge' '
251 mkdir -p tmp && cd tmp &&
252 test_when_finished "cd .. && rm -rf tmp" &&
255 hg init hgrepo1 &&
256 cd hgrepo1 &&
257 echo A > afile &&
258 hg add afile &&
259 hg ci -m "origin" &&
261 echo B > afile &&
262 hg ci -m "A->B" &&
264 echo C > afile &&
265 hg ci -m "B->C" &&
267 hg up -r0 &&
268 echo C > afile &&
269 hg ci -m "A->C" &&
271 hg merge -r2 || true &&
272 hg ci -m "merge"
273 ) &&
275 for x in hg git; do
276 git_clone_$x hgrepo1 gitrepo-$x &&
277 hg_clone_$x gitrepo-$x hgrepo2-$x &&
278 hg_log hgrepo2-$x > hg-log-$x &&
279 git_log gitrepo-$x > git-log-$x
280 done &&
282 test_cmp hg-log-hg hg-log-git &&
283 test_cmp git-log-hg git-log-git
286 test_expect_success 'encoding' '
287 mkdir -p tmp && cd tmp &&
288 test_when_finished "cd .. && rm -rf tmp" &&
291 git init -q gitrepo &&
292 cd gitrepo &&
294 echo alpha > alpha &&
295 git add alpha &&
296 git commit -m "add älphà" &&
298 export GIT_AUTHOR_NAME="tést èncödîng" &&
299 echo beta > beta &&
300 git add beta &&
301 git commit -m "add beta" &&
303 echo gamma > gamma &&
304 git add gamma &&
305 git commit -m "add gämmâ" &&
307 : TODO git config i18n.commitencoding latin-1 &&
308 echo delta > delta &&
309 git add delta &&
310 git commit -m "add déltà"
311 ) &&
313 for x in hg git; do
314 hg_clone_$x gitrepo hgrepo-$x &&
315 git_clone_$x hgrepo-$x gitrepo2-$x &&
317 HGENCODING=utf-8 hg_log hgrepo-$x > hg-log-$x &&
318 git_log gitrepo2-$x > git-log-$x
319 done &&
321 test_cmp hg-log-hg hg-log-git &&
322 test_cmp git-log-hg git-log-git
325 test_expect_success 'file removal' '
326 mkdir -p tmp && cd tmp &&
327 test_when_finished "cd .. && rm -rf tmp" &&
330 git init -q gitrepo &&
331 cd gitrepo &&
332 echo alpha > alpha &&
333 git add alpha &&
334 git commit -m "add alpha" &&
335 echo beta > beta &&
336 git add beta &&
337 git commit -m "add beta"
338 mkdir foo &&
339 echo blah > foo/bar &&
340 git add foo &&
341 git commit -m "add foo" &&
342 git rm alpha &&
343 git commit -m "remove alpha" &&
344 git rm foo/bar &&
345 git commit -m "remove foo/bar"
346 ) &&
348 for x in hg git; do
350 hg_clone_$x gitrepo hgrepo-$x &&
351 cd hgrepo-$x &&
352 hg_log . &&
353 hg manifest -r 3 &&
354 hg manifest
355 ) > output-$x &&
357 git_clone_$x hgrepo-$x gitrepo2-$x &&
358 git_log gitrepo2-$x > log-$x
359 done &&
361 test_cmp output-hg output-git &&
362 test_cmp log-hg log-git
365 test_expect_success 'git tags' '
366 mkdir -p tmp && cd tmp &&
367 test_when_finished "cd .. && rm -rf tmp" &&
370 git init -q gitrepo &&
371 cd gitrepo &&
372 git config receive.denyCurrentBranch ignore &&
373 echo alpha > alpha &&
374 git add alpha &&
375 git commit -m "add alpha" &&
376 git tag alpha &&
378 echo beta > beta &&
379 git add beta &&
380 git commit -m "add beta" &&
381 git tag -a -m "added tag beta" beta
382 ) &&
384 for x in hg git; do
385 hg_clone_$x gitrepo hgrepo-$x &&
386 hg_log hgrepo-$x > log-$x
387 done &&
389 test_cmp log-hg log-git
392 test_expect_success 'hg author' '
393 mkdir -p tmp && cd tmp &&
394 test_when_finished "cd .. && rm -rf tmp" &&
396 for x in hg git; do
398 git init -q gitrepo-$x &&
399 cd gitrepo-$x &&
401 echo alpha > alpha &&
402 git add alpha &&
403 git commit -m "add alpha" &&
404 git checkout -q -b not-master
405 ) &&
408 hg_clone_$x gitrepo-$x hgrepo-$x &&
409 cd hgrepo-$x &&
411 hg co master &&
412 echo beta > beta &&
413 hg add beta &&
414 hg commit -u "test" -m "add beta" &&
416 echo gamma >> beta &&
417 hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
419 echo gamma > gamma &&
420 hg add gamma &&
421 hg commit -u "<test@example.com>" -m "add gamma" &&
423 echo delta > delta &&
424 hg add delta &&
425 hg commit -u "name<test@example.com>" -m "add delta" &&
427 echo epsilon > epsilon &&
428 hg add epsilon &&
429 hg commit -u "name <test@example.com" -m "add epsilon" &&
431 echo zeta > zeta &&
432 hg add zeta &&
433 hg commit -u " test " -m "add zeta" &&
435 echo eta > eta &&
436 hg add eta &&
437 hg commit -u "test < test@example.com >" -m "add eta" &&
439 echo theta > theta &&
440 hg add theta &&
441 hg commit -u "test >test@example.com>" -m "add theta" &&
443 echo iota > iota &&
444 hg add iota &&
445 hg commit -u "test <test <at> example <dot> com>" -m "add iota"
446 ) &&
448 hg_push_$x hgrepo-$x gitrepo-$x &&
449 hg_clone_$x gitrepo-$x hgrepo2-$x &&
451 hg_log hgrepo2-$x > hg-log-$x &&
452 git_log gitrepo-$x > git-log-$x
453 done &&
455 test_cmp git-log-hg git-log-git &&
457 test_cmp hg-log-hg hg-log-git &&
458 test_cmp git-log-hg git-log-git
461 test_expect_success 'hg branch' '
462 mkdir -p tmp && cd tmp &&
463 test_when_finished "cd .. && rm -rf tmp" &&
465 for x in hg git; do
467 git init -q gitrepo-$x &&
468 cd gitrepo-$x &&
470 echo alpha > alpha &&
471 git add alpha &&
472 git commit -q -m "add alpha" &&
473 git checkout -q -b not-master
474 ) &&
477 hg_clone_$x gitrepo-$x hgrepo-$x &&
479 cd hgrepo-$x &&
480 hg -q co master &&
481 hg mv alpha beta &&
482 hg -q commit -m "rename alpha to beta" &&
483 hg branch gamma | grep -v "permanent and global" &&
484 hg -q commit -m "started branch gamma"
485 ) &&
487 hg_push_$x hgrepo-$x gitrepo-$x &&
488 hg_clone_$x gitrepo-$x hgrepo2-$x &&
490 hg_log hgrepo2-$x > hg-log-$x &&
491 git_log gitrepo-$x > git-log-$x
492 done &&
494 test_cmp hg-log-hg hg-log-git &&
495 test_cmp git-log-hg git-log-git
498 test_expect_success 'hg tags' '
499 mkdir -p tmp && cd tmp &&
500 test_when_finished "cd .. && rm -rf tmp" &&
502 for x in hg git; do
504 git init -q gitrepo-$x &&
505 cd gitrepo-$x &&
507 echo alpha > alpha &&
508 git add alpha &&
509 git commit -m "add alpha" &&
510 git checkout -q -b not-master
511 ) &&
514 hg_clone_$x gitrepo-$x hgrepo-$x &&
516 cd hgrepo-$x &&
517 hg co master &&
518 hg tag alpha
519 ) &&
521 hg_push_$x hgrepo-$x gitrepo-$x &&
522 hg_clone_$x gitrepo-$x hgrepo2-$x &&
525 git --git-dir=gitrepo-$x/.git tag -l &&
526 hg_log hgrepo2-$x &&
527 cat hgrepo2-$x/.hgtags
528 ) > output-$x
529 done &&
531 test_cmp output-hg output-git
534 test_done