remote-hg: add test for bookmark diverge
[gitweb.git] / contrib / remote-helpers / test-hg-hg-git.sh
index 9aaf0436695c940ff8c1aa51118d66f9a661efd9..2219284382f0e987423ae00e5bd89e9b7a4b0046 100755 (executable)
@@ -15,28 +15,29 @@ if ! test_have_prereq PYTHON; then
        test_done
 fi
 
-if ! "$PYTHON_PATH" -c 'import mercurial'; then
+if ! python -c 'import mercurial'; then
        skip_all='skipping remote-hg tests; mercurial not available'
        test_done
 fi
 
-if ! "$PYTHON_PATH" -c 'import hggit'; then
+if ! python -c 'import hggit'; then
        skip_all='skipping remote-hg tests; hg-git not available'
        test_done
 fi
 
 # clone to a git repo with git
 git_clone_git () {
-       hg -R $1 bookmark -f -r tip master &&
-       git clone -q "hg::$PWD/$1" $2
+       git clone -q "hg::$1" $2 &&
+       (cd $2 && git checkout master && git branch -D default)
 }
 
 # clone to an hg repo with git
 hg_clone_git () {
        (
        hg init $2 &&
+       hg -R $2 bookmark -i master &&
        cd $1 &&
-       git push -q "hg::$PWD/../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
+       git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
        ) &&
 
        (cd $2 && hg -q update)
@@ -47,7 +48,7 @@ git_clone_hg () {
        (
        git init -q $2 &&
        cd $1 &&
-       hg bookmark -f -r tip master &&
+       hg bookmark -i -f -r tip master &&
        hg -q push -r master ../$2 || true
        )
 }
@@ -61,10 +62,10 @@ hg_clone_hg () {
 hg_push_git () {
        (
        cd $2
-       old=$(git symbolic-ref --short HEAD)
        git checkout -q -b tmp &&
-       git fetch -q "hg::$PWD/../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
-       git checkout -q $old &&
+       git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
+       git branch -D default &&
+       git checkout -q @{-1} &&
        git branch -q -D tmp 2> /dev/null || true
        )
 }
@@ -78,7 +79,8 @@ hg_push_hg () {
 }
 
 hg_log () {
-       hg -R $1 log --graph --debug | grep -v 'tag: *default/'
+       hg -R $1 log --graph --debug >log &&
+       grep -v 'tag: *default/' log
 }
 
 git_log () {
@@ -97,22 +99,24 @@ setup () {
        echo "[extensions]"
        echo "hgext.bookmarks ="
        echo "hggit ="
+       echo "graphlog ="
        ) >> "$HOME"/.hgrc &&
        git config --global receive.denycurrentbranch warn
        git config --global remote-hg.hg-git-compat true
+       git config --global remote-hg.track-branches false
 
-       HGEDITOR=/usr/bin/true
+       HGEDITOR=true
+       HGMERGE=true
 
        GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
        GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
-       export HGEDITOR GIT_AUTHOR_DATE GIT_COMMITTER_DATE
+       export HGEDITOR HGMERGE GIT_AUTHOR_DATE GIT_COMMITTER_DATE
 }
 
 setup
 
 test_expect_success 'executable bit' '
-       mkdir -p tmp && cd tmp &&
-       test_when_finished "cd .. && rm -rf tmp" &&
+       test_when_finished "rm -rf gitrepo* hgrepo*" &&
 
        (
        git init -q gitrepo &&
@@ -141,15 +145,13 @@ test_expect_success 'executable bit' '
                git_clone_$x hgrepo-$x gitrepo2-$x &&
                git_log gitrepo2-$x > log-$x
        done &&
-       cp -r log-* output-* /tmp/foo/ &&
 
        test_cmp output-hg output-git &&
        test_cmp log-hg log-git
 '
 
 test_expect_success 'symlink' '
-       mkdir -p tmp && cd tmp &&
-       test_when_finished "cd .. && rm -rf tmp" &&
+       test_when_finished "rm -rf gitrepo* hgrepo*" &&
 
        (
        git init -q gitrepo &&
@@ -179,8 +181,7 @@ test_expect_success 'symlink' '
 '
 
 test_expect_success 'merge conflict 1' '
-       mkdir -p tmp && cd tmp &&
-       test_when_finished "cd .. && rm -rf tmp" &&
+       test_when_finished "rm -rf gitrepo* hgrepo*" &&
 
        (
        hg init hgrepo1 &&
@@ -196,7 +197,7 @@ test_expect_success 'merge conflict 1' '
        echo C > afile &&
        hg ci -m "A->C" &&
 
-       hg merge -r1 || true &&
+       hg merge -r1 &&
        echo C > afile &&
        hg resolve -m afile &&
        hg ci -m "merge to C"
@@ -214,8 +215,7 @@ test_expect_success 'merge conflict 1' '
 '
 
 test_expect_success 'merge conflict 2' '
-       mkdir -p tmp && cd tmp &&
-       test_when_finished "cd .. && rm -rf tmp" &&
+       test_when_finished "rm -rf gitrepo* hgrepo*" &&
 
        (
        hg init hgrepo1 &&
@@ -249,8 +249,7 @@ test_expect_success 'merge conflict 2' '
 '
 
 test_expect_success 'converged merge' '
-       mkdir -p tmp && cd tmp &&
-       test_when_finished "cd .. && rm -rf tmp" &&
+       test_when_finished "rm -rf gitrepo* hgrepo*" &&
 
        (
        hg init hgrepo1 &&
@@ -285,8 +284,7 @@ test_expect_success 'converged merge' '
 '
 
 test_expect_success 'encoding' '
-       mkdir -p tmp && cd tmp &&
-       test_when_finished "cd .. && rm -rf tmp" &&
+       test_when_finished "rm -rf gitrepo* hgrepo*" &&
 
        (
        git init -q gitrepo &&
@@ -325,8 +323,7 @@ test_expect_success 'encoding' '
 '
 
 test_expect_success 'file removal' '
-       mkdir -p tmp && cd tmp &&
-       test_when_finished "cd .. && rm -rf tmp" &&
+       test_when_finished "rm -rf gitrepo* hgrepo*" &&
 
        (
        git init -q gitrepo &&
@@ -365,8 +362,7 @@ test_expect_success 'file removal' '
 '
 
 test_expect_success 'git tags' '
-       mkdir -p tmp && cd tmp &&
-       test_when_finished "cd .. && rm -rf tmp" &&
+       test_when_finished "rm -rf gitrepo* hgrepo*" &&
 
        (
        git init -q gitrepo &&
@@ -392,8 +388,7 @@ test_expect_success 'git tags' '
 '
 
 test_expect_success 'hg author' '
-       mkdir -p tmp && cd tmp &&
-       test_when_finished "cd .. && rm -rf tmp" &&
+       test_when_finished "rm -rf gitrepo* hgrepo*" &&
 
        for x in hg git; do
                (
@@ -454,15 +449,12 @@ test_expect_success 'hg author' '
                git_log gitrepo-$x > git-log-$x
        done &&
 
-       test_cmp git-log-hg git-log-git &&
-
        test_cmp hg-log-hg hg-log-git &&
        test_cmp git-log-hg git-log-git
 '
 
 test_expect_success 'hg branch' '
-       mkdir -p tmp && cd tmp &&
-       test_when_finished "cd .. && rm -rf tmp" &&
+       test_when_finished "rm -rf gitrepo* hgrepo*" &&
 
        for x in hg git; do
                (
@@ -498,8 +490,7 @@ test_expect_success 'hg branch' '
 '
 
 test_expect_success 'hg tags' '
-       mkdir -p tmp && cd tmp &&
-       test_when_finished "cd .. && rm -rf tmp" &&
+       test_when_finished "rm -rf gitrepo* hgrepo*" &&
 
        for x in hg git; do
                (