aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-02-27 15:11:53 -0800
committerJunio C Hamano <gitster@pobox.com>2026-02-27 15:11:54 -0800
commitd64a20a1b185082fa6fc83b339f922f95fa45bdc (patch)
tree87d874fcd741669fe631aa95c980cd7a9b5e6ee0
parentc0d0b8daedd336677ed30bfb6bb7cdc6c47a468a (diff)
parenta8e89346a7731cb3104010f322c65e2a0c922618 (diff)
downloadgit-d64a20a1b185082fa6fc83b339f922f95fa45bdc.tar.xz
Merge branch 'mf/format-patch-honor-from-for-cover-letter'
"git format-patch --from=<me>" did not honor the command line option when writing out the cover letter, which has been corrected. * mf/format-patch-honor-from-for-cover-letter: format-patch: fix From header in cover letter
-rw-r--r--Documentation/git-format-patch.adoc11
-rw-r--r--builtin/log.c6
-rwxr-xr-xt/t4014-format-patch.sh8
3 files changed, 17 insertions, 8 deletions
diff --git a/Documentation/git-format-patch.adoc b/Documentation/git-format-patch.adoc
index bac9b818f3..36146006fa 100644
--- a/Documentation/git-format-patch.adoc
+++ b/Documentation/git-format-patch.adoc
@@ -282,11 +282,12 @@ e.g., `--rfc='-(WIP)'` results in "PATCH (WIP)".
--from::
--from=<ident>::
- Use `ident` in the `From:` header of each commit email. If the
- author ident of the commit is not textually identical to the
- provided `ident`, place a `From:` header in the body of the
- message with the original author. If no `ident` is given, use
- the committer ident.
+ Use `ident` in the `From:` header of each email. In case of a
+ commit email, if the author ident of the commit is not textually
+ identical to the provided `ident`, place a `From:` header in the
+ body of the message with the original author. If no `ident` is
+ given, or if the option is not passed at all, use the ident of
+ the current committer.
+
Note that this option is only useful if you are actually sending the
emails and want to identify yourself as the sender, but retain the
diff --git a/builtin/log.c b/builtin/log.c
index 8ab6d3a943..3c76ee5169 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1331,7 +1331,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;
@@ -1344,7 +1344,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))
@@ -1367,7 +1367,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..2135b65cee 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -1472,6 +1472,14 @@ test_expect_success '--from uses committer ident' '
test_cmp expect patch.head
'
+test_expect_success '--from applies to cover letter' '
+ test_when_finished "rm -rf patches" &&
+ git format-patch -1 --cover-letter --from="Foo Bar <author@example.com>" -o patches &&
+ echo "From: Foo Bar <author@example.com>" >expect &&
+ grep "^From:" patches/0000-cover-letter.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 &&