Skip to content

Commit 15ced75

Browse files
Oblomovgitster
authored andcommitted
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 <[email protected]>
1 parent a5a6755 commit 15ced75

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

git-am.sh

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,45 @@ check_patch_format () {
142142
then
143143
return 0
144144
fi
145-
patch_format=mbox
145+
146+
# we default to mbox format if input is from stdin and for
147+
# directories
148+
if test $# = 0 || test "x$1" = "x-" || test -d "$1"
149+
then
150+
patch_format=mbox
151+
return 0
152+
fi
153+
154+
# otherwise, check the first few lines of the first patch to try
155+
# to detect its format
156+
{
157+
read l1
158+
read l2
159+
read l3
160+
case "$l1" in
161+
"From "* | "From: "*)
162+
patch_format=mbox
163+
;;
164+
'# This series applies on GIT commit'*)
165+
patch_format=stgit-series
166+
;;
167+
"# HG changeset patch")
168+
patch_format=hg
169+
;;
170+
*)
171+
# if the second line is empty and the third is
172+
# a From, Author or Date entry, this is very
173+
# likely an StGIT patch
174+
case "$l2,$l3" in
175+
,"From: "* | ,"Author: "* | ,"Date: "*)
176+
patch_format=stgit
177+
;;
178+
*)
179+
;;
180+
esac
181+
;;
182+
esac
183+
} < "$1"
146184
}
147185

148186
split_patches () {

0 commit comments

Comments
 (0)