Been trying to use pre-commit together with the following script for formatting java code
https://github.com/maltzj/google-style-precommit-hook
As you can see the plug-in is of type "script" and written for #!/bin/sh
Everything works fine on unix environments
But when team mates that are on windows 10 and use Git Bash as their shell environment it fails miserably with the following
An unexpected error has occurred: FileNotFoundError: [WinError 2] The system cannot find the file specified
Traceback (most recent call last):
File "c:\users\x\scoop\apps\python\3.6.5\lib\site-packages\pre_commit\error_handler.py", line 47, in error_handler
yield
File "c:\users\x\scoop\apps\python\3.6.5\lib\site-packages\pre_commit\main.py", line 258, in main
return run(runner, args)
File "c:\users\x\scoop\apps\python\3.6.5\lib\site-packages\pre_commit\commands\run.py", line 270, in run
return _run_hooks(runner.config, repo_hooks, args, environ)
File "c:\users\x\scoop\apps\python\3.6.5\lib\site-packages\pre_commit\commands\run.py", line 199, in _run_hooks
retval |= _run_single_hook(filenames, hook, repo, args, skips, cols)
File "c:\users\x\scoop\apps\python\3.6.5\lib\site-packages\pre_commit\commands\run.py", line 110, in _run_single_hook
hook, tuple(filenames) if hook['pass_filenames'] else (),
File "c:\users\x\scoop\apps\python\3.6.5\lib\site-packages\pre_commit\repository.py", line 207, in run_hook
return languages[language_name].run_hook(prefix, hook, file_args)
File "c:\users\x\scoop\apps\python\3.6.5\lib\site-packages\pre_commit\languages\script.py", line 16, in run_hook
return xargs(cmd, file_args)
File "c:\users\x\scoop\apps\python\3.6.5\lib\site-packages\pre_commit\xargs.py", line 63, in xargs
*run_cmd, encoding=None, retcode=None
File "c:\users\x\scoop\apps\python\3.6.5\lib\site-packages\pre_commit\util.py", line 167, in cmd_output
proc = subprocess.Popen(cmd, **popen_kwargs)
File "c:\users\x\scoop\apps\python\3.6.5\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "c:\users\x\scoop\apps\python\3.6.5\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
After some debugging seems that the file not found refers to "c:/bin/sh" which of course is not there, git bash has sh but inside "/Program Files/git/bin". On some users having a symlink or c:/bin/sh worked sort of, but it's neither nice nor 100% working on all cases.
Any ideas of something that could be done to avoid those OS headaches or maybe a way on pre-commit to specify the path to the shell executable or to have OS dependent scripts (E.g. .sh vs .bat) somehow and have pre-commit pick the proper one automatically?
If the shebang is changed to #!/usr/bin/env sh it will work I think! I can give a better answer when not on phone and not inebriated :)
Great, that seems to have done the trick at least on one of the tested windows installations. Will try on the other one soon
Thanks ;)
Confirmed that so far it worked on multiple cases!
Thanks for the suggestion and cheers ;)
No problem! Thanks for the issue 馃帀
Most helpful comment
If the shebang is changed to
#!/usr/bin/env shit will work I think! I can give a better answer when not on phone and not inebriated :)