threads / discuss / 50854

GIT_DIR not passed to script if hooksPath is set

Subject: GIT_DIR not passed to script if hooksPath is set

## tl;dr

One message between Apr 1, 2019 and Apr 1, 2019.

replies: 0people: 1as markdown or json

Jan Ziak· Apr 1, 2019, 14:14 UTC · lore
Hello

If git commit executes .git/hooks/post-commit it will pass GIT_DIR env variable to the script. However, if hooksPath is set in $HOME/.gitconfig, git commit executes hooksPath/post-commit without passing GIT_DIR env variable to the script.

Expected behavior: GIT_DIR is passed to hooksPath/post-commit Actual behavior: GIT_DIR isn't passed to hooksPath/post-commit

Please run the attached shell script in an empty directory to reproduce this issue. The script is using strace to determine whether GIT_DIR is passed to the hook script. The script will run "git gui": the user is expected to simply commit changes from the gui and then close the gui for the script to finish. The script is exploiting the fact that (currently) command-line "git commit" and graphical "git gui" commit are invoking different commit hooks.

Script output:
  - !!! missing GIT_DIR in git-commit.strace
  - execve(".git/hooks/post-commit", [... "GIT_DIR=.git" ...
$ cat ~/.gitconfig
[core]
    hooksPath = /home/atom/dev/git-hooks
git version 2.21.0

Sincerely Jan

← back to recent threads