diff --git a/hack/update-gofmt.sh b/hack/update-gofmt.sh index 1758662d511..c5031223d45 100755 --- a/hack/update-gofmt.sh +++ b/hack/update-gofmt.sh @@ -27,20 +27,17 @@ kube::golang::verify_go_version cd "${KUBE_ROOT}" -find_files() { - find . -not \( \ - \( \ - -wholename './output' \ - -o -wholename './.git' \ - -o -wholename './_output' \ - -o -wholename './_gopath' \ - -o -wholename './release' \ - -o -wholename './target' \ - -o -wholename '*/third_party/*' \ - -o -wholename '*/vendor/*' \ - -o -wholename './staging/src/k8s.io/client-go/*vendor/*' \ - \) -prune \ - \) -name '*.go' +function git_find() { + # Similar to find but faster and easier to understand. We want to include + # modified and untracked files because this might be running against code + # which is not tracked by git yet. + git ls-files -cmo --exclude-standard \ + ':!:vendor/*' `# catches vendor/...` \ + ':!:*/vendor/*' `# catches any subdir/vendor/...` \ + ':!:third_party/*' `# catches third_party/...` \ + ':!:*/third_party/*' `# catches third_party/...` \ + ':(glob)**/*.go' \ + "$@" } -find_files | xargs gofmt -s -w +git_find -z | xargs -0 gofmt -s -w