I have a repository which contains versioned git hooks. I have symbolic links (that are relative) inside the .git/hooks
folder that point to my versioned git hooks. The git hooks are implemented in python and contain the #!/usr/bin/env python
shebang line (which should be working https://docs.python.org/3/using/windows.html?#shebang-lines).
As part of my versioned git hooks - I have a pre-commit file and a utils.py
file on the same level which is imported in the pre-commit script.
When I commit on my Mac the pre-commit successfully runs. However, when I commit on a Windows machine, my pre-commit script blows up on the line where utils.py
is being imported and I have no idea why. What is going wrong, what have I missed?
EDIT: This is how I am generating my symbolic links. Note that I have used this question: https://stackoverflow.com/a/28382515/2155605 to make os.symlink
work on unix and windows. Also note that when this script runs I am in the .git/hooks
directory.
for hook in hooks_to_enable:
os.chmod("../../git-hooks/" + hook, os.stat("../../git-hooks/" + hook).st_mode | 0o111)
os.symlink(os.path.join("..", "..", "git-hooks", hook), hook)
EDIT: I may have narrowed down the problem. When I print my module search path (sys.path
) in my versioned hook, it shows the search path from the .hooks
directory so all the modules that are in the versioned hooks directory cannot be imported because they are not on the path. If I manually add them it works. However, when I do this same thing on Unix, the search path contains the directory of the versioned hook - not the .git/hooks
directory - which is why it's working on Unix.