From 8dbc2d1fff076a05dd47a5809d048e20dc772d64 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 22 Jan 2018 15:47:33 -0800 Subject: [PATCH] Makefile: Use 'git diff' to show gofmt changes This makes fixing errors easier. Before this commit, errors looked like [1]: $ make gofmt !!! 'gofmt -s' needs to be run on the following files: ./lib/config.go make: *** [gofmt] Error 1 But that's not very helpful when your local gofmt thinks the file is fine. With this commit, errors will look like: $ make gofmt find . -name '*.go' ! -path './vendor/*' -exec gofmt -s -w {} \+ git diff --exit-code diff --git a/lib/config.go b/lib/config.go index 1acca8c7..6a63b2b0 100644 --- a/lib/config.go +++ b/lib/config.go @@ -2,7 +2,7 @@ package lib import ( "bytes" -"io/ioutil" + "io/ioutil" "github.com/BurntSushi/toml" "github.com/kubernetes-incubator/cri-o/oci" make: *** [Makefile:68: gofmt] Error 1 (or whatever, I just stuffed in a formatting error for demonstration purposes). Also remove the helper script in favor of direct Makefile calls, because with Git handling difference reporting and exit status, this becomes a simpler check. find's -exec, !, and -path arguments are specified in POSIX [2]. [1]: https://travis-ci.org/kubernetes-incubator/cri-o/jobs/331949394#L1075 [2]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html Signed-off-by: W. Trevor King --- Makefile | 3 ++- hack/verify-gofmt.sh | 21 --------------------- 2 files changed, 2 insertions(+), 22 deletions(-) delete mode 100755 hack/verify-gofmt.sh diff --git a/Makefile b/Makefile index 86898afc..7cc1a4c1 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,8 @@ lint: .gopathok @./.tool/lint gofmt: - @./hack/verify-gofmt.sh + find . -name '*.go' ! -path './vendor/*' -exec gofmt -s -w {} \+ + git diff --exit-code conmon: $(MAKE) -C $@ diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh deleted file mode 100755 index 5577d1b9..00000000 --- a/hack/verify-gofmt.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -set -o errexit -set -o nounset -set -o pipefail - -find_files() { - find . -not \( \ - \( \ - -wholename '*/vendor/*' \ - \) -prune \ - \) -name '*.go' -} - -GOFMT="gofmt -s" -bad_files=$(find_files | xargs $GOFMT -l) -if [[ -n "${bad_files}" ]]; then - echo "!!! '$GOFMT' needs to be run on the following files: " - echo "${bad_files}" - exit 1 -fi