From: Mirko Faina <mroik@delayed.space>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Mirko Faina <mroik@delayed.space>
Subject: [PATCH v2] format-patch: fix From header in cover letter
Date: Mon, 16 Feb 2026 16:27:30 +0100 [thread overview]
Message-ID: <20260216152730.37478-1-mroik@delayed.space> (raw)
In-Reply-To: <aZAMr6XOwKkTa55q@exploit>
"git format-patch" takes "--from=<user ident>" command line option and
uses the given ident for patch e-mails, but this is not applied to the
cover letter, the option is ignored and the committer ident of the
current user is used.
Teach the make_cover_letter() function to honor the option, instead of
always using the current committer identity.
Signed-off-by: Mirko Faina <mroik@delayed.space>
---
I'm sorry about the poor quality of the previous commit message, I
realise it did a poor job at explaining what the patch did.
I've applied the changes you suggested and wrote the test.
Thank you for the review.
builtin/log.c | 6 +++---
t/t4014-format-patch.sh | 12 ++++++++++++
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index d43ca693bf..42648dda54 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1332,7 +1332,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
int quiet,
const struct format_config *cfg)
{
- const char *committer;
+ const char *from;
struct shortlog log;
struct strbuf sb = STRBUF_INIT;
int i;
@@ -1345,7 +1345,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
if (!cmit_fmt_is_mail(rev->commit_format))
die(_("cover letter needs email format"));
- committer = git_committer_info(0);
+ from = cfg->from ? cfg->from : git_committer_info(0);
if (use_separate_file &&
open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet))
@@ -1368,7 +1368,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
pp.date_mode.type = DATE_RFC2822;
pp.rev = rev;
pp.encode_email_headers = rev->encode_email_headers;
- pp_user_info(&pp, NULL, &sb, committer, encoding);
+ pp_user_info(&pp, NULL, &sb, from, encoding);
prepare_cover_text(&pp, description_file, branch_name, &sb,
encoding, need_8bit_cte, cfg);
fprintf(rev->diffopt.file, "%s\n", sb.buf);
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 21d6d0cd9e..cb04a9c47b 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -1472,6 +1472,18 @@ test_expect_success '--from uses committer ident' '
test_cmp expect patch.head
'
+test_expect_success '--from applies to cover letter' '
+ echo "This is a test text" >file_to_commit &&
+ git format-patch -1 --stdout --cover-letter --from="Foo Bar <author@example.com>" >patch &&
+ cat >expect <<-\EOF &&
+ From: Foo Bar <author@example.com>
+ From: Foo Bar <author@example.com>
+ From: A U Thor <author@example.com>
+ EOF
+ sed -ne "/^From:/p; /^[[:space:]]$/d" patch >patch.head &&
+ test_cmp expect patch.head
+'
+
test_expect_success '--from omits redundant in-body header' '
git format-patch -1 --stdout --from="A U Thor <author@example.com>" >patch &&
cat >expect <<-\EOF &&
--
2.53.0
next prev parent reply other threads:[~2026-02-16 15:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-14 5:49 [PATCH] format-patch: fix from header in cover letter Mirko Faina
2026-02-16 11:01 ` Junio C Hamano
2026-02-16 15:27 ` Mirko Faina [this message]
2026-02-17 6:22 ` [PATCH v2] format-patch: fix From " Patrick Steinhardt
2026-02-17 6:34 ` Jeff King
2026-02-17 13:21 ` D. Ben Knoble
2026-02-19 11:29 ` Jeff King
2026-02-19 12:03 ` Mirko Faina
2026-02-19 13:43 ` D. Ben Knoble
2026-02-17 15:22 ` Junio C Hamano
2026-02-19 11:43 ` Jeff King
2026-02-20 18:11 ` Junio C Hamano
2026-02-17 22:04 ` [PATCH] " Mroik
2026-02-17 22:13 ` Mirko Faina
2026-02-17 22:43 ` Junio C Hamano
2026-02-17 22:41 ` Junio C Hamano
2026-02-17 23:25 ` [PATCH v4] " Mirko Faina
-- strict thread matches above, loose matches on Subject: below --
2026-02-17 21:30 [PATCH v2] " Mirko Faina
2026-02-17 21:41 Mirko Faina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260216152730.37478-1-mroik@delayed.space \
--to=mroik@delayed.space \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox