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=$(dirname $0)/
12 . "$TEST_DIRECTORY"/test-lib.sh
14 skip_all='skipping remote-hg-hg-git tests; temporarily disabled'
17 if ! test_have_prereq PYTHON
19 skip_all='skipping remote-hg tests; python not available'
23 if ! "$PYTHON_PATH" -c 'import mercurial' > /dev/null 2>&1
25 skip_all='skipping remote-hg tests; mercurial not available'
29 if "$PYTHON_PATH" -c 'import hggit' > /dev/null 2>&1
32 elif "$PYTHON_PATH" -c 'import hgext.git' > /dev/null 2>&1
36 skip_all='skipping remote-hg tests; hg-git not available'
40 hg_version=$("$PYTHON_PATH" -c 'from mercurial import util; print util.version()')
44 skip_all='skipping remote-hg tests; unsuported version of hg by hg-git'
49 # clone to a git repo with git
51 git clone -q "hg::$1" $2 &&
52 (cd $2 && git checkout master && git branch -D default)
55 # clone to an hg repo with git
59 hg -R $2 bookmark -i master &&
61 git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
64 (cd $2 && hg -q update)
67 # clone to a git repo with hg
72 hg bookmark -i -f -r tip master &&
73 hg -q push -r master ../$2 || true
77 # clone to an hg repo with hg
82 # push an hg repo with git
86 git checkout -q -b tmp &&
87 git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
88 git branch -D default &&
89 git checkout -q @{-1} &&
90 git branch -q -D tmp 2> /dev/null || true
94 # push an hg git repo with hg
98 hg -q push ../$2 || true
103 hg -R $1 log --graph --debug > log &&
104 grep -v 'tag: *default/' log
108 git --git-dir=$1/.git fast-export --branches
112 cat > "$HOME"/.hgrc <<-EOF &&
114 username = A U Thor <author@example.com>
118 debugrawcommit = -d "0 0"
124 git config --global receive.denycurrentbranch warn
125 git config --global remote-hg.hg-git-compat true
126 git config --global remote-hg.track-branches false
131 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
132 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
133 export HGEDITOR HGMERGE GIT_AUTHOR_DATE GIT_COMMITTER_DATE
138 test_expect_success 'executable bit' '
139 test_when_finished "rm -rf gitrepo* hgrepo*" &&
142 git init -q gitrepo &&
144 echo alpha > alpha &&
147 git commit -m "add alpha" &&
150 git commit -m "set executable bit" &&
153 git commit -m "clear executable bit"
159 hg_clone_$x gitrepo hgrepo-$x &&
162 hg manifest -r 1 -v &&
166 git_clone_$x hgrepo-$x gitrepo2-$x &&
167 git_log gitrepo2-$x > "log-$x"
170 test_cmp output-hg output-git &&
171 test_cmp log-hg log-git
174 test_expect_success 'symlink' '
175 test_when_finished "rm -rf gitrepo* hgrepo*" &&
178 git init -q gitrepo &&
180 echo alpha > alpha &&
182 git commit -m "add alpha" &&
185 git commit -m "add beta"
191 hg_clone_$x gitrepo hgrepo-$x &&
197 git_clone_$x hgrepo-$x gitrepo2-$x &&
198 git_log gitrepo2-$x > "log-$x"
201 test_cmp output-hg output-git &&
202 test_cmp log-hg log-git
205 test_expect_success 'merge conflict 1' '
206 test_when_finished "rm -rf gitrepo* hgrepo*" &&
224 hg resolve -m afile &&
225 hg ci -m "merge to C"
230 git_clone_$x hgrepo1 gitrepo-$x &&
231 hg_clone_$x gitrepo-$x hgrepo2-$x &&
232 hg_log hgrepo2-$x > "hg-log-$x" &&
233 git_log gitrepo-$x > "git-log-$x"
236 test_cmp hg-log-hg hg-log-git &&
237 test_cmp git-log-hg git-log-git
240 test_expect_success 'merge conflict 2' '
241 test_when_finished "rm -rf gitrepo* hgrepo*" &&
257 hg merge -r1 || true &&
259 hg resolve -m afile &&
260 hg ci -m "merge to B"
265 git_clone_$x hgrepo1 gitrepo-$x &&
266 hg_clone_$x gitrepo-$x hgrepo2-$x &&
267 hg_log hgrepo2-$x > "hg-log-$x" &&
268 git_log gitrepo-$x > "git-log-$x"
271 test_cmp hg-log-hg hg-log-git &&
272 test_cmp git-log-hg git-log-git
275 test_expect_success 'converged merge' '
276 test_when_finished "rm -rf gitrepo* hgrepo*" &&
295 hg merge -r2 || true &&
301 git_clone_$x hgrepo1 gitrepo-$x &&
302 hg_clone_$x gitrepo-$x hgrepo2-$x &&
303 hg_log hgrepo2-$x > "hg-log-$x" &&
304 git_log gitrepo-$x > "git-log-$x"
307 test_cmp hg-log-hg hg-log-git &&
308 test_cmp git-log-hg git-log-git
311 test_expect_success 'encoding' '
312 test_when_finished "rm -rf gitrepo* hgrepo*" &&
315 git init -q gitrepo &&
318 echo alpha > alpha &&
320 git commit -m "add älphà" &&
322 GIT_AUTHOR_NAME="tést èncödîng" &&
323 export GIT_AUTHOR_NAME &&
326 git commit -m "add beta" &&
328 echo gamma > gamma &&
330 git commit -m "add gämmâ" &&
332 : TODO git config i18n.commitencoding latin-1 &&
333 echo delta > delta &&
335 git commit -m "add déltà"
340 hg_clone_$x gitrepo hgrepo-$x &&
341 git_clone_$x hgrepo-$x gitrepo2-$x &&
343 HGENCODING=utf-8 hg_log hgrepo-$x > "hg-log-$x" &&
344 git_log gitrepo2-$x > "git-log-$x"
347 test_cmp hg-log-hg hg-log-git &&
348 test_cmp git-log-hg git-log-git
351 test_expect_success 'file removal' '
352 test_when_finished "rm -rf gitrepo* hgrepo*" &&
355 git init -q gitrepo &&
357 echo alpha > alpha &&
359 git commit -m "add alpha" &&
362 git commit -m "add beta"
364 echo blah > foo/bar &&
366 git commit -m "add foo" &&
368 git commit -m "remove alpha" &&
370 git commit -m "remove foo/bar"
376 hg_clone_$x gitrepo hgrepo-$x &&
383 git_clone_$x hgrepo-$x gitrepo2-$x &&
384 git_log gitrepo2-$x > "log-$x"
387 test_cmp output-hg output-git &&
388 test_cmp log-hg log-git
391 test_expect_success 'git tags' '
392 test_when_finished "rm -rf gitrepo* hgrepo*" &&
395 git init -q gitrepo &&
397 git config receive.denyCurrentBranch ignore &&
398 echo alpha > alpha &&
400 git commit -m "add alpha" &&
405 git commit -m "add beta" &&
406 git tag -a -m "added tag beta" beta
411 hg_clone_$x gitrepo hgrepo-$x &&
412 hg_log hgrepo-$x > "log-$x"
415 test_cmp log-hg log-git
418 test_expect_success 'hg author' '
419 test_when_finished "rm -rf gitrepo* hgrepo*" &&
424 git init -q gitrepo-$x &&
427 echo alpha > alpha &&
429 git commit -m "add alpha" &&
430 git checkout -q -b not-master
434 hg_clone_$x gitrepo-$x hgrepo-$x &&
440 hg commit -u "test" -m "add beta" &&
442 echo gamma >> beta &&
443 hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
445 echo gamma > gamma &&
447 hg commit -u "<test@example.com>" -m "add gamma" &&
449 echo delta > delta &&
451 hg commit -u "name<test@example.com>" -m "add delta" &&
453 echo epsilon > epsilon &&
455 hg commit -u "name <test@example.com" -m "add epsilon" &&
459 hg commit -u " test " -m "add zeta" &&
463 hg commit -u "test < test@example.com >" -m "add eta" &&
465 echo theta > theta &&
467 hg commit -u "test >test@example.com>" -m "add theta" &&
471 hg commit -u "test <test <at> example <dot> com>" -m "add iota"
474 hg_push_$x hgrepo-$x gitrepo-$x &&
475 hg_clone_$x gitrepo-$x hgrepo2-$x &&
477 hg_log hgrepo2-$x > "hg-log-$x" &&
478 git_log gitrepo-$x > "git-log-$x"
481 test_cmp hg-log-hg hg-log-git &&
482 test_cmp git-log-hg git-log-git
485 test_expect_success 'hg branch' '
486 test_when_finished "rm -rf gitrepo* hgrepo*" &&
491 git init -q gitrepo-$x &&
494 echo alpha > alpha &&
496 git commit -q -m "add alpha" &&
497 git checkout -q -b not-master
501 hg_clone_$x gitrepo-$x hgrepo-$x &&
506 hg -q commit -m "rename alpha to beta" &&
507 hg branch gamma | grep -v "permanent and global" &&
508 hg -q commit -m "started branch gamma"
511 hg_push_$x hgrepo-$x gitrepo-$x &&
512 hg_clone_$x gitrepo-$x hgrepo2-$x &&
514 hg_log hgrepo2-$x > "hg-log-$x" &&
515 git_log gitrepo-$x > "git-log-$x"
518 test_cmp hg-log-hg hg-log-git &&
519 test_cmp git-log-hg git-log-git
522 test_expect_success 'hg tags' '
523 test_when_finished "rm -rf gitrepo* hgrepo*" &&
528 git init -q gitrepo-$x &&
531 echo alpha > alpha &&
533 git commit -m "add alpha" &&
534 git checkout -q -b not-master
538 hg_clone_$x gitrepo-$x hgrepo-$x &&
545 hg_push_$x hgrepo-$x gitrepo-$x &&
546 hg_clone_$x gitrepo-$x hgrepo2-$x &&
549 git --git-dir=gitrepo-$x/.git tag -l &&
551 cat hgrepo2-$x/.hgtags
555 test_cmp output-hg output-git