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

Re: Bug: `git init` with hook `reference-transaction` running `git rev-parse --git-dir` fails

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 7, 2024, 11:24 UTC
Message-ID
<ZwPEwL-fKHBkUOcm@pks.im>
In-Reply-To
<a8807b44026458097267932f429ef61d5b77aa4c.camel@gmail.com>
On Mon, Oct 07, 2024 at 01:02:56PM +0200, Gabriel Nützi wrote:
> Ah, jeah thats true:
> 
> The command in question which is `git rev-parse --git-dir` to find the actual GIT_DIR is actually the issue here:
> It relies on having a proper HEAD despite the docs saying it only reports GIT_DIR if set etc...

That's not quite true. The second paragraph for the `--git-dir` option in git-rev-parse(1) has this to say:

    If $GIT_DIR is not defined and the current directory is not detected to lie in a Git
    repository or work tree print a message to stderr and exit with nonzero status.

But in our case you're correct: `$GIT_DIR` _is_ defined during hook execution. So in theory, if git-rev-parse(1) behaved exactly as documented, it shouldn't even care whether or not it is executing in a repository.

> Could we maybe make these commands more agnostic? 

So this could indeed be a viable fix, but I guess we'd rather play whack-a-mole because other Git commands that one may want to execute in this repository would also be broken.

> Making an empty HEAD probably directly also resolves these commands to work correctly.

So agreed, creating a stub HEAD is the most sensible option we have. I'd like to wait a bit for more feedback from other contributors before we do so though.

Patrick
Previous: Gabriel NütziNext: Junio C Hamano
Message 7 of 14 in “Bug: `git init` with hook `reference-transaction` running `git rev-parse --git-dir` fails”
  1. Gabriel NütziSep 20, 2024
  2. Gabriel NütziSep 20, 2024
  3. Patrick SteinhardtOct 7, 2024
  4. Gabriel NütziOct 7, 2024
  5. Patrick SteinhardtOct 7, 2024
  6. Gabriel NütziOct 7, 2024
  7. Patrick SteinhardtOct 7, 2024
  8. Junio C HamanoOct 7, 2024
  9. Patrick SteinhardtOct 9, 2024
  10. Karthik NayakOct 9, 2024
  11. Gabriel NütziOct 9, 2024
  12. Patrick SteinhardtOct 9, 2024
  13. Junio C HamanoOct 9, 2024
  14. Patrick SteinhardtOct 14, 2024

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.