git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: I've noticed the command `git --git-dir=<path> shortlog`

From
Jeff King <peff@peff.net>
Date
Feb 5, 2021, 16:57 UTC
Message-ID
<YB148VZJqKIPC8P2@coredump.intra.peff.net>
In-Reply-To
<CAD6AYr-BD08FcbnVfHpOUt7ZwFH0PgoATgyegKnBQ3GOe9isdA@mail.gmail.com>
On Mon, Feb 01, 2021 at 11:05:13AM +0800, SURA wrote:
Show 11 quoted lines
> $ git clone --bare https://github.com/gitlabhq/gitlabhq.git
> $ git clone https://gitlab.com/gitlab-org/gitaly.git
> 
> $ git --git-dir=./gitlabhq.git shortlog --summary --email --numbered
> --committer HEAD --end-of-options | wc -l
> > 2592
> [...]
> $ cd gitaly
> $ git --git-dir=../gitlabhq.git shortlog --summary --email --numbered
> --committer HEAD --end-of-options | wc -l
> > 2587

I think what's happening is that the second command is using the .mailmap file found in the working tree of the gitaly repository.

If the first checkout were non-bare, I would say that is the right behavior (because --git-dir without otherwise specifying the working tree means that the current directory becomes the working tree, and we read ".mailmap" out of the top of the working tree). But because it was cloned with "--bare", it should have the core.bare config set, and will think there is no working tree at all.

So I do think there is a bug, which is: Git should avoid looking for ".mailmap" in the current directory if we do not have a working tree. I.e., something like:

diff --git a/mailmap.c b/mailmap.c
index eb77c6e77c..3ea35a2289 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -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 (!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);

It's possible somebody is relying on this in order to read ".mailmap" in
a bare repository, but it seems rather unlikely. And the documentation
says "If the file .mailmap exists at the toplevel of the repository",
which I think pretty clearly means the top of the working tree.

-Peff
Previous: SURANext: Bryan Turner
Message 2 of 12 in “I've noticed the command `git --git-dir=<path> shortlog`”
  1. SURAFeb 1, 2021
  2. Jeff KingFeb 5, 2021
  3. Bryan TurnerFeb 5, 2021
  4. mailmap: only look for .mailmap in work treeJeff King, Feb 9, 2021
  5. Eric SunshineFeb 9, 2021
  6. Junio C HamanoFeb 9, 2021
  7. Jeff KingFeb 10, 2021
  8. Junio C HamanoFeb 9, 2021
  9. Jeff KingFeb 10, 2021
  10. Junio C HamanoFeb 10, 2021
  11. Jeff KingFeb 10, 2021
  12. Jeff KingFeb 10, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.