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>
Paul Tan committed
Jul 19, 2015 at 23:49 UTC
f26bdf2d98b6efbf02e65ef41a33b31cd3fbfcb9
1 file changed
+35
t/t4150-am.sh
+35
@@ -199,6 +199,41 @@ test_expect_success 'am applies patch e-mail with preceding whitespace' '
199
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
200
'
201
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
+
237
test_expect_success 'setup: new author and committer' '
238
GIT_AUTHOR_NAME="Another Thor" &&
239
GIT_AUTHOR_EMAIL="a.thor@example.com" &&