Even though GIT_DIR is set, I would still try a:
git --git-dir=/full/path/to/repo/.git --work-tree=/full/path/to/rpeo diff --cached |grep -q "^my/folder"
That way, you are sure the hook is executed where it is supposed to.
Question
I'm trying to build a pre-commit script in git. In that script I plan on running tasks if a certain folder has changed. To test, in my script I have
git diff --cached | grep -q "^my/folder"
This results in...
Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>
pwd
says I'm in the correct directory and $GIT_DIR
is .git
. I was lead to belive that --cached
was the special sauce to get this working in a hook. Is there a way to do this?
La solution
Even though GIT_DIR is set, I would still try a:
git --git-dir=/full/path/to/repo/.git --work-tree=/full/path/to/rpeo diff --cached |grep -q "^my/folder"
That way, you are sure the hook is executed where it is supposed to.
Autres conseils
unset GIT_DIR
cleared it up. I'm disappointed that --git-dir
did not.