Skip to content

Commit d3efdd7

Browse files
committed
Merge branch 'mf/format-patch-honor-from-for-cover-letter' into next
"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
2 parents b9a5c15 + a8e8934 commit d3efdd7

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

Documentation/git-format-patch.adoc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,12 @@ e.g., `--rfc='-(WIP)'` results in "PATCH (WIP)".
282282
283283
--from::
284284
--from=<ident>::
285-
Use `ident` in the `From:` header of each commit email. If the
286-
author ident of the commit is not textually identical to the
287-
provided `ident`, place a `From:` header in the body of the
288-
message with the original author. If no `ident` is given, use
289-
the committer ident.
285+
Use `ident` in the `From:` header of each email. In case of a
286+
commit email, if the author ident of the commit is not textually
287+
identical to the provided `ident`, place a `From:` header in the
288+
body of the message with the original author. If no `ident` is
289+
given, or if the option is not passed at all, use the ident of
290+
the current committer.
290291
+
291292
Note that this option is only useful if you are actually sending the
292293
emails and want to identify yourself as the sender, but retain the

builtin/log.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
13311331
int quiet,
13321332
const struct format_config *cfg)
13331333
{
1334-
const char *committer;
1334+
const char *from;
13351335
struct shortlog log;
13361336
struct strbuf sb = STRBUF_INIT;
13371337
int i;
@@ -1344,7 +1344,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
13441344
if (!cmit_fmt_is_mail(rev->commit_format))
13451345
die(_("cover letter needs email format"));
13461346

1347-
committer = git_committer_info(0);
1347+
from = cfg->from ? cfg->from : git_committer_info(0);
13481348

13491349
if (use_separate_file &&
13501350
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,
13671367
pp.date_mode.type = DATE_RFC2822;
13681368
pp.rev = rev;
13691369
pp.encode_email_headers = rev->encode_email_headers;
1370-
pp_user_info(&pp, NULL, &sb, committer, encoding);
1370+
pp_user_info(&pp, NULL, &sb, from, encoding);
13711371
prepare_cover_text(&pp, description_file, branch_name, &sb,
13721372
encoding, need_8bit_cte, cfg);
13731373
fprintf(rev->diffopt.file, "%s\n", sb.buf);

t/t4014-format-patch.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,14 @@ test_expect_success '--from uses committer ident' '
14721472
test_cmp expect patch.head
14731473
'
14741474

1475+
test_expect_success '--from applies to cover letter' '
1476+
test_when_finished "rm -rf patches" &&
1477+
git format-patch -1 --cover-letter --from="Foo Bar <author@example.com>" -o patches &&
1478+
echo "From: Foo Bar <author@example.com>" >expect &&
1479+
grep "^From:" patches/0000-cover-letter.patch >patch.head &&
1480+
test_cmp expect patch.head
1481+
'
1482+
14751483
test_expect_success '--from omits redundant in-body header' '
14761484
git format-patch -1 --stdout --from="A U Thor <author@example.com>" >patch &&
14771485
cat >expect <<-\EOF &&

0 commit comments

Comments
 (0)