Skip to content

Commit ea16794

Browse files
apelissegitster
authored andcommitted
commit: search author pattern against mailmap
"git commit --author=$name" sets the author to one whose name matches the given string from existing commits, when $name is not in the "Name <e-mail>" format. However, it does not honor the mailmap to use the canonical name for the author found this way. Fix it by telling the logic to find a matching existing author to honor the mailmap, and use the name and email after applying the mailmap. Signed-off-by: Antoine Pelisse <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d8beaa commit ea16794

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>..."),
@@ -935,6 +936,7 @@ static const char *find_author_by_nickname(const char *name)
935936
struct rev_info revs;
936937
struct commit *commit;
937938
struct strbuf buf = STRBUF_INIT;
939+
struct string_list mailmap = STRING_LIST_INIT_NODUP;
938940
const char *av[20];
939941
int ac = 0;
940942

@@ -945,13 +947,17 @@ static const char *find_author_by_nickname(const char *name)
945947
av[++ac] = buf.buf;
946948
av[++ac] = NULL;
947949
setup_revisions(ac, av, &revs, NULL);
950+
revs.mailmap = &mailmap;
951+
read_mailmap(revs.mailmap, NULL);
952+
948953
prepare_revision_walk(&revs);
949954
commit = get_revision(&revs);
950955
if (commit) {
951956
struct pretty_print_context ctx = {0};
952957
ctx.date_mode = DATE_NORMAL;
953958
strbuf_release(&buf);
954-
format_commit_message(commit, "%an <%ae>", &buf, &ctx);
959+
format_commit_message(commit, "%aN <%aE>", &buf, &ctx);
960+
clear_mailmap(&mailmap);
955961
return strbuf_detach(&buf, NULL);
956962
}
957963
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
@@ -470,4 +470,15 @@ test_expect_success 'Blame output (complex mapping)' '
470470
test_cmp expect actual.fuzz
471471
'
472472

473+
cat >expect <<\EOF
474+
Some Dude <[email protected]>
475+
EOF
476+
477+
test_expect_success 'commit --author honors mailmap' '
478+
test_must_fail git commit --author "nick" --allow-empty -meight &&
479+
git commit --author "Some Dude" --allow-empty -meight &&
480+
git show --pretty=format:"%an <%ae>%n" >actual &&
481+
test_cmp expect actual
482+
'
483+
473484
test_done

0 commit comments

Comments
 (0)