Skip to content

Commit a078f73

Browse files
bonzinigitster
authored andcommitted
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>
1 parent 452dfbe commit a078f73

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

Documentation/git-am.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ OPTIONS
5757
--no-scissors::
5858
Ignore scissors lines (see linkgit:git-mailinfo[1]).
5959

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+
6071
-q::
6172
--quiet::
6273
Be quiet. Only print error messages.

git-am.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ s,signoff add a Signed-off-by line to the commit message
1717
u,utf8 recode into utf8 (default)
1818
k,keep pass -k flag to git-mailinfo
1919
keep-non-patch pass -b flag to git-mailinfo
20+
m,message-id pass -m flag to git-mailinfo
2021
keep-cr pass --keep-cr flag to git-mailsplit for mbox format
2122
no-keep-cr do not pass --keep-cr flag to git-mailsplit independent of am.keepcr
2223
c,scissors strip everything before a scissors line
@@ -371,13 +372,18 @@ split_patches () {
371372
prec=4
372373
dotest="$GIT_DIR/rebase-apply"
373374
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=
375376
git_apply_opt=
376377
committer_date_is_author_date=
377378
ignore_date=
378379
allow_rerere_autoupdate=
379380
gpg_sign_opt=
380381

382+
if test "$(git config --bool --get am.messageid)" = true
383+
then
384+
messageid=t
385+
fi
386+
381387
if test "$(git config --bool --get am.keepcr)" = true
382388
then
383389
keepcr=t
@@ -400,6 +406,10 @@ it will be removed. Please do not use it anymore."
400406
utf8=t ;; # this is now default
401407
--no-utf8)
402408
utf8= ;;
409+
-m|--message-id)
410+
messageid=t ;;
411+
--no-message-id)
412+
messageid=f ;;
403413
-k|--keep)
404414
keep=t ;;
405415
--keep-non-patch)
@@ -567,6 +577,7 @@ Use \"git am --abort\" to remove it.")"
567577
echo "$sign" >"$dotest/sign"
568578
echo "$utf8" >"$dotest/utf8"
569579
echo "$keep" >"$dotest/keep"
580+
echo "$messageid" >"$dotest/messageid"
570581
echo "$scissors" >"$dotest/scissors"
571582
echo "$no_inbody_headers" >"$dotest/no_inbody_headers"
572583
echo "$GIT_QUIET" >"$dotest/quiet"
@@ -621,6 +632,12 @@ b)
621632
*)
622633
keep= ;;
623634
esac
635+
case "$(cat "$dotest/messageid")" in
636+
t)
637+
messageid=-m ;;
638+
f)
639+
messageid= ;;
640+
esac
624641
case "$(cat "$dotest/scissors")" in
625642
t)
626643
scissors=--scissors ;;
@@ -692,7 +709,7 @@ do
692709
get_author_ident_from_commit "$commit" >"$dotest/author-script"
693710
git diff-tree --root --binary --full-index "$commit" >"$dotest/patch"
694711
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" \
696713
<"$dotest/$msgnum" >"$dotest/info" ||
697714
stop_here $this
698715

t/t4150-am.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ test_expect_success setup '
8585
8686
git format-patch --stdout first >patch1 &&
8787
{
88+
echo "Message-Id: <1226501681-24923-1-git-send-email-bda@mnsspb.ru>" &&
8889
echo "X-Fake-Field: Line One" &&
8990
echo "X-Fake-Field: Line Two" &&
9091
echo "X-Fake-Field: Line Three" &&
@@ -536,4 +537,26 @@ test_expect_success 'am empty-file does not infloop' '
536537
test_i18ncmp expected actual
537538
'
538539

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+
539562
test_done

0 commit comments

Comments
 (0)