Merge branch 'nd/make-wildmatch-default'
[gitweb.git] / contrib / remote-helpers / test-hg.sh
index 66e37af09a7d0cbd86fa992bc822b28944ffd85f..f7ce8aa853d5ad9689f49a9cadf0d43ce16ed34f 100755 (executable)
@@ -48,6 +48,44 @@ check_bookmark () {
        fi
 }
 
+check_push () {
+       local expected_ret=$1 ret=0 ref_ret=0 IFS=':'
+
+       shift
+       git push origin "$@" 2> error
+       ret=$?
+       cat error
+
+       while read branch kind
+       do
+               case "$kind" in
+               'new')
+                       grep "^ \* \[new branch\] *${branch} -> ${branch}$" error || ref_ret=1
+                       ;;
+               'non-fast-forward')
+                       grep "^ ! \[rejected\] *${branch} -> ${branch} (non-fast-forward)$" error || ref_ret=1
+                       ;;
+               'fetch-first')
+                       grep "^ ! \[rejected\] *${branch} -> ${branch} (fetch first)$" error || ref_ret=1
+                       ;;
+               'forced-update')
+                       grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *${branch} -> ${branch} (forced update)$" error || ref_ret=1
+                       ;;
+               '')
+                       grep "^   [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret=1
+                       ;;
+               esac
+               let 'ref_ret' && echo "match for '$branch' failed" && break
+       done
+
+       if let 'expected_ret != ret || ref_ret'
+       then
+               return 1
+       fi
+
+       return 0
+}
+
 setup () {
        (
        echo "[ui]"
@@ -328,7 +366,7 @@ test_expect_success 'remote new bookmark' '
        check_bookmark hgrepo feature-b feature-b
 '
 
-test_expect_failure 'remote push diverged' '
+test_expect_success 'remote push diverged' '
        test_when_finished "rm -rf gitrepo*" &&
 
        git clone "hg::hgrepo" gitrepo &&
@@ -344,14 +382,15 @@ test_expect_failure 'remote push diverged' '
        cd gitrepo &&
        echo diverge > content &&
        git commit -a -m diverged &&
-       test_expect_code 1 git push 2> error &&
-       grep "^ ! \[rejected\] *master -> master (non-fast-forward)$" error
+       check_push 1 <<-EOF
+       master:non-fast-forward
+       EOF
        ) &&
 
        check_branch hgrepo default bump
 '
 
-test_expect_failure 'remote update bookmark diverge' '
+test_expect_success 'remote update bookmark diverge' '
        test_when_finished "rm -rf gitrepo*" &&
 
        (
@@ -373,14 +412,15 @@ test_expect_failure 'remote update bookmark diverge' '
        git checkout --quiet diverge &&
        echo diverge > content &&
        git commit -a -m diverge &&
-       test_expect_code 1 git push 2> error &&
-       grep "^ ! \[rejected\] *diverge -> diverge (non-fast-forward)$" error
+       check_push 1 <<-EOF
+       diverge:fetch-first
+       EOF
        ) &&
 
        check_bookmark hgrepo diverge "bump bookmark"
 '
 
-test_expect_failure 'remote new bookmark multiple branch head' '
+test_expect_success 'remote new bookmark multiple branch head' '
        test_when_finished "rm -rf gitrepo*" &&
 
        (
@@ -398,9 +438,7 @@ test_expect_failure 'remote new bookmark multiple branch head' '
 # cleanup previous stuff
 rm -rf hgrepo
 
-test_expect_failure 'remote big push' '
-       test_when_finished "rm -rf hgrepo gitrepo*" &&
-
+setup_big_push () {
        (
        hg init hgrepo &&
        cd hgrepo &&
@@ -459,21 +497,28 @@ test_expect_failure 'remote big push' '
 
        git checkout -q -b branches/new_branch master &&
        echo ten > content &&
-       git commit -q -a -m ten &&
-
-       test_expect_code 1 git push origin master \
-               good_bmark bad_bmark1 bad_bmark2 new_bmark \
-               branches/good_branch branches/bad_branch \
-               branches/new_branch 2> error &&
-
-       grep "^   [a-f0-9]*\.\.[a-f0-9]* *master -> master$" error &&
-       grep "^   [a-f0-9]*\.\.[a-f0-9]* *good_bmark -> good_bmark$" error &&
-       grep "^ \* \[new branch\] *new_bmark -> new_bmark$" error &&
-       grep "^ ! \[rejected\] *bad_bmark2 -> bad_bmark2 (non-fast-forward)$" error &&
-       grep "^ ! \[rejected\] *bad_bmark1 -> bad_bmark1 (non-fast-forward)$" error &&
-       grep "^   [a-f0-9]*\.\.[a-f0-9]* *branches/good_branch -> branches/good_branch$" error &&
-       grep "^ ! \[rejected\] *branches/bad_branch -> branches/bad_branch (non-fast-forward)$" error &&
-       grep "^ \* \[new branch\] *branches/new_branch -> branches/new_branch$" error
+       git commit -q -a -m ten
+       )
+}
+
+test_expect_success 'remote big push' '
+       test_when_finished "rm -rf hgrepo gitrepo*" &&
+
+       setup_big_push
+
+       (
+       cd gitrepo &&
+
+       check_push 1 --all <<-EOF
+       master
+       good_bmark
+       branches/good_branch
+       new_bmark:new
+       branches/new_branch:new
+       bad_bmark1:non-fast-forward
+       bad_bmark2:non-fast-forward
+       branches/bad_branch:non-fast-forward
+       EOF
        ) &&
 
        check_branch hgrepo default one &&
@@ -486,4 +531,162 @@ test_expect_failure 'remote big push' '
        check_bookmark hgrepo new_bmark ''
 '
 
+test_expect_success 'remote big push fetch first' '
+       test_when_finished "rm -rf hgrepo gitrepo*" &&
+
+       (
+       hg init hgrepo &&
+       cd hgrepo &&
+       echo zero > content &&
+       hg add content &&
+       hg commit -m zero &&
+       hg bookmark bad_bmark &&
+       hg bookmark good_bmark &&
+       hg bookmark -i good_bmark &&
+       hg -q branch good_branch &&
+       echo "good branch" > content &&
+       hg commit -m "good branch" &&
+       hg -q branch bad_branch &&
+       echo "bad branch" > content &&
+       hg commit -m "bad branch"
+       ) &&
+
+       git clone "hg::hgrepo" gitrepo &&
+
+       (
+       cd hgrepo &&
+       hg bookmark -f bad_bmark &&
+       echo update_bmark > content &&
+       hg commit -m "update bmark"
+       ) &&
+
+       (
+       cd gitrepo &&
+       echo two > content &&
+       git commit -q -a -m two &&
+
+       git checkout -q good_bmark &&
+       echo three > content &&
+       git commit -q -a -m three &&
+
+       git checkout -q bad_bmark &&
+       echo four > content &&
+       git commit -q -a -m four &&
+
+       git checkout -q branches/bad_branch &&
+       echo five > content &&
+       git commit -q -a -m five &&
+
+       check_push 1 --all <<-EOF
+       master
+       good_bmark
+       new_bmark:new
+       new_branch:new
+       bad_bmark:fetch-first
+       branches/bad_branch:festch-first
+       EOF
+
+       git fetch &&
+
+       check_push 1 --all <<-EOF
+       master
+       good_bmark
+       bad_bmark:non-fast-forward
+       branches/bad_branch:non-fast-forward
+       EOF
+       )
+'
+
+test_expect_failure 'remote big push force' '
+       test_when_finished "rm -rf hgrepo gitrepo*" &&
+
+       setup_big_push
+
+       (
+       cd gitrepo &&
+
+       check_push 0 --force --all <<-EOF
+       master
+       good_bmark
+       branches/good_branch
+       new_bmark:new
+       branches/new_branch:new
+       bad_bmark1:forced-update
+       bad_bmark2:forced-update
+       branches/bad_branch:forced-update
+       EOF
+       ) &&
+
+       check_branch hgrepo default six &&
+       check_branch hgrepo good_branch eight &&
+       check_branch hgrepo bad_branch nine &&
+       check_branch hgrepo new_branch ten &&
+       check_bookmark hgrepo good_bmark three &&
+       check_bookmark hgrepo bad_bmark1 four &&
+       check_bookmark hgrepo bad_bmark2 five &&
+       check_bookmark hgrepo new_bmark six
+'
+
+test_expect_failure 'remote big push dry-run' '
+       test_when_finished "rm -rf hgrepo gitrepo*" &&
+
+       setup_big_push
+
+       (
+       cd gitrepo &&
+
+       check_push 0 --dry-run --all <<-EOF
+       master
+       good_bmark
+       branches/good_branch
+       new_bmark:new
+       branches/new_branch:new
+       bad_bmark1:non-fast-forward
+       bad_bmark2:non-fast-forward
+       branches/bad_branch:non-fast-forward
+       EOF
+
+       check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-EOF
+       master
+       good_bmark
+       branches/good_branch
+       new_bmark:new
+       branches/new_branch:new
+       EOF
+       ) &&
+
+       check_branch hgrepo default one &&
+       check_branch hgrepo good_branch "good branch" &&
+       check_branch hgrepo bad_branch "bad branch" &&
+       check_branch hgrepo new_branch '' &&
+       check_bookmark hgrepo good_bmark one &&
+       check_bookmark hgrepo bad_bmark1 one &&
+       check_bookmark hgrepo bad_bmark2 one &&
+       check_bookmark hgrepo new_bmark ''
+'
+
+test_expect_success 'remote double failed push' '
+       test_when_finished "rm -rf hgrepo gitrepo*" &&
+
+       (
+       hg init hgrepo &&
+       cd hgrepo &&
+       echo zero > content &&
+       hg add content &&
+       hg commit -m zero &&
+       echo one > content &&
+       hg commit -m one
+       ) &&
+
+       (
+       git clone "hg::hgrepo" gitrepo &&
+       cd gitrepo &&
+       git reset --hard HEAD^ &&
+       echo two > content &&
+       git commit -a -m two &&
+       test_expect_code 1 git push &&
+       test_expect_code 1 git push
+       )
+'
+
 test_done