t4150: am with pre-applypatch hook

Since d1c5f2a (Add git-am, applymbox replacement., 2005-10-07), git-am.sg will invoke the pre-applypatch hook after applying the patch to the index, but before a commit is made. Should the hook exit with a non-zero status, git am will exit. Add tests for this hook. Helped-by: Junio C Hamano <gitster@pobox.com> Reviewed-by: Stefan Beller <sbeller@google.com> Reviewed-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Paul Tan committed Jul 19, 2015 at 23:49 UTC 3bc6686b8687e3aa0331b37464ce25b609c3ec88
1 file changed +33
t/t4150-am.sh
+33
@@ -234,6 +234,39 @@ test_expect_success 'am with failing applypatch-msg hook' '
234 test_cmp_rev first HEAD
235 '
236
237 +test_expect_success 'am with pre-applypatch hook' '
238 + test_when_finished "rm -f .git/hooks/pre-applypatch" &&
239 + rm -fr .git/rebase-apply &&
240 + git reset --hard &&
241 + git checkout first &&
242 + mkdir -p .git/hooks &&
243 + write_script .git/hooks/pre-applypatch <<-\EOF &&
244 + git diff first >diff.actual
245 + exit 0
246 + EOF
247 + git am patch1 &&
248 + test_path_is_missing .git/rebase-apply &&
249 + git diff --exit-code second &&
250 + test_cmp_rev second HEAD &&
251 + git diff first..second >diff.expected &&
252 + test_cmp diff.expected diff.actual
253 +'
254 +
255 +test_expect_success 'am with failing pre-applypatch hook' '
256 + test_when_finished "rm -f .git/hooks/pre-applypatch" &&
257 + rm -fr .git/rebase-apply &&
258 + git reset --hard &&
259 + git checkout first &&
260 + mkdir -p .git/hooks &&
261 + write_script .git/hooks/pre-applypatch <<-\EOF &&
262 + exit 1
263 + EOF
264 + test_must_fail git am patch1 &&
265 + test_path_is_dir .git/rebase-apply &&
266 + git diff --exit-code second &&
267 + test_cmp_rev first HEAD
268 +'
269 +
270 test_expect_success 'setup: new author and committer' '
271 GIT_AUTHOR_NAME="Another Thor" &&
272 GIT_AUTHOR_EMAIL="a.thor@example.com" &&