Skip to content

Commit 3bc6686

Browse files
pyokagangitster
authored andcommitted
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>
1 parent f26bdf2 commit 3bc6686

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

t/t4150-am.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,39 @@ test_expect_success 'am with failing applypatch-msg hook' '
234234
test_cmp_rev first HEAD
235235
'
236236

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+
237270
test_expect_success 'setup: new author and committer' '
238271
GIT_AUTHOR_NAME="Another Thor" &&
239272
GIT_AUTHOR_EMAIL="a.thor@example.com" &&

0 commit comments

Comments
 (0)