aboutsummaryrefslogtreecommitdiff
path: root/git-am.sh
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-05-27 23:20:12 +0200
committerJunio C Hamano <gitster@pobox.com>2009-05-28 23:06:34 -0700
commit15ced753ac091314941abb28302f7109a9e86b81 (patch)
treeb70f1f53516d83aba7e6faedf8d41f64acf991f6 /git-am.sh
parenta5a6755a1d4707bf2fab7752e5c974ebf63d086a (diff)
downloadgit-15ced753ac091314941abb28302f7109a9e86b81.tar.gz
git-15ced753ac091314941abb28302f7109a9e86b81.tar.xz
git-am foreign patch support: autodetect some patch formats
Default to mbox format if input is from stdin. Otherwise, look at the first few lines of the first patch to try to guess its format. Include checks for mailboxes, stgit patch series, stgit single patches and hg patches. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-am.sh')
-rwxr-xr-xgit-am.sh40
1 files changed, 39 insertions, 1 deletions
diff --git a/git-am.sh b/git-am.sh
index da160de3c..552b88870 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -142,7 +142,45 @@ check_patch_format () {
then
return 0
fi
- patch_format=mbox
+
+ # we default to mbox format if input is from stdin and for
+ # directories
+ if test $# = 0 || test "x$1" = "x-" || test -d "$1"
+ then
+ patch_format=mbox
+ return 0
+ fi
+
+ # otherwise, check the first few lines of the first patch to try
+ # to detect its format
+ {
+ read l1
+ read l2
+ read l3
+ case "$l1" in
+ "From "* | "From: "*)
+ patch_format=mbox
+ ;;
+ '# This series applies on GIT commit'*)
+ patch_format=stgit-series
+ ;;
+ "# HG changeset patch")
+ patch_format=hg
+ ;;
+ *)
+ # if the second line is empty and the third is
+ # a From, Author or Date entry, this is very
+ # likely an StGIT patch
+ case "$l2,$l3" in
+ ,"From: "* | ,"Author: "* | ,"Date: "*)
+ patch_format=stgit
+ ;;
+ *)
+ ;;
+ esac
+ ;;
+ esac
+ } < "$1"
}
split_patches () {