push test: simplify check of push result

This test checks each ref with code like the following:

	r=$(git show-ref -s --verify refs/$ref) &&
	test "z$r" = "z$the_first_commit"

Afterward it counts refs:

	test 1 = $(git for-each-ref refs/remotes/origin | wc -l)

Simpler to test the number and values of relevant refs in for-each-ref
output at the same time using test_cmp.  This makes the test more
readable and provides more helpful "./t5516-push-push.sh -v" output
when the test fails.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Nieder 2013-03-18 16:13:41 -07:00 committed by Junio C Hamano
parent 3c69552338
commit 848575d833

View File

@ -30,11 +30,10 @@ mk_test () {
cd testrepo && cd testrepo &&
for ref in "$@" for ref in "$@"
do do
r=$(git show-ref -s --verify refs/$ref) && echo "$the_first_commit" >expect &&
test "z$r" = "z$the_first_commit" || { git show-ref -s --verify refs/$ref >actual &&
echo "Oops, refs/$ref is wrong" test_cmp expect actual ||
exit 1 exit
}
done && done &&
git fsck --full git fsck --full
) )
@ -82,15 +81,13 @@ mk_child() {
check_push_result () { check_push_result () {
( (
cd testrepo && cd testrepo &&
it="$1" && echo "$1" >expect &&
shift shift &&
for ref in "$@" for ref in "$@"
do do
r=$(git show-ref -s --verify refs/$ref) && git show-ref -s --verify refs/$ref >actual &&
test "z$r" = "z$it" || { test_cmp expect actual ||
echo "Oops, refs/$ref is wrong" exit
exit 1
}
done && done &&
git fsck --full git fsck --full
) )
@ -118,10 +115,9 @@ test_expect_success 'fetch without wildcard' '
cd testrepo && cd testrepo &&
git fetch .. refs/heads/master:refs/remotes/origin/master && git fetch .. refs/heads/master:refs/remotes/origin/master &&
r=$(git show-ref -s --verify refs/remotes/origin/master) && echo "$the_commit commit refs/remotes/origin/master" >expect &&
test "z$r" = "z$the_commit" && git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
) )
' '
@ -133,10 +129,9 @@ test_expect_success 'fetch with wildcard' '
git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
git fetch up && git fetch up &&
r=$(git show-ref -s --verify refs/remotes/origin/master) && echo "$the_commit commit refs/remotes/origin/master" >expect &&
test "z$r" = "z$the_commit" && git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
) )
' '
@ -150,10 +145,9 @@ test_expect_success 'fetch with insteadOf' '
git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
git fetch up && git fetch up &&
r=$(git show-ref -s --verify refs/remotes/origin/master) && echo "$the_commit commit refs/remotes/origin/master" >expect &&
test "z$r" = "z$the_commit" && git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
) )
' '
@ -167,10 +161,9 @@ test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
git fetch up && git fetch up &&
r=$(git show-ref -s --verify refs/remotes/origin/master) && echo "$the_commit commit refs/remotes/origin/master" >expect &&
test "z$r" = "z$the_commit" && git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
) )
' '
@ -180,10 +173,9 @@ test_expect_success 'push without wildcard' '
git push testrepo refs/heads/master:refs/remotes/origin/master && git push testrepo refs/heads/master:refs/remotes/origin/master &&
( (
cd testrepo && cd testrepo &&
r=$(git show-ref -s --verify refs/remotes/origin/master) && echo "$the_commit commit refs/remotes/origin/master" >expect &&
test "z$r" = "z$the_commit" && git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
) )
' '
@ -193,10 +185,9 @@ test_expect_success 'push with wildcard' '
git push testrepo "refs/heads/*:refs/remotes/origin/*" && git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
( (
cd testrepo && cd testrepo &&
r=$(git show-ref -s --verify refs/remotes/origin/master) && echo "$the_commit commit refs/remotes/origin/master" >expect &&
test "z$r" = "z$the_commit" && git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
) )
' '
@ -207,10 +198,9 @@ test_expect_success 'push with insteadOf' '
git push trash/testrepo refs/heads/master:refs/remotes/origin/master && git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
( (
cd testrepo && cd testrepo &&
r=$(git show-ref -s --verify refs/remotes/origin/master) && echo "$the_commit commit refs/remotes/origin/master" >expect &&
test "z$r" = "z$the_commit" && git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
) )
' '
@ -221,10 +211,9 @@ test_expect_success 'push with pushInsteadOf' '
git push trash/testrepo refs/heads/master:refs/remotes/origin/master && git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
( (
cd testrepo && cd testrepo &&
r=$(git show-ref -s --verify refs/remotes/origin/master) && echo "$the_commit commit refs/remotes/origin/master" >expect &&
test "z$r" = "z$the_commit" && git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
) )
' '
@ -237,10 +226,9 @@ test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf
git push r refs/heads/master:refs/remotes/origin/master && git push r refs/heads/master:refs/remotes/origin/master &&
( (
cd testrepo && cd testrepo &&
r=$(git show-ref -s --verify refs/remotes/origin/master) && echo "$the_commit commit refs/remotes/origin/master" >expect &&
test "z$r" = "z$the_commit" && git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
) )
' '
@ -827,9 +815,9 @@ test_expect_success 'fetch with branches' '
( (
cd testrepo && cd testrepo &&
git fetch branch1 && git fetch branch1 &&
r=$(git show-ref -s --verify refs/heads/branch1) && echo "$the_commit commit refs/heads/branch1" >expect &&
test "z$r" = "z$the_commit" && git for-each-ref refs/heads >actual &&
test 1 = $(git for-each-ref refs/heads | wc -l) test_cmp expect actual
) && ) &&
git checkout master git checkout master
' '
@ -840,9 +828,9 @@ test_expect_success 'fetch with branches containing #' '
( (
cd testrepo && cd testrepo &&
git fetch branch2 && git fetch branch2 &&
r=$(git show-ref -s --verify refs/heads/branch2) && echo "$the_first_commit commit refs/heads/branch2" >expect &&
test "z$r" = "z$the_first_commit" && git for-each-ref refs/heads >actual &&
test 1 = $(git for-each-ref refs/heads | wc -l) test_cmp expect actual
) && ) &&
git checkout master git checkout master
' '
@ -854,9 +842,9 @@ test_expect_success 'push with branches' '
git push branch1 && git push branch1 &&
( (
cd testrepo && cd testrepo &&
r=$(git show-ref -s --verify refs/heads/master) && echo "$the_first_commit commit refs/heads/master" >expect &&
test "z$r" = "z$the_first_commit" && git for-each-ref refs/heads >actual &&
test 1 = $(git for-each-ref refs/heads | wc -l) test_cmp expect actual
) )
' '
@ -866,9 +854,9 @@ test_expect_success 'push with branches containing #' '
git push branch2 && git push branch2 &&
( (
cd testrepo && cd testrepo &&
r=$(git show-ref -s --verify refs/heads/branch3) && echo "$the_first_commit commit refs/heads/branch3" >expect &&
test "z$r" = "z$the_first_commit" && git for-each-ref refs/heads >actual &&
test 1 = $(git for-each-ref refs/heads | wc -l) test_cmp expect actual
) && ) &&
git checkout master git checkout master
' '
@ -951,9 +939,9 @@ test_expect_success 'push --porcelain' '
git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master && git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master &&
( (
cd testrepo && cd testrepo &&
r=$(git show-ref -s --verify refs/remotes/origin/master) && echo "$the_commit commit refs/remotes/origin/master" >expect &&
test "z$r" = "z$the_commit" && git for-each-ref refs/remotes/origin >actual &&
test 1 = $(git for-each-ref refs/remotes/origin | wc -l) test_cmp expect actual
) && ) &&
test_cmp .git/foo .git/bar test_cmp .git/foo .git/bar
' '