Skip to content

Commit f0c5793

Browse files
meyeringgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ad687b4 commit f0c5793

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

git-am.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ check_patch_format () {
201201
l1=
202202
while test -z "$l1"
203203
do
204-
read l1
204+
read l1 || break
205205
done
206206
read l2
207207
read l3

t/t4150-am.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,4 +495,14 @@ test_expect_success 'am -q is quiet' '
495495
! test -s output.out
496496
'
497497

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+
498508
test_done

0 commit comments

Comments
 (0)