From 7a5c376e63085d60a5d9c00d8f176b4a945f1ad0 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 2 Jul 2018 08:45:06 -0700 Subject: Makefile: Use 'git diff' to show gofmt changes This makes fixing errors easier. Before this commit, errors looked like [1]: $ make gofmt libpod/container_linux.go:1::warning: file is not gofmted with -s (gofmt) 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/libpod/container_internal.go b/libpod/container_internal.go index df4de3fe..22b39870 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1,7 +1,7 @@ package libpod import ( -"bytes" + "bytes" "context" "encoding/json" "fmt" make: *** [Makefile:87: 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 Closes: #1038 Approved by: rhatdan --- hack/verify-gofmt.sh | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100755 hack/verify-gofmt.sh (limited to 'hack') diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh deleted file mode 100755 index af252a13b..000000000 --- a/hack/verify-gofmt.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -set -o errexit -set -o nounset -set -o pipefail - -find_files() { - find . -not \( \ - \( \ - -wholename '*/vendor/*' \ - \) -prune \ - \) -name '*.go' \ - -not \( -wholename './_output/*' \) \ - -not \( -wholename './cmd/podman/ioprojectatomicpodman/ioprojectatomicpodman.go' \) -} -FIX=0 -GOFMT="gofmt -s" -bad_files=$(find_files | xargs $GOFMT -l) - -while getopts "f?:" opt; do - case "$opt" in - f) FIX=1 - ;; - esac -done - -if [[ -n "${bad_files}" ]]; then - if (($FIX == 1)) ; then - echo "Correcting the following files:" - echo "${bad_files}" - while read -r go_file; do - gofmt -s -w $go_file - done <<< "${bad_files}" - else - echo "!!! '$GOFMT' needs to be run on the following files: " - echo "${bad_files}" - exit 1 - fi -fi -- cgit v1.2.3-54-g00ecf