mirror of
https://github.com/git/git
synced 2024-08-25 10:45:59 +00:00
Merge branch 'jk/test-lint-forbid-when-finished-in-subshell' into maint
Because "test_when_finished" in our test framework queues the clean-up tasks to be done in a shell variable, it should not be used inside a subshell. Add a mechanism to allow 'bash' to catch such uses, and fix the ones that were found. * jk/test-lint-forbid-when-finished-in-subshell: test-lib-functions: detect test_when_finished in subshell t7800: don't use test_config in a subshell test-lib-functions: support "test_config -C <dir> ..." t5801: don't use test_when_finished in a subshell t7610: don't use test_config in a subshell
This commit is contained in:
commit
4cb5488fa6
|
@ -242,13 +242,6 @@ clean_mark () {
|
|||
sort >$(basename "$1")
|
||||
}
|
||||
|
||||
cmp_marks () {
|
||||
test_when_finished "rm -rf git.marks testgit.marks" &&
|
||||
clean_mark ".git/testgit/$1/git.marks" &&
|
||||
clean_mark ".git/testgit/$1/testgit.marks" &&
|
||||
test_cmp git.marks testgit.marks
|
||||
}
|
||||
|
||||
test_expect_success 'proper failure checks for fetching' '
|
||||
(cd local &&
|
||||
test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error &&
|
||||
|
@ -258,12 +251,15 @@ test_expect_success 'proper failure checks for fetching' '
|
|||
'
|
||||
|
||||
test_expect_success 'proper failure checks for pushing' '
|
||||
test_when_finished "rm -rf local/git.marks local/testgit.marks" &&
|
||||
(cd local &&
|
||||
git checkout -b crash master &&
|
||||
echo crash >>file &&
|
||||
git commit -a -m crash &&
|
||||
test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all &&
|
||||
cmp_marks origin
|
||||
clean_mark ".git/testgit/origin/git.marks" &&
|
||||
clean_mark ".git/testgit/origin/testgit.marks" &&
|
||||
test_cmp git.marks testgit.marks
|
||||
)
|
||||
'
|
||||
|
||||
|
|
|
@ -174,9 +174,9 @@ test_expect_success 'mergetool skips autoresolved' '
|
|||
'
|
||||
|
||||
test_expect_success 'mergetool merges all from subdir' '
|
||||
test_config rerere.enabled false &&
|
||||
(
|
||||
cd subdir &&
|
||||
test_config rerere.enabled false &&
|
||||
test_must_fail git merge master &&
|
||||
( yes "r" | git mergetool ../submod ) &&
|
||||
( yes "d" "d" | git mergetool --no-prompt ) &&
|
||||
|
|
|
@ -492,12 +492,12 @@ test_expect_success PERL 'difftool --no-symlinks detects conflict ' '
|
|||
|
||||
test_expect_success PERL 'difftool properly honors gitlink and core.worktree' '
|
||||
git submodule add ./. submod/ule &&
|
||||
test_config -C submod/ule diff.tool checktrees &&
|
||||
test_config -C submod/ule difftool.checktrees.cmd '\''
|
||||
test -d "$LOCAL" && test -d "$REMOTE" && echo good
|
||||
'\'' &&
|
||||
(
|
||||
cd submod/ule &&
|
||||
test_config diff.tool checktrees &&
|
||||
test_config difftool.checktrees.cmd '\''
|
||||
test -d "$LOCAL" && test -d "$REMOTE" && echo good
|
||||
'\'' &&
|
||||
echo good >expect &&
|
||||
git difftool --tool=checktrees --dir-diff HEAD~ >actual &&
|
||||
test_cmp expect actual
|
||||
|
|
|
@ -201,7 +201,14 @@ test_chmod () {
|
|||
|
||||
# Unset a configuration variable, but don't fail if it doesn't exist.
|
||||
test_unconfig () {
|
||||
git config --unset-all "$@"
|
||||
config_dir=
|
||||
if test "$1" = -C
|
||||
then
|
||||
shift
|
||||
config_dir=$1
|
||||
shift
|
||||
fi
|
||||
git ${config_dir:+-C "$config_dir"} config --unset-all "$@"
|
||||
config_status=$?
|
||||
case "$config_status" in
|
||||
5) # ok, nothing to unset
|
||||
|
@ -213,8 +220,15 @@ test_unconfig () {
|
|||
|
||||
# Set git config, automatically unsetting it after the test is over.
|
||||
test_config () {
|
||||
test_when_finished "test_unconfig '$1'" &&
|
||||
git config "$@"
|
||||
config_dir=
|
||||
if test "$1" = -C
|
||||
then
|
||||
shift
|
||||
config_dir=$1
|
||||
shift
|
||||
fi
|
||||
test_when_finished "test_unconfig ${config_dir:+-C '$config_dir'} '$1'" &&
|
||||
git ${config_dir:+-C "$config_dir"} config "$@"
|
||||
}
|
||||
|
||||
test_config_global () {
|
||||
|
@ -722,6 +736,11 @@ test_seq () {
|
|||
# what went wrong.
|
||||
|
||||
test_when_finished () {
|
||||
# We cannot detect when we are in a subshell in general, but by
|
||||
# doing so on Bash is better than nothing (the test will
|
||||
# silently pass on other shells).
|
||||
test "${BASH_SUBSHELL-0}" = 0 ||
|
||||
error "bug in test script: test_when_finished does nothing in a subshell"
|
||||
test_cleanup="{ $*
|
||||
} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue