Skip to content

Commit beace29

Browse files
committed
Merge branch 'db/am-skip-blank-at-the-beginning'
* db/am-skip-blank-at-the-beginning: am: ignore leading whitespace before patch
2 parents d8308c7 + 0e8341f commit beace29

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

git-am.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,15 @@ check_patch_format () {
197197
return 0
198198
fi
199199

200-
# otherwise, check the first few lines of the first patch to try
201-
# to detect its format
200+
# otherwise, check the first few non-blank lines of the first
201+
# patch to try to detect its format
202202
{
203-
read l1
203+
# Start from first line containing non-whitespace
204+
l1=
205+
while test -z "$l1"
206+
do
207+
read l1
208+
done
204209
read l2
205210
read l3
206211
case "$l1" in

t/t4150-am.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ test_expect_success setup '
9696
echo "X-Fake-Field: Line Three" &&
9797
git format-patch --stdout first | sed -e "1d"
9898
} | append_cr >patch1-crlf.eml &&
99+
{
100+
printf "%255s\\n" ""
101+
echo "X-Fake-Field: Line One" &&
102+
echo "X-Fake-Field: Line Two" &&
103+
echo "X-Fake-Field: Line Three" &&
104+
git format-patch --stdout first | sed -e "1d"
105+
} > patch1-ws.eml &&
99106
100107
sed -n -e "3,\$p" msg >file &&
101108
git add file &&
@@ -167,6 +174,17 @@ test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
167174
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
168175
'
169176

177+
test_expect_success 'am applies patch e-mail with preceding whitespace' '
178+
rm -fr .git/rebase-apply &&
179+
git reset --hard &&
180+
git checkout first &&
181+
git am patch1-ws.eml &&
182+
! test -d .git/rebase-apply &&
183+
git diff --exit-code second &&
184+
test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
185+
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
186+
'
187+
170188
test_expect_success 'setup: new author and committer' '
171189
GIT_AUTHOR_NAME="Another Thor" &&
172190
GIT_AUTHOR_EMAIL="a.thor@example.com" &&

0 commit comments

Comments
 (0)