summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2012-02-25 17:34:26 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-02-27 00:32:54 (GMT)
commitf0c5793b37a53992611968ab4a1d62a0e3edc2dd (patch)
tree56d00d3f93f74032aa45899a931dd6f4872bb082
parentad687b447a87efaf61c39075da2ef81b85715186 (diff)
downloadgit-f0c5793b37a53992611968ab4a1d62a0e3edc2dd.zip
git-f0c5793b37a53992611968ab4a1d62a0e3edc2dd.tar.gz
git-f0c5793b37a53992611968ab4a1d62a0e3edc2dd.tar.bz2
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>
-rwxr-xr-xgit-am.sh2
-rwxr-xr-xt/t4150-am.sh10
2 files changed, 11 insertions, 1 deletions
diff --git a/git-am.sh b/git-am.sh
index 1c13b13..f43a75b 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -201,7 +201,7 @@ check_patch_format () {
l1=
while test -z "$l1"
do
- read l1
+ read l1 || break
done
read l2
read l3
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index d7d9ccc..03eee07 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -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