git-am: add --message-id/--no-message-id

Parse the option and pass it directly to git-mailinfo. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Paolo Bonzini committed Nov 25, 2014 at 15:00 UTC a078f7321b02eb945b63804a80b0ba52c9da4ed3
3 files changed +53 -2
Documentation/git-am.txt
+11
@@ -57,6 +57,17 @@ OPTIONS
57 --no-scissors::
58 Ignore scissors lines (see linkgit:git-mailinfo[1]).
59
60 +-m::
61 +--message-id::
62 + Pass the `-m` flag to 'git mailinfo' (see linkgit:git-mailinfo[1]),
63 + so that the Message-ID header is added to the commit message.
64 + The `am.messageid` configuration variable can be used to specify
65 + the default behaviour.
66 +
67 +--no-message-id::
68 + Do not add the Message-ID header to the commit message.
69 + `no-message-id` is useful to override `am.messageid`.
70 +
71 -q::
72 --quiet::
73 Be quiet. Only print error messages.
git-am.sh
+19 -2
@@ -17,6 +17,7 @@ s,signoff add a Signed-off-by line to the commit message
17 u,utf8 recode into utf8 (default)
18 k,keep pass -k flag to git-mailinfo
19 keep-non-patch pass -b flag to git-mailinfo
20 +m,message-id pass -m flag to git-mailinfo
21 keep-cr pass --keep-cr flag to git-mailsplit for mbox format
22 no-keep-cr do not pass --keep-cr flag to git-mailsplit independent of am.keepcr
23 c,scissors strip everything before a scissors line
@@ -371,13 +372,18 @@ split_patches () {
372 prec=4
373 dotest="$GIT_DIR/rebase-apply"
374 sign= utf8=t keep= keepcr= skip= interactive= resolved= rebasing= abort=
374 -resolvemsg= resume= scissors= no_inbody_headers=
375 +messageid= resolvemsg= resume= scissors= no_inbody_headers=
376 git_apply_opt=
377 committer_date_is_author_date=
378 ignore_date=
379 allow_rerere_autoupdate=
380 gpg_sign_opt=
381
382 +if test "$(git config --bool --get am.messageid)" = true
383 +then
384 + messageid=t
385 +fi
386 +
387 if test "$(git config --bool --get am.keepcr)" = true
388 then
389 keepcr=t
@@ -400,6 +406,10 @@ it will be removed. Please do not use it anymore."
406 utf8=t ;; # this is now default
407 --no-utf8)
408 utf8= ;;
409 + -m|--message-id)
410 + messageid=t ;;
411 + --no-message-id)
412 + messageid=f ;;
413 -k|--keep)
414 keep=t ;;
415 --keep-non-patch)
@@ -567,6 +577,7 @@ Use \"git am --abort\" to remove it.")"
577 echo "$sign" >"$dotest/sign"
578 echo "$utf8" >"$dotest/utf8"
579 echo "$keep" >"$dotest/keep"
580 + echo "$messageid" >"$dotest/messageid"
581 echo "$scissors" >"$dotest/scissors"
582 echo "$no_inbody_headers" >"$dotest/no_inbody_headers"
583 echo "$GIT_QUIET" >"$dotest/quiet"
@@ -621,6 +632,12 @@ b)
632 *)
633 keep= ;;
634 esac
635 +case "$(cat "$dotest/messageid")" in
636 +t)
637 + messageid=-m ;;
638 +f)
639 + messageid= ;;
640 +esac
641 case "$(cat "$dotest/scissors")" in
642 t)
643 scissors=--scissors ;;
@@ -692,7 +709,7 @@ do
709 get_author_ident_from_commit "$commit" >"$dotest/author-script"
710 git diff-tree --root --binary --full-index "$commit" >"$dotest/patch"
711 else
695 - git mailinfo $keep $no_inbody_headers $scissors $utf8 "$dotest/msg" "$dotest/patch" \
712 + git mailinfo $keep $no_inbody_headers $messageid $scissors $utf8 "$dotest/msg" "$dotest/patch" \
713 <"$dotest/$msgnum" >"$dotest/info" ||
714 stop_here $this
715
t/t4150-am.sh
+23
@@ -85,6 +85,7 @@ test_expect_success setup '
85
86 git format-patch --stdout first >patch1 &&
87 {
88 + echo "Message-Id: <1226501681-24923-1-git-send-email-bda@mnsspb.ru>" &&
89 echo "X-Fake-Field: Line One" &&
90 echo "X-Fake-Field: Line Two" &&
91 echo "X-Fake-Field: Line Three" &&
@@ -536,4 +537,26 @@ test_expect_success 'am empty-file does not infloop' '
537 test_i18ncmp expected actual
538 '
539
540 +test_expect_success 'am --message-id really adds the message id' '
541 + rm -fr .git/rebase-apply &&
542 + git reset --hard &&
543 + git checkout HEAD^ &&
544 + git am --message-id patch1.eml &&
545 + test_path_is_missing .git/rebase-apply &&
546 + git cat-file commit HEAD | tail -n1 >actual &&
547 + grep Message-Id patch1.eml >expected &&
548 + test_cmp expected actual
549 +'
550 +
551 +test_expect_success 'am --message-id -s signs off after the message id' '
552 + rm -fr .git/rebase-apply &&
553 + git reset --hard &&
554 + git checkout HEAD^ &&
555 + git am -s --message-id patch1.eml &&
556 + test_path_is_missing .git/rebase-apply &&
557 + git cat-file commit HEAD | tail -n2 | head -n1 >actual &&
558 + grep Message-Id patch1.eml >expected &&
559 + test_cmp expected actual
560 +'
561 +
562 test_done