am: ignore leading whitespace before patch
Some web-based email clients prepend whitespace to raw message transcripts to workaround content-sniffing in some browsers. Adjust the patch format detection logic to ignore leading whitespace. So now you can apply patches from GMail with "git am" in three steps: 1. choose "show original" 2. tell the browser to "save as" (for example by pressing Ctrl+S) 3. run "git am" on the saved file This fixes a regression introduced by v1.6.4-rc0~15^2~2 (git-am foreign patch support: autodetect some patch formats, 2009-05-27). GMail support was first introduced to "git am" by v1.5.4-rc0~274^2 (Make mailsplit and mailinfo strip whitespace from the start of the input, 2007-11-01). Signed-off-by: David Barr <davidbarr@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
e7a85be3cf
commit
0e8341f29d
11
git-am.sh
11
git-am.sh
|
@ -196,10 +196,15 @@ check_patch_format () {
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# otherwise, check the first few lines of the first patch to try
|
# otherwise, check the first few non-blank lines of the first
|
||||||
# to detect its format
|
# patch to try to detect its format
|
||||||
{
|
{
|
||||||
read l1
|
# Start from first line containing non-whitespace
|
||||||
|
l1=
|
||||||
|
while test -z "$l1"
|
||||||
|
do
|
||||||
|
read l1
|
||||||
|
done
|
||||||
read l2
|
read l2
|
||||||
read l3
|
read l3
|
||||||
case "$l1" in
|
case "$l1" in
|
||||||
|
|
|
@ -96,6 +96,13 @@ test_expect_success setup '
|
||||||
echo "X-Fake-Field: Line Three" &&
|
echo "X-Fake-Field: Line Three" &&
|
||||||
git format-patch --stdout first | sed -e "1d"
|
git format-patch --stdout first | sed -e "1d"
|
||||||
} | append_cr >patch1-crlf.eml &&
|
} | append_cr >patch1-crlf.eml &&
|
||||||
|
{
|
||||||
|
printf "%255s\\n" ""
|
||||||
|
echo "X-Fake-Field: Line One" &&
|
||||||
|
echo "X-Fake-Field: Line Two" &&
|
||||||
|
echo "X-Fake-Field: Line Three" &&
|
||||||
|
git format-patch --stdout first | sed -e "1d"
|
||||||
|
} > patch1-ws.eml &&
|
||||||
|
|
||||||
sed -n -e "3,\$p" msg >file &&
|
sed -n -e "3,\$p" msg >file &&
|
||||||
git add file &&
|
git add file &&
|
||||||
|
@ -167,6 +174,17 @@ test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
|
||||||
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
|
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'am applies patch e-mail with preceding whitespace' '
|
||||||
|
rm -fr .git/rebase-apply &&
|
||||||
|
git reset --hard &&
|
||||||
|
git checkout first &&
|
||||||
|
git am patch1-ws.eml &&
|
||||||
|
! test -d .git/rebase-apply &&
|
||||||
|
git diff --exit-code second &&
|
||||||
|
test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
|
||||||
|
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'setup: new author and committer' '
|
test_expect_success 'setup: new author and committer' '
|
||||||
GIT_AUTHOR_NAME="Another Thor" &&
|
GIT_AUTHOR_NAME="Another Thor" &&
|
||||||
GIT_AUTHOR_EMAIL="a.thor@example.com" &&
|
GIT_AUTHOR_EMAIL="a.thor@example.com" &&
|
||||||
|
|
Loading…
Reference in New Issue