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
Gabriel Nützi <gnuetzi@gmail.com>
Date
Sep 20, 2024, 10:42 UTC
Message-ID
<6102c928cb2f2e9afbc93e89737556c9d66b68eb.camel@gmail.com>
In-Reply-To
<0084cc18b6d90ba14849a7f788939f4a1d0d61c9.camel@gmail.com>

The same happens with `git rev-parse --git-comon-dir` and `git config a.a "hello"` (which might be ok, since the config file is not yet setup at this point...)

On Fri, 2024-09-20 at 12:07 +0200, Gabriel Nützi wrote:
Show 76 quoted lines
> Thank you for filling out a Git bug report!  
> Please answer the following questions to help us understand your issue.
> 
> What did you do before the bug happened? (Steps to reproduce your  
> issue)
> 
> I set `git config --global core.hooksPath ~/myhooks` and placed a  
> `reference-transaction` hook in `~/myhooks/reference-transaction`  
> with the content:
> 
> ```shell  
> #!/usr/bin/env bash
> 
> set -e  
> echo "$GIT_DIR"  
> git rev-parse --absolute-git-dir  
> ```
> 
> then I ran
> 
> ```shell  
> mkdir ~/test && cd test  
> git init  
> ```
> 
> What did you expect to happen? (Expected behavior)
> 
> The Git repo `~/test` should have been initialized (and the hook  
> `reference-transaction` would have passed successfully.)
> 
> 
> What happened instead? (Actual behavior)
> 
> The hook `reference-transaction` crashes since `git rev-parse --  
> absolute-git-dir` with  
> ```  
> failed: not a git repository: ...  
> ```
> 
> What's different between what you expected and what actually happened?
> 
> The documentation says that `git rev-parse --absolute-git-dir` inside  
> the `reference-transaction` hooks read "$GIT_DIR" if defined (which is  
> defined!) so the `reference-transaction` should have passed. I assume  
> that hooks should be executed on properly initialized repositories,  
> right? Therefore I do not understand why `git rev-parse --absolute-git-  
> dir` fails -> Bug?
> 
> Anything else you want to add:
> 
> This came up with `Githooks` hooks manager  
> [https://github.com/gabyx/Githooks](https://github.com/gabyx/Githooks) where we use this command  
> to locate the current Git dir...
> 
> Please review the rest of the bug report below.  
> You can delete any lines you don't wish to share.
> 
> 
> [System Info]  
> git version:  
> git version 2.46.0  
> cpu: x86_64  
> no commit associated with this build  
> sizeof-long: 8  
> sizeof-size_t: 8  
> shell-path: /nix/store/izpf49b74i15pcr9708s3xdwyqs4jxwl-bash-  
> 5.2p32/bin/bash  
> libcurl: 8.9.1  
> OpenSSL: OpenSSL 3.0.14 4 Jun 2024  
> zlib: 1.3.1  
> uname: Linux 6.6.45 #1-NixOS SMP PREEMPT_DYNAMIC Sun Aug 11 10:47:28  
> UTC 2024 x86_64  
> compiler info: gnuc: 13.3  
> libc info: glibc: 2.39  
> $SHELL (typically, interactive shell): /run/current-system/sw/bin/zsh
> 
Previous: Gabriel NütziNext: Patrick Steinhardt
Message 2 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.