Only run fmtcheck on changed files pre-commit (#21747)

The pre-commit hook was taking quite a while to run. Let's just check
changed files to avoid unnecessary `go fmt` on the entire tree.
This commit is contained in:
Mike Palmiotto
2023-07-11 10:26:16 -04:00
committed by GitHub
parent 1bed33a399
commit a9778be3f2
2 changed files with 14 additions and 4 deletions

View File

@@ -62,11 +62,14 @@ ui_lint() {
backend_lint() {
# Silently succeed if no changes staged for Go code files.
if git diff --name-only --cached --exit-code -- '*.go'; then
staged=$(git diff --name-only --cached --exit-code -- '*.go')
ret=$?
if [ $ret -eq 0 ]; then
return 0
fi
./scripts/gofmtcheck.sh || block "Backend linting failed; run 'make fmt' to fix."
# Only run fmtcheck on staged files
./scripts/gofmtcheck.sh "${staged}" || block "Backend linting failed; run 'make fmt' to fix."
}
for CHECK in $CHECKS; do