mirror of
https://github.com/kuhyx/scripts.git
synced 2026-07-04 13:03:05 +02:00
fix: improve pre-commit hook to avoid formatting loop
- Auto-fix with shfmt on staged files - Run shellcheck validation directly instead of full shell_check.sh - Avoids shfmt -d validation after auto-formatting (prevents .orig file loop) - Ensures consistent formatting without blocking commits
This commit is contained in:
parent
03bd36e41d
commit
dfe079c219
@ -36,10 +36,19 @@ fi
|
|||||||
printf 'Running shell_check validation...\n'
|
printf 'Running shell_check validation...\n'
|
||||||
|
|
||||||
# Run shell_check to validate all checks
|
# Run shell_check to validate all checks
|
||||||
if ! scripts/meta/shell_check.sh --skip-install 2>&1; then
|
# Note: We only validate the staged files since we just auto-formatted them
|
||||||
printf '\nCommit aborted: shell_check reported issues.\n' >&2
|
# Validate only shellcheck, not shfmt (we already applied formatting)
|
||||||
printf 'Fix the remaining problems and retry the commit.\n' >&2
|
mapfile -d '' -t staged_shell_files < <(git diff --cached --name-only --diff-filter=ACM -z | grep -zE '\.(sh|bash|zsh)$' || true)
|
||||||
exit 1
|
|
||||||
|
if [[ ${#staged_shell_files[@]} -gt 0 ]]; then
|
||||||
|
# Run shellcheck on staged files
|
||||||
|
if command -v shellcheck > /dev/null 2>&1; then
|
||||||
|
if ! shellcheck -x -S style "${staged_shell_files[@]}" 2>&1; then
|
||||||
|
printf '\nCommit aborted: shellcheck found issues.\n' >&2
|
||||||
|
printf 'Fix the remaining problems and retry the commit.\n' >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf 'shell_check passed. Proceeding with commit.\n'
|
printf 'shell_check passed. Proceeding with commit.\n'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user