Skip to content

Commit

Permalink
am: don't infloop for an empty input file
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
meyering authored and gitster committed Feb 27, 2012
1 parent ad687b4 commit f0c5793
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion git-am.sh
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ check_patch_format () {
l1=
while test -z "$l1"
do
read l1
read l1 || break
done
read l2
read l3
Expand Down
10 changes: 10 additions & 0 deletions t/t4150-am.sh
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,14 @@ test_expect_success 'am -q is quiet' '
! test -s output.out
'

test_expect_success 'am empty-file does not infloop' '
rm -fr .git/rebase-apply &&
git reset --hard &&
touch empty-file &&
test_tick &&
{ git am empty-file > actual 2>&1 && false || :; } &&
echo Patch format detection failed. >expected &&
test_cmp expected actual
'

test_done

0 comments on commit f0c5793

Please sign in to comment.