Skip to content

Commit 5aebc9a

Browse files
committed
Merge branch 'ap/commit-author-mailmap'
"git commit --author=$name", when $name is not in the canonical "A. U. Thor <[email protected]>" format, looks for a matching name from existing history, but did not consult mailmap to grab the preferred author name. * ap/commit-author-mailmap: commit: search author pattern against mailmap
2 parents b8f2311 + ea16794 commit 5aebc9a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

builtin/commit.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "column.h"
3131
#include "sequencer.h"
3232
#include "notes-utils.h"
33+
#include "mailmap.h"
3334

3435
static const char * const builtin_commit_usage[] = {
3536
N_("git commit [options] [--] <pathspec>..."),
@@ -933,6 +934,7 @@ static const char *find_author_by_nickname(const char *name)
933934
struct rev_info revs;
934935
struct commit *commit;
935936
struct strbuf buf = STRBUF_INIT;
937+
struct string_list mailmap = STRING_LIST_INIT_NODUP;
936938
const char *av[20];
937939
int ac = 0;
938940

@@ -943,13 +945,17 @@ static const char *find_author_by_nickname(const char *name)
943945
av[++ac] = buf.buf;
944946
av[++ac] = NULL;
945947
setup_revisions(ac, av, &revs, NULL);
948+
revs.mailmap = &mailmap;
949+
read_mailmap(revs.mailmap, NULL);
950+
946951
prepare_revision_walk(&revs);
947952
commit = get_revision(&revs);
948953
if (commit) {
949954
struct pretty_print_context ctx = {0};
950955
ctx.date_mode = DATE_NORMAL;
951956
strbuf_release(&buf);
952-
format_commit_message(commit, "%an <%ae>", &buf, &ctx);
957+
format_commit_message(commit, "%aN <%aE>", &buf, &ctx);
958+
clear_mailmap(&mailmap);
953959
return strbuf_detach(&buf, NULL);
954960
}
955961
die(_("No existing author found with '%s'"), name);

t/t4203-mailmap.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,15 @@ test_expect_success 'Blame output (complex mapping)' '
484484
test_cmp expect actual.fuzz
485485
'
486486

487+
cat >expect <<\EOF
488+
Some Dude <[email protected]>
489+
EOF
490+
491+
test_expect_success 'commit --author honors mailmap' '
492+
test_must_fail git commit --author "nick" --allow-empty -meight &&
493+
git commit --author "Some Dude" --allow-empty -meight &&
494+
git show --pretty=format:"%an <%ae>%n" >actual &&
495+
test_cmp expect actual
496+
'
497+
487498
test_done

0 commit comments

Comments
 (0)