Closed denizgenc closed 4 years ago
So why does this happen? Atom and VSCode and Emacs and vim are OK...
tl;dr: I believe the cause of the issue might be that git-gui
doesn't look in the right place for the pre-commit hooks that we install, since we change the git core.hooksPath
variable to something else.
To try and figure out why this happens, I spent this morning looking at the git-gui
source, found here: https://github.com/prati0100/git-gui
The following are a collection of notes I took, roughly following the order of function invocations when a commit is made. Function names link to the lines in which they are found in the source files, for convenience.
do_commit
is what is called to create commits in the first place. It only does one thing, which is that it calls a function named commit_tree
, which can be found in lib/commit.tcl
.Going into lib/commit.tcl
:
commit_tree
has a bunch of code that we're not interested in. Near the end, starting on line 236, we have the pre-commit hook related code.
The first actual line of code sets a variable (fd_ph
) to the output of a function, called githook_read
, called with the string argument pre-commit
. This function is found in git-gui.sh
, again.
Back to git-gui.sh
, looking at the function githook_read
:
hook_name
and then a variable number of arguments following it using the args
keyword.pchook
to the output of gitdir hooks $hook_name
. gitdir
is yet another function in the git-gui.sh
file.
gitdir
will return $_gitdir/hooks/pre-commit
.What is $_gitdir
?
$_gitdir
is assigned to $env(GIT_DIR)
during "repository setup". The env variable is built in and represents the environment variables on the machine, and the GIT_DIR
environment variable represents the .git
found in a repo.
This might be the cause of the issue. It's probably the case that when githook_read
executes the githooks, it's looking in the wrong place for the hooks.
As part of the installation script, gds-pre-commit changes the core.hooksPath
variable for git, which changes where git searches for hooks. It doesn't seem that git-gui uses this variable, from what I can tell.
Long story long - gitdir
:
This function takes a variable number of arguments, since its only argument is args
.
What this function does is check if args
is equal to an empty string. If so, it simply returns the existing _gitdir
global variable.
If there are arguments passed to it, it uses eval
to essentially create a filesystem path, starting from _gitdir
, with each successive argument in $args
representing the next folder.
(An explanation of this can be found in the eval
documentation - see specifically the paragraph and example following on from "Note that in the most common case...")
In our case, gitdir
is called in githook_read
with the arguments hooks $hook_name
, where $hook_name
was set by commit_tree
to be pre-commit
. ↩
Apologies for reviving an extremely dead thread @denizgenc - it is nice to see that it's back to the CS for me when I have an issue though 🤣
Did a fix for git gui
and git hooks get implemented? I can see this issue was closed and your notes are very thorough, but I don't yet see how I can install a git hook and have it run via a git gui
commit...? Unless I've mis-read something..
From what I understand, the only way would be to install the hook in the traditional .git/hooks
folder, rather than use:
git config core.hooksPath <our-hooks-dir>
We no longer support this, please see the readme, which states:
We used to vendor our own bundle of pre-commit and detect-secrets. This was too brittle for us to support, we now recommend installing the off-the-shelf tools
I'd recommend asking this question on the pre-commit framework forums. Good luck!
No worries @0atman - Worth the punt to see if the fix was easy to remember!
Can't commit via regular
git
:But you can commit via
git gui
:(note the "secret access key ID" is simply a random 40 character string. Any resemblance to existing or future key IDs is purely coincidental)