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

[PATCH 3/4] git-am: Add configuration am.keepcr and parameter --no-keep-cr to override configuration.

From
SHStefan-W. Hahn <stefan.hahn@s-hahn.de>
Date
Feb 27, 2010, 14:20 UTC
Message-ID
<1267280428-18223-4-git-send-email-stefan.hahn@s-hahn.de>
In-Reply-To
<1266080362-24760-1-git-send-email-stefan.hahn@s-hahn.de>

This patch adds the configuration `am.keepcr` for git-am. It also adds `--no-keep-cr` parameter for git-am to give the possibility to override configuration from command line.

Signed-off-by: Stefan-W. Hahn <stefan.hahn@s-hahn.de>
---
 Documentation/config.txt |    7 +++++++
 Documentation/git-am.txt |    6 ++++--
 git-am.sh                |   20 +++++++++++++++-----
 3 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 664de6b..403c392 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -555,6 +555,13 @@ it will be treated as a shell command.  For example, defining
 executed from the top-level directory of a repository, which may
 not necessarily be the current directory.
 
+am.keepcr::
+	If true, git-am will call git-mailsplit for patches in mbox format 
+	with parameter '--keep-cr'. In this case git-mailsplit will
+	not remove `\r` from lines ending with `\r\n`. Can be overrriden
+	by giving '--no-keep-cr' from the command line.
+	See linkgit:git-am[1], linkgit:git-mailsplit[1].
+
 apply.ignorewhitespace::
 	When set to 'change', tells 'git apply' to ignore changes in
 	whitespace, in the same way as the '--ignore-space-change'
diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
index df3c6d6..aef2b86 100644
--- a/Documentation/git-am.txt
+++ b/Documentation/git-am.txt
@@ -9,7 +9,7 @@ git-am - Apply a series of patches from a mailbox
 SYNOPSIS
 --------
 [verse]
-'git am' [--signoff] [--keep] [--keep-cr] [--utf8 | --no-utf8]
+'git am' [--signoff] [--keep] [--keep-cr | --no-keep-cr] [--utf8 | --no-utf8]
 	 [--3way] [--interactive] [--committer-date-is-author-date]
 	 [--ignore-date] [--ignore-space-change | --ignore-whitespace]
 	 [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
@@ -40,9 +40,11 @@ OPTIONS
 	Pass `-k` flag to 'git mailinfo' (see linkgit:git-mailinfo[1]).
 
 --keep-cr::
+--no-keep-cr::
 	With `--keep-cr`, call 'git mailsplit' (see linkgit:git-mailsplit[1])
 	with the same option, to prevent it from stripping CR at the end of 
-	lines.
+	lines. `am.keepcr` configuration variable can be used to specify the 
+	default behaviour.  `--no-keep-cr` is useful to override `am.keepcr`.
 
 -c::
 --scissors::
diff --git a/git-am.sh b/git-am.sh
index 7563609..ed42df0 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -16,6 +16,7 @@ s,signoff       add a Signed-off-by line to the commit message
 u,utf8          recode into utf8 (default)
 k,keep          pass -k flag to git-mailinfo
 keep-cr         pass --keep-cr flag to git-mailsplit for mbox format
+no-keep-cr      do not pass --keep-cr flag to git-mailsplit independent of am.keepcr
 c,scissors      strip everything before a scissors line
 whitespace=     pass it through git-apply
 ignore-space-change pass it through git-apply
@@ -218,7 +219,7 @@ check_patch_format () {
 split_patches () {
 	case "$patch_format" in
 	mbox)
-		if test -n "$rebasing$keepcr"
+		if test -n "$rebasing" -o "$keepcr" = t
 		then
                     keep_cr=--keep-cr
 		else
@@ -299,6 +300,11 @@ committer_date_is_author_date=
 ignore_date=
 allow_rerere_autoupdate=
 
+if test "$(git config --bool --get am.keepcr)" = true
+then 
+    keepcr=t
+fi
+
 while test $# != 0
 do
 	case "$1" in
@@ -351,6 +357,8 @@ do
 		GIT_QUIET=t ;;
 	--keep-cr)
 		keepcr=t ;;
+	--no-keep-cr)
+		keepcr=f ;;
 	--)
 		shift; break ;;
 	*)
@@ -500,10 +508,12 @@ if test "$(cat "$dotest/keep")" = t
 then
 	keep=-k
 fi
-if test "$(cat "$dotest/keepcr")" = t
-then
-	keepcr=--keep-cr
-fi
+case "$(cat "$dotest/keepcr")" in
+t)
+	keepcr=--keep-cr ;;
+f)
+	keepcr=--no-keep-cr ;;
+esac
 case "$(cat "$dotest/scissors")" in
 t)
 	scissors=--scissors ;;
-- 
1.7.0.98.g42448
Previous: Stefan-W. HahnNext: Stefan-W. Hahn
Message 14 of 15 in “[PATCHv3 0/3] Using git-mailsplit in mixed line ending environment”
  1. Stefan-W. HahnFeb 13, 2010
  2. 1/3 git-mailsplit: Show parameter '--keep-cr' in usage and documentationStefan-W. Hahn, Feb 13, 2010
  3. 2/3 git-am: Add command line parameter `--keep-cr` passing it to git-mailsplit.Stefan-W. Hahn, Feb 13, 2010
  4. 3/3 Adding test for `--keep-cr` for git-am.Stefan-W. Hahn, Feb 13, 2010
  5. 1/3 git-mailsplit: Show parameter '--keep-cr' in usage and documentationStefan-W. Hahn, Feb 13, 2010
  6. 2/3 git-am: Add command line parameter `--keep-cr` passing it to git-mailsplit.Stefan-W. Hahn, Feb 13, 2010
  7. Junio C HamanoFeb 22, 2010
  8. 3/3 Adding test for `--keep-cr` for git-am.Stefan-W. Hahn, Feb 13, 2010
  9. Junio C HamanoFeb 22, 2010
  10. 0/4 Using git-mailsplit in mixed line ending environmentStefan-W. Hahn, Feb 27, 2010
  11. Junio C HamanoFeb 28, 2010
  12. 1/4 git-mailsplit: Show parameter '--keep-cr' in usage and documentationStefan-W. Hahn, Feb 27, 2010
  13. 2/4 git-am: Add command line parameter `--keep-cr` passing it to git-mailsplit.Stefan-W. Hahn, Feb 27, 2010
  14. 3/4 git-am: Add configuration am.keepcr and parameter --no-keep-cr to override configuration.Stefan-W. Hahn, Feb 27, 2010
  15. 4/4 git-am: Adding tests for `--keep-cr`, `--no-keep-cr` and `am.keepcr`.Stefan-W. Hahn, Feb 27, 2010

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.