am: fix patch format detection for Thunderbird "Save As" emails
The patch detection wants to inspect all the headers of a rfc2822 message and ensure that they look like header fields. The headers are always separated from the message body with a blank line. When Thunderbird saves the message the blank line separating the headers from the body includes a CR. The patch detection is failing because a CRLF doesn't match /^$/. Fix this by allowing a CR to exist on the separating line. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stephen Boyd committed
Jan 25, 2010 at 16:33 UTC
e3f67d30b20e49d8fc3eefe819808cba7998b060
2 files changed
+17
-1
git-am.sh
+2
-1
@@ -205,7 +205,8 @@ check_patch_format () {
205
# discarding the indented remainder of folded lines,
206
# and see if it looks like that they all begin with the
207
# header field names...
208
- sed -n -e '/^$/q' -e '/^[ ]/d' -e p "$1" |
208
+ tr -d '\015' <"$1" |
209
+ sed -n -e '/^$/q' -e '/^[ ]/d' -e p |
210
sane_egrep -v '^[!-9;-~]+:' >/dev/null ||
211
patch_format=mbox
212
fi
t/t4150-am.sh
+15
@@ -83,6 +83,12 @@ test_expect_success setup '
83
echo "X-Fake-Field: Line Three" &&
84
git format-patch --stdout first | sed -e "1d"
85
} > patch1.eml &&
86
+ {
87
+ echo "X-Fake-Field: Line One" &&
88
+ echo "X-Fake-Field: Line Two" &&
89
+ echo "X-Fake-Field: Line Three" &&
90
+ git format-patch --stdout first | sed -e "1d"
91
+ } | append_cr >patch1-crlf.eml &&
92
sed -n -e "3,\$p" msg >file &&
93
git add file &&
94
test_tick &&
@@ -123,6 +129,15 @@ test_expect_success 'am applies patch e-mail not in a mbox' '
129
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
130
'
131
132
+test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
133
+ git checkout first &&
134
+ git am patch1-crlf.eml &&
135
+ ! test -d .git/rebase-apply &&
136
+ test -z "$(git diff second)" &&
137
+ test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
138
+ test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
139
+'
140
+
141
GIT_AUTHOR_NAME="Another Thor"
142
GIT_AUTHOR_EMAIL="a.thor@example.com"
143
GIT_COMMITTER_NAME="Co M Miter"