mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 02:57:59 +00:00
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:
@@ -62,11 +62,14 @@ ui_lint() {
|
|||||||
|
|
||||||
backend_lint() {
|
backend_lint() {
|
||||||
# Silently succeed if no changes staged for Go code files.
|
# 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
|
return 0
|
||||||
fi
|
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
|
for CHECK in $CHECKS; do
|
||||||
|
|||||||
@@ -2,10 +2,17 @@
|
|||||||
# Copyright (c) HashiCorp, Inc.
|
# Copyright (c) HashiCorp, Inc.
|
||||||
# SPDX-License-Identifier: MPL-2.0
|
# SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
|
||||||
echo "==> Checking that code complies with gofmt requirements..."
|
echo "==> Checking that code complies with gofmt requirements..."
|
||||||
|
|
||||||
gofmt_files="$(find . -name '*.go' | grep -v pb.go | grep -v vendor | xargs go run mvdan.cc/gofumpt -l)"
|
files=$(echo $1 | xargs)
|
||||||
|
if [ -n "$files" ]; then
|
||||||
|
echo "Checking changed files..."
|
||||||
|
gofmt_files="$(echo $1 | grep -v pb.go | grep -v vendor | xargs go run mvdan.cc/gofumpt -l)"
|
||||||
|
else
|
||||||
|
echo "Checking all files..."
|
||||||
|
gofmt_files="$(find . -name '*.go' | grep -v pb.go | grep -v vendor | xargs go run mvdan.cc/gofumpt -l)"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -n "${gofmt_files}" ]]; then
|
if [[ -n "${gofmt_files}" ]]; then
|
||||||
echo 'gofumpt needs running on the following files:'
|
echo 'gofumpt needs running on the following files:'
|
||||||
echo "${gofmt_files}"
|
echo "${gofmt_files}"
|
||||||
|
|||||||
Reference in New Issue
Block a user