Modernize t5400 test script
Many tests checked for failure by hand without using test_must_fail (they probably predate the shell function). When we know the desired outcome, explicitly check for it, instead of checking if the result does not match one possible incorrect outcome. E.g. if you expect a push to be refused, you do not test if the result is different from what was pushed. Instead, make sure that the ref did not before and after the push. The test sequence chdir'ed around and any failure at one point could have started the next test in an unexpected directory. Fix this problem by using subshells as necessary. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
@ -32,9 +32,7 @@ test_expect_success setup '
|
|||||||
done &&
|
done &&
|
||||||
git update-ref HEAD "$commit" &&
|
git update-ref HEAD "$commit" &&
|
||||||
git clone ./. victim &&
|
git clone ./. victim &&
|
||||||
cd victim &&
|
( cd victim && git log ) &&
|
||||||
git log &&
|
|
||||||
cd .. &&
|
|
||||||
git update-ref HEAD "$zero" &&
|
git update-ref HEAD "$zero" &&
|
||||||
parent=$zero &&
|
parent=$zero &&
|
||||||
i=0 &&
|
i=0 &&
|
||||||
@ -59,88 +57,84 @@ test_expect_success 'pack the source repository' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'pack the destination repository' '
|
test_expect_success 'pack the destination repository' '
|
||||||
|
(
|
||||||
cd victim &&
|
cd victim &&
|
||||||
git repack -a -d &&
|
git repack -a -d &&
|
||||||
git prune &&
|
git prune
|
||||||
cd ..
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success 'refuse pushing rewound head without --force' '
|
||||||
'pushing rewound head should not barf but require --force' '
|
pushed_head=$(git rev-parse --verify master) &&
|
||||||
# should not fail but refuse to update.
|
victim_orig=$(cd victim && git rev-parse --verify master) &&
|
||||||
if git send-pack ./victim/.git/ master
|
test_must_fail git send-pack ./victim master &&
|
||||||
then
|
victim_head=$(cd victim && git rev-parse --verify master) &&
|
||||||
# now it should fail with Pasky patch
|
test "$victim_head" = "$victim_orig" &&
|
||||||
echo >&2 Gaah, it should have failed.
|
|
||||||
false
|
|
||||||
else
|
|
||||||
echo >&2 Thanks, it correctly failed.
|
|
||||||
true
|
|
||||||
fi &&
|
|
||||||
if cmp victim/.git/refs/heads/master .git/refs/heads/master
|
|
||||||
then
|
|
||||||
# should have been left as it was!
|
|
||||||
false
|
|
||||||
else
|
|
||||||
true
|
|
||||||
fi &&
|
|
||||||
# this should update
|
# this should update
|
||||||
git send-pack --force ./victim/.git/ master &&
|
git send-pack --force ./victim master &&
|
||||||
cmp victim/.git/refs/heads/master .git/refs/heads/master
|
victim_head=$(cd victim && git rev-parse --verify master) &&
|
||||||
|
test "$victim_head" = "$pushed_head"
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'push can be used to delete a ref' '
|
'push can be used to delete a ref' '
|
||||||
cd victim &&
|
( cd victim && git branch extra master ) &&
|
||||||
git branch extra master &&
|
git send-pack ./victim :extra master &&
|
||||||
cd .. &&
|
( cd victim &&
|
||||||
test -f victim/.git/refs/heads/extra &&
|
test_must_fail git rev-parse --verify extra )
|
||||||
git send-pack ./victim/.git/ :extra master &&
|
|
||||||
! test -f victim/.git/refs/heads/extra
|
|
||||||
'
|
'
|
||||||
|
|
||||||
unset GIT_CONFIG
|
test_expect_success 'refuse deleting push with denyDeletes' '
|
||||||
HOME=`pwd`/no-such-directory
|
(
|
||||||
export HOME ;# this way we force the victim/.git/config to be used.
|
|
||||||
|
|
||||||
test_expect_success \
|
|
||||||
'pushing a delete should be denied with denyDeletes' '
|
|
||||||
cd victim &&
|
cd victim &&
|
||||||
|
( git branch -D extra || : ) &&
|
||||||
git config receive.denyDeletes true &&
|
git config receive.denyDeletes true &&
|
||||||
git branch extra master &&
|
git branch extra master
|
||||||
cd .. &&
|
) &&
|
||||||
test -f victim/.git/refs/heads/extra &&
|
test_must_fail git send-pack ./victim :extra master
|
||||||
test_must_fail git send-pack ./victim/.git/ :extra master
|
|
||||||
'
|
'
|
||||||
rm -f victim/.git/refs/heads/extra
|
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success 'denyNonFastforwards trumps --force' '
|
||||||
'pushing with --force should be denied with denyNonFastforwards' '
|
(
|
||||||
cd victim &&
|
cd victim &&
|
||||||
git config receive.denyNonFastforwards true &&
|
( git branch -D extra || : ) &&
|
||||||
cd .. &&
|
git config receive.denyNonFastforwards true
|
||||||
git update-ref refs/heads/master master^ || return 1
|
) &&
|
||||||
git send-pack --force ./victim/.git/ master && return 1
|
victim_orig=$(cd victim && git rev-parse --verify master) &&
|
||||||
! test_cmp .git/refs/heads/master victim/.git/refs/heads/master
|
test_must_fail git send-pack --force ./victim master^:master &&
|
||||||
|
victim_head=$(cd victim && git rev-parse --verify master) &&
|
||||||
|
test "$victim_orig" = "$victim_head"
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success 'push --all excludes remote tracking hierarchy' '
|
||||||
'pushing does not include non-head refs' '
|
mkdir parent &&
|
||||||
mkdir parent && cd parent &&
|
(
|
||||||
git init && touch file && git add file && git commit -m add &&
|
cd parent &&
|
||||||
cd .. &&
|
git init && : >file && git add file && git commit -m add
|
||||||
git clone parent child && cd child && git push --all &&
|
) &&
|
||||||
cd ../parent &&
|
git clone parent child &&
|
||||||
git branch -a >branches && ! grep origin/master branches
|
(
|
||||||
|
cd child && git push --all
|
||||||
|
) &&
|
||||||
|
(
|
||||||
|
cd parent &&
|
||||||
|
test -z "$(git for-each-ref refs/remotes/origin)"
|
||||||
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
rewound_push_setup() {
|
rewound_push_setup() {
|
||||||
rm -rf parent child &&
|
rm -rf parent child &&
|
||||||
mkdir parent && cd parent &&
|
mkdir parent &&
|
||||||
git init && echo one >file && git add file && git commit -m one &&
|
(
|
||||||
echo two >file && git commit -a -m two &&
|
cd parent &&
|
||||||
cd .. &&
|
git init &&
|
||||||
git clone parent child && cd child && git reset --hard HEAD^
|
echo one >file && git add file && git commit -m one &&
|
||||||
|
echo two >file && git commit -a -m two
|
||||||
|
) &&
|
||||||
|
git clone parent child &&
|
||||||
|
(
|
||||||
|
cd child && git reset --hard HEAD^
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
rewound_push_succeeded() {
|
rewound_push_succeeded() {
|
||||||
@ -156,30 +150,44 @@ rewound_push_failed() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success 'pushing explicit refspecs respects forcing' '
|
||||||
'pushing explicit refspecs respects forcing' '
|
|
||||||
rewound_push_setup &&
|
rewound_push_setup &&
|
||||||
if git send-pack ../parent/.git refs/heads/master:refs/heads/master
|
parent_orig=$(cd parent && git rev-parse --verify master) &&
|
||||||
then
|
(
|
||||||
false
|
cd child &&
|
||||||
else
|
test_must_fail git send-pack ../parent \
|
||||||
true
|
refs/heads/master:refs/heads/master
|
||||||
fi && rewound_push_failed &&
|
) &&
|
||||||
git send-pack ../parent/.git +refs/heads/master:refs/heads/master &&
|
parent_head=$(cd parent && git rev-parse --verify master) &&
|
||||||
rewound_push_succeeded
|
test "$parent_orig" = "$parent_head" &&
|
||||||
|
(
|
||||||
|
cd child &&
|
||||||
|
git send-pack ../parent \
|
||||||
|
+refs/heads/master:refs/heads/master
|
||||||
|
) &&
|
||||||
|
parent_head=$(cd parent && git rev-parse --verify master) &&
|
||||||
|
child_head=$(cd parent && git rev-parse --verify master) &&
|
||||||
|
test "$parent_head" = "$child_head"
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success 'pushing wildcard refspecs respects forcing' '
|
||||||
'pushing wildcard refspecs respects forcing' '
|
|
||||||
rewound_push_setup &&
|
rewound_push_setup &&
|
||||||
if git send-pack ../parent/.git refs/heads/*:refs/heads/*
|
parent_orig=$(cd parent && git rev-parse --verify master) &&
|
||||||
then
|
(
|
||||||
false
|
cd child &&
|
||||||
else
|
test_must_fail git send-pack ../parent \
|
||||||
true
|
"refs/heads/*:refs/heads/*"
|
||||||
fi && rewound_push_failed &&
|
) &&
|
||||||
git send-pack ../parent/.git +refs/heads/*:refs/heads/* &&
|
parent_head=$(cd parent && git rev-parse --verify master) &&
|
||||||
rewound_push_succeeded
|
test "$parent_orig" = "$parent_head" &&
|
||||||
|
(
|
||||||
|
cd child &&
|
||||||
|
git send-pack ../parent \
|
||||||
|
"+refs/heads/*:refs/heads/*"
|
||||||
|
) &&
|
||||||
|
parent_head=$(cd parent && git rev-parse --verify master) &&
|
||||||
|
child_head=$(cd parent && git rev-parse --verify master) &&
|
||||||
|
test "$parent_head" = "$child_head"
|
||||||
'
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Reference in New Issue
Block a user