Skip to content

Commit c938d87

Browse files
committed
Improve pre-commit hook
1 parent dac3c7b commit c938d87

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

.githooks/pre-commit

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
#!/bin/sh
22

3-
git stash -ku
3+
set -e
44

5-
trap "git stash pop" EXIT
5+
export PATH="./node_modules/.bin:$PATH"
66

7-
staged=$(git --no-pager diff --staged --name-only | grep -E '\.js$')
8-
9-
if [ -n "$staged" ]; then
10-
./node_modules/.bin/oxlint -- `echo $staged` && make test
7+
if git rev-parse --verify HEAD >/dev/null 2>&1
8+
then
9+
against=HEAD
10+
else
11+
against=$(git hash-object -t tree /dev/null)
1112
fi
13+
14+
git diff-index --check --cached "$against" --
15+
16+
git stash -ku --quiet
17+
trap "git stash pop --quiet" EXIT
18+
19+
changed_files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|ts)$') || true
20+
21+
if [ -z "$changed_files" ]; then exit 0; fi
22+
23+
oxlint $changed_files
24+
25+
vitest run --changed

0 commit comments

Comments
 (0)