"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. This has been the case ever since
"--from" was introduced in
a9080475 (teach format-patch to place
other authors into in-body "From", 2013-07-03).
Teach the make_cover_letter() function to honor the option, instead of
always using the current committer identity. Change variable name from
"committer" to "from" to better reflect the purpose of the variable.
Signed-off-by: Mirko Faina <mroik@delayed.space>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
--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
int quiet,
const struct format_config *cfg)
{
- const char *committer;
+ const char *from;
struct shortlog log;
struct strbuf sb = STRBUF_INIT;
int i;
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))
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);
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 &&