mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 01:51:46 +04:00
Use plain sh for the pre-commit script
Bash is currently a dependency of pre-commit. It is only used in the pre-commit script, and the only bash-specific feature that is used is a single array. Use the `args` array instead, which works on plain sh (e.g.: POSIX sh). This change drops bash as a runtime dependency. Tested with busybox sh(ash) and OpenBSD's sh(ksh).
This commit is contained in:
parent
7b88c63ae6
commit
b748138ed6
2 changed files with 7 additions and 13 deletions
|
|
@ -94,17 +94,10 @@ def _install_hook_script(
|
||||||
before, rest = contents.split(TEMPLATE_START)
|
before, rest = contents.split(TEMPLATE_START)
|
||||||
_, after = rest.split(TEMPLATE_END)
|
_, after = rest.split(TEMPLATE_END)
|
||||||
|
|
||||||
# on windows always use `/bin/sh` since `bash` might not be on PATH
|
|
||||||
# though we use bash-specific features `sh` on windows is actually
|
|
||||||
# bash in "POSIXLY_CORRECT" mode which still supports the features we
|
|
||||||
# use: subshells / arrays
|
|
||||||
if sys.platform == 'win32': # pragma: win32 cover
|
|
||||||
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')
|
hook_file.write(f'INSTALL_PYTHON={shlex.quote(sys.executable)}\n')
|
||||||
args_s = shlex.join(args)
|
args_s = shlex.join(args)
|
||||||
hook_file.write(f'ARGS=({args_s})\n')
|
hook_file.write(f"ARGS='{args_s}'\n")
|
||||||
hook_file.write(TEMPLATE_END + after)
|
hook_file.write(TEMPLATE_END + after)
|
||||||
make_executable(hook_path)
|
make_executable(hook_path)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,20 @@
|
||||||
#!/usr/bin/env bash
|
#!/bin/sh
|
||||||
# File generated by pre-commit: https://pre-commit.com
|
# File generated by pre-commit: https://pre-commit.com
|
||||||
# ID: 138fd403232d2ddd5efb44317e38bf03
|
# ID: 138fd403232d2ddd5efb44317e38bf03
|
||||||
|
|
||||||
# start templated
|
# start templated
|
||||||
INSTALL_PYTHON=''
|
INSTALL_PYTHON=''
|
||||||
ARGS=(hook-impl)
|
ARGS="hook-impl"
|
||||||
# end templated
|
# end templated
|
||||||
|
|
||||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||||
ARGS+=(--hook-dir "$HERE" -- "$@")
|
set -- $ARGS --hook-dir "$HERE" -- "$@"
|
||||||
|
|
||||||
if [ -x "$INSTALL_PYTHON" ]; then
|
if [ -x "$INSTALL_PYTHON" ]; then
|
||||||
exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
|
exec "$INSTALL_PYTHON" -mpre_commit "$@"
|
||||||
|
|
||||||
elif command -v pre-commit > /dev/null; then
|
elif command -v pre-commit > /dev/null; then
|
||||||
exec pre-commit "${ARGS[@]}"
|
exec pre-commit "$@"
|
||||||
else
|
else
|
||||||
echo '`pre-commit` not found. Did you forget to activate your virtualenv?' 1>&2
|
echo '`pre-commit` not found. Did you forget to activate your virtualenv?' 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue