git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-am --one

From
HAH. Peter Anvin <hpa@zytor.com>
Date
Dec 14, 2005, 01:10 UTC
Message-ID
<439F7105.9050302@zytor.com>

This patch adds the --one (-o) option to git-am, to apply a single message in RFC 2822 format, as opposed to an mbox. With some MUAs it's a lot easier to save individual messages than with mboxes, and either way the user may want to control the ordering if there are known interdependencies.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
index a415fe2..bec5c84 100644
--- a/Documentation/git-am.txt
+++ b/Documentation/git-am.txt
@@ -8,7 +8,7 @@ git-am - Apply a series of patches in a 
 
 SYNOPSIS
 --------
-'git-am' [--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way] <mbox>...
+'git-am' [--one] [--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way] <mbox>...
 'git-am' [--skip | --resolved]
 
 DESCRIPTION
@@ -19,6 +19,10 @@ current branch.
 
 OPTIONS
 -------
+--one::
+	Indicates that <mbox> contains a single message in RFC 2822
+	format, without mbox-style separators.
+
 --signoff::
 	Add `Signed-off-by:` line to the commit message, using
 	the committer identity of yourself.
diff --git a/git-am.sh b/git-am.sh
index 6ed527c..9628651 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -4,7 +4,7 @@
 . git-sh-setup
 
 usage () {
-    echo >&2 "usage: $0 [--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way] <mbox>"
+    echo >&2 "usage: $0 [--one] [--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way] <mbox>"
     echo >&2 "	or, when resuming"
     echo >&2 "	$0 [--skip | --resolved]"
     exit 1;
@@ -98,11 +98,13 @@ fall_back_3way () {
 }
 
 prec=4
-dotest=.dotest sign= utf8= keep= skip= interactive= resolved= binary=
+dotest=.dotest sign= utf8= keep= skip= interactive= resolved= binary= one=
 
 while case "$#" in 0) break;; esac
 do
 	case "$1" in
+	-o|--o|--on|--one)
+	one=t; shift;;
 	-d=*|--d=*|--do=*|--dot=*|--dote=*|--dotes=*|--dotest=*)
 	dotest=`expr "$1" : '-[^=]*=\(.*\)'`; shift ;;
 	-d|--d|--do|--dot|--dote|--dotes|--dotest)
@@ -165,8 +167,16 @@ else
 	mkdir -p "$dotest" || exit
 
 	# cat does the right thing for us, including '-' to mean
-	# standard input.
-	cat "$@" |
+	# standard input.  To prepend the header, we thus want a
+	# second cat, sigh...
+	if test "$one" = t
+	then
+		LANG=C date +'From - %a %b %d %T %Y' > "$dotest"/fakefrom
+		fakefrom="$dotest"/fakefrom
+	else
+		fakefrom=/dev/null
+	fi
+	cat "$@" | cat "$fakefrom" - |
 	git-mailsplit -d$prec "$dotest/" >"$dotest/last" || {
 		rm -fr "$dotest"
 		exit 1
Next: Junio C Hamano
Message 1 of 6 in “git-am --one”
  1. git-am --oneH. Peter Anvin, Dec 14, 2005
  2. Junio C HamanoDec 14, 2005
  3. H. Peter AnvinDec 14, 2005
  4. Junio C HamanoDec 14, 2005
  5. H. Peter AnvinDec 14, 2005
  6. Junio C HamanoDec 14, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.