Skip to content

Commit 87b24a4

Browse files
committed
Merge branch 'ap/commit-author-mailmap' into maint
* ap/commit-author-mailmap: commit: search author pattern against mailmap
2 parents f8a3fd2 + ea16794 commit 87b24a4

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
@@ -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)