Files
lila/bin/git-hooks/pre-commit

20 lines
725 B
Bash
Executable File

#!/bin/sh
# Short circuit lint-staged to avoid waiting on node when not needed. Even
# when no files match, and we execute lint-stage directly, it still delays
# the commit by .15s or so, which is annoying.
if \git --no-pager diff-index -z --name-only --no-renames --cached HEAD | \
\grep -qzE '\.(json|ts|mts|mjs|scss)$'; then
# NOTE! grep must be kept in sync with lint-staged config (ui/lint-staged-config.mjs)
ROOT_DIR="$(dirname -- $0)/../.."
LINT_STAGED="$ROOT_DIR/node_modules/.bin/lint-staged"
# pnpm or npx adds .25s overhead. exec further reduces overhead.
if [ -x "$LINT_STAGED" ]; then
exec "$LINT_STAGED" --config "$ROOT_DIR/ui/lint-staged.config.mjs"
else
exec pnpm lint-staged
fi
fi