am: learn passing -b to mailinfo

git-am could pass -k to mailinfo, but not -b. Introduce an option that does so. We change the meaning of the 'keep' state file, but are careful not to cause a problem unless you downgrade in the middle of an 'am' run. This uncovers a bug in mailinfo -b, hence the failing test. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Jan 16, 2012 at 11:53 UTC f7e5ea171b693bf5fc88e059d9d4af3753c09143
3 files changed +31 -6
Documentation/git-am.txt
+3
@@ -39,6 +39,9 @@ OPTIONS
39 --keep::
40 Pass `-k` flag to 'git mailinfo' (see linkgit:git-mailinfo[1]).
41
42 +--keep-non-patch::
43 + Pass `-b` flag to 'git mailinfo' (see linkgit:git-mailinfo[1]).
44 +
45 --keep-cr::
46 --no-keep-cr::
47 With `--keep-cr`, call 'git mailsplit' (see linkgit:git-mailsplit[1])
git-am.sh
+16 -4
@@ -15,6 +15,7 @@ q,quiet be quiet
15 s,signoff add a Signed-off-by line to the commit message
16 u,utf8 recode into utf8 (default)
17 k,keep pass -k flag to git-mailinfo
18 +keep-non-patch pass -b flag to git-mailinfo
19 keep-cr pass --keep-cr flag to git-mailsplit for mbox format
20 no-keep-cr do not pass --keep-cr flag to git-mailsplit independent of am.keepcr
21 c,scissors strip everything before a scissors line
@@ -345,6 +346,8 @@ do
346 utf8= ;;
347 -k|--keep)
348 keep=t ;;
349 + --keep-non-patch)
350 + keep=b ;;
351 -c|--scissors)
352 scissors=t ;;
353 --no-scissors)
@@ -522,16 +525,25 @@ case "$resolved" in
525 fi
526 esac
527
528 +# Now, decide what command line options we will give to the git
529 +# commands we invoke, based on the result of parsing command line
530 +# options and previous invocation state stored in $dotest/ files.
531 +
532 if test "$(cat "$dotest/utf8")" = t
533 then
534 utf8=-u
535 else
536 utf8=-n
537 fi
531 -if test "$(cat "$dotest/keep")" = t
532 -then
533 - keep=-k
534 -fi
538 +keep=$(cat "$dotest/keep")
539 +case "$keep" in
540 +t)
541 + keep=-k ;;
542 +b)
543 + keep=-b ;;
544 +*)
545 + keep= ;;
546 +esac
547 case "$(cat "$dotest/keepcr")" in
548 t)
549 keepcr=--keep-cr ;;
t/t4150-am.sh
+12 -2
@@ -219,7 +219,7 @@ test_expect_success 'am stays in branch' '
219
220 test_expect_success 'am --signoff does not add Signed-off-by: line if already there' '
221 git format-patch --stdout HEAD^ >patch3 &&
222 - sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2," patch3 >patch4 &&
222 + sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2] [foo," patch3 >patch4 &&
223 rm -fr .git/rebase-apply &&
224 git reset --hard &&
225 git checkout HEAD^ &&
@@ -241,7 +241,17 @@ test_expect_success 'am --keep really keeps the subject' '
241 git am --keep patch4 &&
242 ! test -d .git/rebase-apply &&
243 git cat-file commit HEAD >actual &&
244 - grep "Re: Re: Re: \[PATCH 1/5 v2\] third" actual
244 + grep "Re: Re: Re: \[PATCH 1/5 v2\] \[foo\] third" actual
245 +'
246 +
247 +test_expect_failure 'am --keep-non-patch really keeps the non-patch part' '
248 + rm -fr .git/rebase-apply &&
249 + git reset --hard &&
250 + git checkout HEAD^ &&
251 + git am --keep-non-patch patch4 &&
252 + ! test -d .git/rebase-apply &&
253 + git cat-file commit HEAD >actual &&
254 + grep "^\[foo\] third" actual
255 '
256
257 test_expect_success 'am -3 falls back to 3-way merge' '