Skip to content

Commit 9bdccbc

Browse files
committed
Merge branch 'jk/mailmap-only-at-root'
The .mailmap is documented to be read only from the root level of a working tree, but a stray file in a bare repository also was read by accident, which has been corrected. * jk/mailmap-only-at-root: mailmap: only look for .mailmap in work tree
2 parents f712632 + a38cb98 commit 9bdccbc

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

Documentation/git-shortlog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ MAPPING AUTHORS
113113

114114
See linkgit:gitmailmap[5].
115115

116+
Note that if `git shortlog` is run outside of a repository (to process
117+
log contents on standard input), it will look for a `.mailmap` file in
118+
the current directory.
119+
116120
GIT
117121
---
118122
Part of the linkgit:git[1] suite

mailmap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ int read_mailmap(struct string_list *map)
225225
if (!git_mailmap_blob && is_bare_repository())
226226
git_mailmap_blob = "HEAD:.mailmap";
227227

228-
err |= read_mailmap_file(map, ".mailmap");
228+
if (!startup_info->have_repository || !is_bare_repository())
229+
err |= read_mailmap_file(map, ".mailmap");
229230
if (startup_info->have_repository)
230231
err |= read_mailmap_blob(map, git_mailmap_blob);
231232
err |= read_mailmap_file(map, git_mailmap_file);

t/t4203-mailmap.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,4 +889,47 @@ test_expect_success 'empty syntax: setup' '
889889
test_cmp expect actual
890890
'
891891

892+
test_expect_success 'set up mailmap location tests' '
893+
git init --bare loc-bare &&
894+
git --git-dir=loc-bare --work-tree=. commit \
895+
--allow-empty -m foo --author="Orig <[email protected]>" &&
896+
echo "New <[email protected]> <[email protected]>" >loc-bare/.mailmap
897+
'
898+
899+
test_expect_success 'bare repo with --work-tree finds mailmap at top-level' '
900+
git -C loc-bare --work-tree=. log -1 --format=%aE >actual &&
901+
echo [email protected] >expect &&
902+
test_cmp expect actual
903+
'
904+
905+
test_expect_success 'bare repo does not look in current directory' '
906+
git -C loc-bare log -1 --format=%aE >actual &&
907+
echo [email protected] >expect &&
908+
test_cmp expect actual
909+
'
910+
911+
test_expect_success 'non-git shortlog respects mailmap in current dir' '
912+
git --git-dir=loc-bare log -1 >input &&
913+
nongit cp "$TRASH_DIRECTORY/loc-bare/.mailmap" . &&
914+
nongit git shortlog -s <input >actual &&
915+
echo " 1 New" >expect &&
916+
test_cmp expect actual
917+
'
918+
919+
test_expect_success 'shortlog on stdin respects mailmap from repo' '
920+
cp loc-bare/.mailmap . &&
921+
git shortlog -s <input >actual &&
922+
echo " 1 New" >expect &&
923+
test_cmp expect actual
924+
'
925+
926+
test_expect_success 'find top-level mailmap from subdir' '
927+
git clone loc-bare loc-wt &&
928+
cp loc-bare/.mailmap loc-wt &&
929+
mkdir loc-wt/subdir &&
930+
git -C loc-wt/subdir log -1 --format=%aE >actual &&
931+
echo [email protected] >expect &&
932+
test_cmp expect actual
933+
'
934+
892935
test_done

0 commit comments

Comments
 (0)