am: don't infloop for an empty input file

git-am.sh's check_patch_format function would attempt to preview the patch to guess its format, but would go into an infinite loop when the patch file happened to be empty. The solution: exit the loop when "read" fails, not when the line var, "$l1" becomes empty. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jim Meyering committed Feb 25, 2012 at 18:34 UTC f0c5793b37a53992611968ab4a1d62a0e3edc2dd
2 files changed +11 -1
git-am.sh
+1 -1
@@ -201,7 +201,7 @@ check_patch_format () {
201 l1=
202 while test -z "$l1"
203 do
204 - read l1
204 + read l1 || break
205 done
206 read l2
207 read l3
t/t4150-am.sh
+10
@@ -495,4 +495,14 @@ test_expect_success 'am -q is quiet' '
495 ! test -s output.out
496 '
497
498 +test_expect_success 'am empty-file does not infloop' '
499 + rm -fr .git/rebase-apply &&
500 + git reset --hard &&
501 + touch empty-file &&
502 + test_tick &&
503 + { git am empty-file > actual 2>&1 && false || :; } &&
504 + echo Patch format detection failed. >expected &&
505 + test_cmp expected actual
506 +'
507 +
508 test_done