]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-am.sh
Merge branch 'gb/apply-ignore-whitespace'
[thirdparty/git.git] / git-am.sh
index ab39b3c2fa3cb6c6e68f6193e0c4038edf8af512..3c03f3e0df96f7b993db1c3822d3f3dab8741a4b 100755 (executable)
--- a/git-am.sh
+++ b/git-am.sh
@@ -193,13 +193,33 @@ check_patch_format () {
                        esac
                        ;;
                esac
+               if test -z "$patch_format" &&
+                       test -n "$l1" &&
+                       test -n "$l2" &&
+                       test -n "$l3"
+               then
+                       # This begins with three non-empty lines.  Is this a
+                       # piece of e-mail a-la RFC2822?  Grab all the headers,
+                       # discarding the indented remainder of folded lines,
+                       # and see if it looks like that they all begin with the
+                       # header field names...
+                       sed -n -e '/^$/q' -e '/^[       ]/d' -e p "$1" |
+                       egrep -v '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null ||
+                       patch_format=mbox
+               fi
        } < "$1" || clean_abort
 }
 
 split_patches () {
        case "$patch_format" in
        mbox)
-               git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" ||
+               case "$rebasing" in
+               '')
+                       keep_cr= ;;
+               ?*)
+                       keep_cr=--keep-cr ;;
+               esac
+               git mailsplit -d"$prec" -o"$dotest" -b $keep_cr -- "$@" > "$dotest/last" ||
                clean_abort
                ;;
        stgit-series)
@@ -256,7 +276,11 @@ split_patches () {
                msgnum=
                ;;
        *)
-               clean_abort "Patch format $patch_format is not supported."
+               if test -n "$parse_patch" ; then
+                       clean_abort "Patch format $patch_format is not supported."
+               else
+                       clean_abort "Patch format detection failed."
+               fi
                ;;
        esac
 }