Skip to content

Commit f26bdf2

Browse files
pyokagangitster
authored andcommitted
t4150: am with applypatch-msg hook
Since d1c5f2a (Add git-am, applymbox replacement., 2005-10-07), git-am will invoke the applypatch-msg hooks just after extracting the patch message. If the applypatch-msg hook exits with a non-zero status, git-am abort before even applying the patch to the index. 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 9e2a113 commit f26bdf2

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

t/t4150-am.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,41 @@ test_expect_success 'am applies patch e-mail with preceding whitespace' '
199199
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
200200
'
201201

202+
test_expect_success 'am with applypatch-msg hook' '
203+
test_when_finished "rm -f .git/hooks/applypatch-msg" &&
204+
rm -fr .git/rebase-apply &&
205+
git reset --hard &&
206+
git checkout first &&
207+
mkdir -p .git/hooks &&
208+
write_script .git/hooks/applypatch-msg <<-\EOF &&
209+
cat "$1" >actual-msg &&
210+
echo hook-message >"$1"
211+
EOF
212+
git am patch1 &&
213+
test_path_is_missing .git/rebase-apply &&
214+
git diff --exit-code second &&
215+
echo hook-message >expected &&
216+
git log -1 --format=format:%B >actual &&
217+
test_cmp expected actual &&
218+
git log -1 --format=format:%B second >expected &&
219+
test_cmp expected actual-msg
220+
'
221+
222+
test_expect_success 'am with failing applypatch-msg hook' '
223+
test_when_finished "rm -f .git/hooks/applypatch-msg" &&
224+
rm -fr .git/rebase-apply &&
225+
git reset --hard &&
226+
git checkout first &&
227+
mkdir -p .git/hooks &&
228+
write_script .git/hooks/applypatch-msg <<-\EOF &&
229+
exit 1
230+
EOF
231+
test_must_fail git am patch1 &&
232+
test_path_is_dir .git/rebase-apply &&
233+
git diff --exit-code first &&
234+
test_cmp_rev first HEAD
235+
'
236+
202237
test_expect_success 'setup: new author and committer' '
203238
GIT_AUTHOR_NAME="Another Thor" &&
204239
GIT_AUTHOR_EMAIL="a.thor@example.com" &&

0 commit comments

Comments
 (0)