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
maint
Junio C Hamano 2021-02-17 17:21:41 -08:00
commit 9bdccbcda7
3 changed files with 49 additions and 1 deletions

View File

@ -113,6 +113,10 @@ MAPPING AUTHORS

See linkgit:gitmailmap[5].

Note that if `git shortlog` is run outside of a repository (to process
log contents on standard input), it will look for a `.mailmap` file in
the current directory.

GIT
---
Part of the linkgit:git[1] suite

View File

@ -225,7 +225,8 @@ int read_mailmap(struct string_list *map)
if (!git_mailmap_blob && is_bare_repository())
git_mailmap_blob = "HEAD:.mailmap";

err |= read_mailmap_file(map, ".mailmap");
if (!startup_info->have_repository || !is_bare_repository())
err |= read_mailmap_file(map, ".mailmap");
if (startup_info->have_repository)
err |= read_mailmap_blob(map, git_mailmap_blob);
err |= read_mailmap_file(map, git_mailmap_file);

View File

@ -889,4 +889,47 @@ test_expect_success 'empty syntax: setup' '
test_cmp expect actual
'

test_expect_success 'set up mailmap location tests' '
git init --bare loc-bare &&
git --git-dir=loc-bare --work-tree=. commit \
--allow-empty -m foo --author="Orig <orig@example.com>" &&
echo "New <new@example.com> <orig@example.com>" >loc-bare/.mailmap
'

test_expect_success 'bare repo with --work-tree finds mailmap at top-level' '
git -C loc-bare --work-tree=. log -1 --format=%aE >actual &&
echo new@example.com >expect &&
test_cmp expect actual
'

test_expect_success 'bare repo does not look in current directory' '
git -C loc-bare log -1 --format=%aE >actual &&
echo orig@example.com >expect &&
test_cmp expect actual
'

test_expect_success 'non-git shortlog respects mailmap in current dir' '
git --git-dir=loc-bare log -1 >input &&
nongit cp "$TRASH_DIRECTORY/loc-bare/.mailmap" . &&
nongit git shortlog -s <input >actual &&
echo " 1 New" >expect &&
test_cmp expect actual
'

test_expect_success 'shortlog on stdin respects mailmap from repo' '
cp loc-bare/.mailmap . &&
git shortlog -s <input >actual &&
echo " 1 New" >expect &&
test_cmp expect actual
'

test_expect_success 'find top-level mailmap from subdir' '
git clone loc-bare loc-wt &&
cp loc-bare/.mailmap loc-wt &&
mkdir loc-wt/subdir &&
git -C loc-wt/subdir log -1 --format=%aE >actual &&
echo new@example.com >expect &&
test_cmp expect actual
'

test_done