Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$GIT_DIR no longer set in pre-commit hooks

Tags:

git

githooks

Using $GIT_DIR in pre-commit hook would return the location of the .git directory. Even if it had not been explicitly set to anything, using it in the pre-commit hook would still return you the location. After an update, moving to Git 2.18 this appears to no longer be the case and the behavior of my pre-commit hooks are different and not working as intended. Any idea how to fix this?

like image 698
Dave Avatar asked Aug 26 '26 23:08

Dave


1 Answers

Some really detailed information on this can be found here

https://public-inbox.org/git/[email protected]/t/

I will attempt to paraphrase to the best of my ability for the sake of question quality.

Using $GIT_DIR, when it has not been explicity set, in pre-commit hooks did work pre Git 2.18, however this was an unexpected side effect and not intended behavior.

A change in GIT 2.18 caused this to stop working. In the link a contributor mentions that the correct way to get the location of the .git directory in a pre-commit hook (or any hook for that matter) is to use this git command

git rev-parse --git-dir

They may, in future, produce a patch to return the behavior to how it was pre 2.18 but I would recommend not relying on undocumented and unintended behavior

like image 170
Dave Avatar answered Aug 28 '26 16:08

Dave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!