Reputation: 606
I set up a .mailmap file in my git repository, so now running
git log --format="%aE"
in my local repo correctly maps all email addresses as specified in the .mailmap file. But after I push to my bare repo and run the same command on the server, the output is unchanged (the .mailmap file is ignored). I'm sure this is because bare repositories don't have a working tree, so the log command doesn't see the .mailmap file. Is there some tricky way I can make it work?
The clunky way I can think of is to run:
git show master:.mailmap
and then apply some sort of find and replace operation. Is this the best option?
Upvotes: 4
Views: 605
Reputation: 1323115
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 with Git 2.31 (Q1 2021).
See commit a38cb98 (10 Feb 2021) by Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
-- in commit 9bdccbc, 17 Feb 2021)
mailmap
: only look for.mailmap
in work treeSigned-off-by: Jeff King
When trying to find a
.mailmap
file, we will always look for it in the current directory.
This makes sense in a repository with a working tree, since we'd always go to the toplevel directory at startup.But for a bare repository, it can be confusing.
With an option like
--git-dir
(or$GIT_DIR
in the environment), we don'tchdir
at all, and we'd read.mailmap
from whatever directory you happened to be in before starting Git.(Note that
--git-dir
without specifying a working tree historically means the current directory is the root of the working tree, but most bare repositories will havecore.bare
set these days, meaning they will realize there is no working tree at all).The documentation for gitmailmap(5) says:
If the file `.mailmap` exists at the toplevel of the repository[...]
which likewise reinforces the notion that we are looking in the working tree.
This patch prevents us from looking for such a file when we're in a bare repository.
This does break something that used to work:cd bare.git git cat-file blob HEAD:.mailmap >.mailmap git shortlog
But that was never advertised in the documentation.
And these days we havemailmap.blob
(which defaults toHEAD:.mailmap
) to do the same thing in a much cleaner way.However, there's one more interesting case: we might not have a repository at all! The
git-shortlog
(man) command can be run withgit-log
output fed on its stdin, and it will apply the mailmap.
In that case, it probably does make sense to read.mailmap
from the current directory.
This patch will continue to do so.That leads to one even weirder case: if you run
git-shortlog
to process stdin, the input could be from a different repository entirely.
Should we respect the in-tree.mailmap
then? Probably yes.
Whatever the source of the input, if shortlog is running in a repository, the documentation claims that we'd read the.mailmap
from its top-level (and of course it's reasonably likely that it is from the same repo, and the user just preferred to rungit-log
(man) andgit-shortlog
separately for whatever reason).The included test covers these cases, and we now document the "no repo" case explicitly.
We also add a test that confirms we find a top-level "
.mailmap
" even when we start in a subdirectory of the working tree.
This worked both before and after this commit, but we never tested it explicitly (it works because we alwayschdir
to the top-level of the working tree if there is one).
git shortlog
now includes in its man page:
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.
And since git shortlog
can run outside the repository, do use Git 2.48 (Q1 2025), batch 5: it teaches 'shortlog
' to explicitly use SHA-1 when operating outside a repository.
See commit b330016 (17 Oct 2024) by Wolfgang Müller (wylfen
).
(Merged by Taylor Blau -- ttaylorr
-- in commit 55d12c2, 25 Oct 2024)
builtin/shortlog
: explicitly set hash algo when there is no repoThanks-to: Eric Sunshine
Signed-off-by: Wolfgang Müller
Signed-off-by: Taylor Blau
Whilst
git-shortlog
(1) does not explicitly need any repository information when run without reference to one, it still parses some of its arguments withparse_revision_opt()
which assumes that the hash algorithm is set.
However, in c8aed5e ("repository
: stop setting SHA1 as the default object hash", 2024-05-07, Git v2.46.0-rc0 -- merge listed in batch #9) we stopped setting up a default hash algorithm and instead require commands to set it up explicitly.This was done for most other commands like in ab27490 ("
builtin/diff
: explicitly set hash algo when there is no repo", 2024-05-07, Git v2.46.0-rc0 -- merge listed in batch #9) but was missed for builtin/shortlog, making git-shortlog(1) segfault outside of a repository when given arguments like--author
that trigger a call toparse_revision_opt()
.Fix this for now by explicitly setting the hash algorithm to SHA1.
Upvotes: 0