GIT_DIR=. for hooks?

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

GIT_DIR=. for hooks?

From: Michael J Gruber <hidden>
Date: 2016-06-15 22:47:58

Hi there,

as it seems hooks (at least post-receive) are called with a $PWD in the
.git dir and GIT_DIR=. exported.

Now, that leads to problems when, say, diffing between the index and the
worktree ("Don't do that!", I know). Without cd'ing around, the worktree
is not found, and after "cd ..", the git-dir is not found.

I can unset GIT_DIR or set WORK_TREE, of course, but I'm wondering
whether GIT_DIR=. is a sane setting at all: a git-dir in $PWD is always
found, and when cd'ing away that setting does not help either.

Michael

Re: GIT_DIR=. for hooks?

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:47:58

Michael J Gruber [off-list ref] writes:
I can unset GIT_DIR or set WORK_TREE, of course,
That is not just an acceptable but _the_ right way to write hooks that
touch the files in the work tree.  In earlier versions of git, a git-dir
in $PWD was not found without GIT_DIR=. and hooks are supposed to work
across versions of git, so this behaviour got stuck.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help