Web lists-archives.com

Re: Problem with environment of hook execution when git is run with --work-tree / --git-dir

Michael Sloan <mgsloan@xxxxxxxxx> writes:

> So what's the problem with this choice of environment variables?
> Well, the problem is that if PWD is changed during the execution of
> the script, then GIT_WORK_TREE and GIT_DIR will no longer work
> properly. For example, if the pre-commit hook is
>     #!/bin/sh
>     cd some-dir
>     git status
> This will fail with
>     Not a git repository: '.dotfiles-git'

That is to be expected.  It's up to the script to make them absolute
if it cannot cope with relative paths.

> There is another detail here, which is that when --git-dir /
> --work-tree is not specified, the no GIT_WORK_TREE / GIT_DIR
> environment variable is set.  This means that in this case, changing
> PWD in the hook will work fine as long as the search for .git will
> find the right one.

That also is working as designed.