Browse Source

Merge branch 'sh/am-keep-cr'

* sh/am-keep-cr:
  git-am: Add tests for `--keep-cr`, `--no-keep-cr` and `am.keepcr`
  git-am: Add am.keepcr and --no-keep-cr to override it
  git-am: Add command line parameter `--keep-cr` passing it to git-mailsplit
  documentation: 'git-mailsplit --keep-cr' is not hidden anymore
maint
Junio C Hamano 15 years ago
parent
commit
c505a85015
  1. 7
      Documentation/config.txt
  2. 9
      Documentation/git-am.txt
  3. 5
      Documentation/git-mailsplit.txt
  4. 2
      builtin/mailsplit.c
  5. 32
      git-am.sh
  6. 96
      t/t4253-am-keep-cr-dos.sh

7
Documentation/config.txt

@ -555,6 +555,13 @@ it will be treated as a shell command. For example, defining @@ -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'

9
Documentation/git-am.txt

@ -9,7 +9,7 @@ git-am - Apply a series of patches from a mailbox @@ -9,7 +9,7 @@ git-am - Apply a series of patches from a mailbox
SYNOPSIS
--------
[verse]
'git am' [--signoff] [--keep] [--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>]
@ -39,6 +39,13 @@ OPTIONS @@ -39,6 +39,13 @@ OPTIONS
--keep::
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. `am.keepcr` configuration variable can be used to specify the
default behaviour. `--no-keep-cr` is useful to override `am.keepcr`.

-c::
--scissors::
Remove everything in body before a scissors line (see

5
Documentation/git-mailsplit.txt

@ -7,7 +7,7 @@ git-mailsplit - Simple UNIX mbox splitter program @@ -7,7 +7,7 @@ git-mailsplit - Simple UNIX mbox splitter program

SYNOPSIS
--------
'git mailsplit' [-b] [-f<nn>] [-d<prec>] -o<directory> [--] [<mbox>|<Maildir>...]
'git mailsplit' [-b] [-f<nn>] [-d<prec>] [--keep-cr] -o<directory> [--] [<mbox>|<Maildir>...]

DESCRIPTION
-----------
@ -43,6 +43,9 @@ OPTIONS @@ -43,6 +43,9 @@ OPTIONS
Skip the first <nn> numbers, for example if -f3 is specified,
start the numbering with 0004.

--keep-cr::
Do not remove `\r` from lines ending with `\r\n`.

Author
------
Written by Linus Torvalds <torvalds@osdl.org>

2
builtin/mailsplit.c

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
#include "strbuf.h"

static const char git_mailsplit_usage[] =
"git mailsplit [-d<prec>] [-f<n>] [-b] -o<directory> [<mbox>|<Maildir>...]";
"git mailsplit [-d<prec>] [-f<n>] [-b] [--keep-cr] -o<directory> [<mbox>|<Maildir>...]";

static int is_from_line(const char *line, int len)
{

32
git-am.sh

@ -15,6 +15,8 @@ q,quiet be quiet @@ -15,6 +15,8 @@ q,quiet be quiet
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
@ -217,12 +219,12 @@ check_patch_format () { @@ -217,12 +219,12 @@ check_patch_format () {
split_patches () {
case "$patch_format" in
mbox)
case "$rebasing" in
'')
keep_cr= ;;
?*)
keep_cr=--keep-cr ;;
esac
if test -n "$rebasing" || test t = "$keepcr"
then
keep_cr=--keep-cr
else
keep_cr=
fi
git mailsplit -d"$prec" -o"$dotest" -b $keep_cr -- "$@" > "$dotest/last" ||
clean_abort
;;
@ -291,13 +293,18 @@ split_patches () { @@ -291,13 +293,18 @@ split_patches () {

prec=4
dotest="$GIT_DIR/rebase-apply"
sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
sign= utf8=t keep= keepcr= skip= interactive= resolved= rebasing= abort=
resolvemsg= resume= scissors= no_inbody_headers=
git_apply_opt=
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
@ -348,6 +355,10 @@ do @@ -348,6 +355,10 @@ do
allow_rerere_autoupdate="$1" ;;
-q|--quiet)
GIT_QUIET=t ;;
--keep-cr)
keepcr=t ;;
--no-keep-cr)
keepcr=f ;;
--)
shift; break ;;
*)
@ -453,6 +464,7 @@ else @@ -453,6 +464,7 @@ else
echo "$sign" >"$dotest/sign"
echo "$utf8" >"$dotest/utf8"
echo "$keep" >"$dotest/keep"
echo "$keepcr" >"$dotest/keepcr"
echo "$scissors" >"$dotest/scissors"
echo "$no_inbody_headers" >"$dotest/no_inbody_headers"
echo "$GIT_QUIET" >"$dotest/quiet"
@ -496,6 +508,12 @@ if test "$(cat "$dotest/keep")" = t @@ -496,6 +508,12 @@ if test "$(cat "$dotest/keep")" = t
then
keep=-k
fi
case "$(cat "$dotest/keepcr")" in
t)
keepcr=--keep-cr ;;
f)
keepcr=--no-keep-cr ;;
esac
case "$(cat "$dotest/scissors")" in
t)
scissors=--scissors ;;

96
t/t4253-am-keep-cr-dos.sh

@ -0,0 +1,96 @@ @@ -0,0 +1,96 @@
#!/bin/sh
#
# Copyright (c) 2010 Stefan-W. Hahn
#

test_description='git-am mbox with dos line ending.

'
. ./test-lib.sh

# Three patches which will be added as files with dos line ending.

cat >file1 <<\EOF
line 1
EOF

cat >file1a <<\EOF
line 1
line 4
EOF

cat >file2 <<\EOF
line 1
line 2
EOF

cat >file3 <<\EOF
line 1
line 2
line 3
EOF

test_expect_success 'setup repository with dos files' '
append_cr <file1 >file &&
git add file &&
git commit -m Initial &&
git tag initial &&
append_cr <file2 >file &&
git commit -a -m Second &&
append_cr <file3 >file &&
git commit -a -m Third
'

test_expect_success 'am with dos files without --keep-cr' '
git checkout -b dosfiles initial &&
git format-patch -k initial..master &&
test_must_fail git am -k -3 000*.patch &&
git am --abort &&
rm -rf .git/rebase-apply 000*.patch
'

test_expect_success 'am with dos files with --keep-cr' '
git checkout -b dosfiles-keep-cr initial &&
git format-patch -k --stdout initial..master | git am --keep-cr -k -3 &&
git diff --exit-code master
'

test_expect_success 'am with dos files config am.keepcr' '
git config am.keepcr 1 &&
git checkout -b dosfiles-conf-keepcr initial &&
git format-patch -k --stdout initial..master | git am -k -3 &&
git diff --exit-code master
'

test_expect_success 'am with dos files config am.keepcr overriden by --no-keep-cr' '
git config am.keepcr 1 &&
git checkout -b dosfiles-conf-keepcr-override initial &&
git format-patch -k initial..master &&
test_must_fail git am -k -3 --no-keep-cr 000*.patch &&
git am --abort &&
rm -rf .git/rebase-apply 000*.patch
'

test_expect_success 'am with dos files with --keep-cr continue' '
git checkout -b dosfiles-keep-cr-continue initial &&
git format-patch -k initial..master &&
append_cr <file1a >file &&
git commit -m "different patch" file &&
test_must_fail git am --keep-cr -k -3 000*.patch &&
append_cr <file2 >file &&
git add file &&
git am -3 --resolved &&
git diff --exit-code master
'

test_expect_success 'am with unix files config am.keepcr overriden by --no-keep-cr' '
git config am.keepcr 1 &&
git checkout -b unixfiles-conf-keepcr-override initial &&
cp -f file1 file &&
git commit -m "line ending to unix" file &&
git format-patch -k initial..master &&
git am -k -3 --no-keep-cr 000*.patch &&
git diff --exit-code -w master
'

test_done
Loading…
Cancel
Save