The problem in your script is this line:
cwd=os.path.dirname('../../'),
The hooks are run inside your .git
directory, not inside the hooks directory. So you are leaving the repo with the given line. More details on this can be found here in this answer. So you do not need to change the cwd for git diff --cached
.
You might want to change the cwd so the paths you are feeding into UniversalDetector
make sense. But what you are doing there is wrong anyways. You should not check the working dir files, but the files in the index, because they are what’s actually going to be commited.
You should use git ls-files --staged
and git show
to get the contents of the index. A shorthand for that is git show :filename
, but that might cause trouble with wierd filenames.
Also add -z
to the paramaters for git diff
, so you can handle more filenames.