gc + p4 tests: use "test_hook", remove sub-shells

Refactor the repository setup code for tests that test hooks the use
of sub-shells when setting up the test repository and hooks, and use
the "test_hook" wrapper instead of "write_scripts".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason
2022-03-17 11:13:12 +01:00
committed by Junio C Hamano
parent f818f7f725
commit d7ef03681f
2 changed files with 24 additions and 21 deletions

View File

@ -277,16 +277,21 @@ test_expect_success 'run hook p4-pre-submit before submit' '
git commit -m "add hello.txt" &&
git config git-p4.skipSubmitEdit true &&
git p4 submit --dry-run >out &&
grep "Would apply" out &&
mkdir -p .git/hooks &&
write_script .git/hooks/p4-pre-submit <<-\EOF &&
exit 0
EOF
grep "Would apply" out
) &&
test_hook -C "$git" p4-pre-submit <<-\EOF &&
exit 0
EOF
(
cd "$git" &&
git p4 submit --dry-run >out &&
grep "Would apply" out &&
write_script .git/hooks/p4-pre-submit <<-\EOF &&
exit 1
EOF
grep "Would apply" out
) &&
test_hook -C "$git" --clobber p4-pre-submit <<-\EOF &&
exit 1
EOF
(
cd "$git" &&
test_must_fail git p4 submit --dry-run >errs 2>&1 &&
! grep "Would apply" errs
)