1

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.

Ogen
  • 6,499
  • 7
  • 58
  • 124
  • So the hook is running, but isn't running successfully to completion? Could you share the error you're seeing, as well as the code around the line it fails on? – Patrick Haugh May 24 '18 at 01:52
  • It fails on the first line `from utils import get_validation_error`. It can't find my `utils.py` module. – Ogen May 24 '18 at 01:54
  • 1
    Would https://stackoverflow.com/a/8749214/6309 help? – VonC May 24 '18 at 04:35
  • @VonC They are relevant but it doesn't explain why my symlinks are specifically not working on windows. – Ogen May 24 '18 at 05:11
  • @VonC Please see my edit on how I am generating the symlinks. I saw this comment: https://stackoverflow.com/questions/40922742/can-you-import-a-python-module-from-a-windows-symbolic-link?noredirect=1&lq=1#comment69059582_40922742 Do you think this might be my problem? – Ogen May 24 '18 at 05:26
  • What a `dir`done in a CMD return when done in the folder where your symlink has been created? Is it a folder junction? Or an actual folder link? (the latter would require administrative privilege to be correctly created) – VonC May 24 '18 at 06:02
  • @VonC It is an actual folder link - with windows I am running command prompt as an administrator when I run my script to create the links. – Ogen May 24 '18 at 21:57
  • Please see my edit I may have narrowed down the problem – Ogen May 24 '18 at 22:59

0 Answers0