Skip to content

Commit ad2c928

Browse files
Stefan-W. Hahngitster
authored andcommitted
git-am: Add command line parameter --keep-cr passing it to git-mailsplit
c2ca1d7 (Allow mailsplit (and hence git-am) to handle mails with CRLF line-endings, 2009-08-04) fixed "git mailsplit" to help people with MUA whose output from save-as command uses CRLF as line terminators by stripping CR at the end of lines. However, when you know you are feeding output from "git format-patch" directly to "git am", and especially when your contents have CR at the end of line, such stripping is undesirable. To help such a use case, teach --keep-cr option to "git am" and pass that to "git mailinfo". Signed-off-by: Stefan-W. Hahn <stefan.hahn@s-hahn.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent abeb09b commit ad2c928

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

Documentation/git-am.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-am - Apply a series of patches from a mailbox
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git am' [--signoff] [--keep] [--utf8 | --no-utf8]
12+
'git am' [--signoff] [--keep] [--keep-cr] [--utf8 | --no-utf8]
1313
[--3way] [--interactive] [--committer-date-is-author-date]
1414
[--ignore-date] [--ignore-space-change | --ignore-whitespace]
1515
[--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
@@ -39,6 +39,11 @@ OPTIONS
3939
--keep::
4040
Pass `-k` flag to 'git mailinfo' (see linkgit:git-mailinfo[1]).
4141

42+
--keep-cr::
43+
With `--keep-cr`, call 'git mailsplit' (see linkgit:git-mailsplit[1])
44+
with the same option, to prevent it from stripping CR at the end of
45+
lines.
46+
4247
-c::
4348
--scissors::
4449
Remove everything in body before a scissors line (see

git-am.sh

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ q,quiet be quiet
1515
s,signoff add a Signed-off-by line to the commit message
1616
u,utf8 recode into utf8 (default)
1717
k,keep pass -k flag to git-mailinfo
18+
keep-cr pass --keep-cr flag to git-mailsplit for mbox format
1819
c,scissors strip everything before a scissors line
1920
whitespace= pass it through git-apply
2021
ignore-space-change pass it through git-apply
@@ -217,12 +218,12 @@ check_patch_format () {
217218
split_patches () {
218219
case "$patch_format" in
219220
mbox)
220-
case "$rebasing" in
221-
'')
222-
keep_cr= ;;
223-
?*)
224-
keep_cr=--keep-cr ;;
225-
esac
221+
if test -n "$rebasing$keepcr"
222+
then
223+
keep_cr=--keep-cr
224+
else
225+
keep_cr=
226+
fi
226227
git mailsplit -d"$prec" -o"$dotest" -b $keep_cr -- "$@" > "$dotest/last" ||
227228
clean_abort
228229
;;
@@ -291,7 +292,7 @@ split_patches () {
291292

292293
prec=4
293294
dotest="$GIT_DIR/rebase-apply"
294-
sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
295+
sign= utf8=t keep= keepcr= skip= interactive= resolved= rebasing= abort=
295296
resolvemsg= resume= scissors= no_inbody_headers=
296297
git_apply_opt=
297298
committer_date_is_author_date=
@@ -348,6 +349,8 @@ do
348349
allow_rerere_autoupdate="$1" ;;
349350
-q|--quiet)
350351
GIT_QUIET=t ;;
352+
--keep-cr)
353+
keepcr=t ;;
351354
--)
352355
shift; break ;;
353356
*)
@@ -453,6 +456,7 @@ else
453456
echo "$sign" >"$dotest/sign"
454457
echo "$utf8" >"$dotest/utf8"
455458
echo "$keep" >"$dotest/keep"
459+
echo "$keepcr" >"$dotest/keepcr"
456460
echo "$scissors" >"$dotest/scissors"
457461
echo "$no_inbody_headers" >"$dotest/no_inbody_headers"
458462
echo "$GIT_QUIET" >"$dotest/quiet"
@@ -496,6 +500,10 @@ if test "$(cat "$dotest/keep")" = t
496500
then
497501
keep=-k
498502
fi
503+
if test "$(cat "$dotest/keepcr")" = t
504+
then
505+
keepcr=--keep-cr
506+
fi
499507
case "$(cat "$dotest/scissors")" in
500508
t)
501509
scissors=--scissors ;;

0 commit comments

Comments
 (0)