mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 10:01:46 +04:00
Add sys.executable escapes on Windows
This fixes a lack of escaping backslashes on Windows. This is pretty critical, since they are the main path separator, so will lead to catastrophic errors like `.git/hooks/pre-commit: line 6: exec: C:mypythoninstalldirpython.exe: not found`
This commit is contained in:
parent
46f7117753
commit
8a5e2e19fb
1 changed files with 5 additions and 1 deletions
|
|
@ -102,7 +102,11 @@ def _install_hook_script(
|
||||||
hook_file.write('#!/bin/sh\n')
|
hook_file.write('#!/bin/sh\n')
|
||||||
|
|
||||||
hook_file.write(before + TEMPLATE_START)
|
hook_file.write(before + TEMPLATE_START)
|
||||||
hook_file.write(f'INSTALL_PYTHON={shlex.quote(sys.executable)}\n')
|
sys_exec = sys.executable
|
||||||
|
if sys.platform == 'win32': # pragma: win32 cover
|
||||||
|
# shlex does not escape on non-nix: https://docs.python.org/3/library/shlex.html#parsing-rules
|
||||||
|
sys_exec = sys_exec.replace('\\', '\\\\')
|
||||||
|
hook_file.write(f'INSTALL_PYTHON={shlex.quote(sys_exec)}\n')
|
||||||
# TODO: python3.8+: shlex.join
|
# TODO: python3.8+: shlex.join
|
||||||
args_s = ' '.join(shlex.quote(part) for part in args)
|
args_s = ' '.join(shlex.quote(part) for part in args)
|
||||||
hook_file.write(f'ARGS=({args_s})\n')
|
hook_file.write(f'ARGS=({args_s})\n')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue