From 049e1bbf73bcfdc22a2e2b79714aaa93dbdb756f Mon Sep 17 00:00:00 2001 From: Matthew Patton Date: Wed, 1 Feb 2017 22:57:36 -0500 Subject: [PATCH] too many files for shell during Make, convert .go and .sh to EOL=lf --- .gitattributes | 6 ++++-- Makefile | 9 ++++++--- scripts/gofmtcheck.sh | 14 ++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.gitattributes b/.gitattributes index 7230f36f4..fba3b1303 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,4 @@ - -common/test-fixtures/root/* eol=lf \ No newline at end of file +* text=auto +*.go text eol=lf +*.sh text eol=lf +common/test-fixtures/root/* eol=lf diff --git a/Makefile b/Makefile index 54852ce26..cb48d7e2c 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ VET?=$(shell ls -d */ | grep -v vendor | grep -v website) GITSHA:=$(shell git rev-parse HEAD) # Get the current local branch name from git (if we can, this may be blank) GITBRANCH:=$(shell git symbolic-ref --short HEAD 2>/dev/null) -GOFMT_FILES?=$$(find . -not -path "./vendor/*" -name "*.go") +GOFMT_FILES?=find . -path ./vendor -prune -o -name "*.go" GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) GOPATH=$(shell go env GOPATH) @@ -57,10 +57,13 @@ dev: deps ## Build and install a development build @cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH) fmt: ## Format Go code - @gofmt -w -s $(GOFMT_FILES) + @$(GOFMT_FILES) | xargs gofmt -w -s fmt-check: ## Check go code formatting - $(CURDIR)/scripts/gofmtcheck.sh $(GOFMT_FILES) + @echo "==> Checking that code complies with gofmt requirements..." + @echo "You can use the command: \`make fmt\` to reformat code." + @$(GOFMT_FILES) | xargs $(CURDIR)/scripts/gofmtcheck.sh + @echo "Check complete." fmt-docs: @find ./website/source/docs -name "*.md" -exec pandoc --wrap auto --columns 79 --atx-headers -s -f "markdown_github+yaml_metadata_block" -t "markdown_github+yaml_metadata_block" {} -o {} \; diff --git a/scripts/gofmtcheck.sh b/scripts/gofmtcheck.sh index 5b99bcdc4..cc6deb81e 100755 --- a/scripts/gofmtcheck.sh +++ b/scripts/gofmtcheck.sh @@ -1,14 +1,8 @@ #!/usr/bin/env bash -# Check gofmt -echo "==> Checking that code complies with gofmt requirements..." -gofmt_files=$(gofmt -s -l ${@}) -if [[ -n ${gofmt_files} ]]; then - echo 'gofmt needs running on the following files:' - echo "${gofmt_files}" - echo "You can use the command: \`make fmt\` to reformat code." - exit 1 -fi -echo "Check passed." +for f in $@; do + [ -n "`dos2unix 2>/dev/null < $f | gofmt -s -d`" ] && echo $f +done +# always return success or else 'make' will abort exit 0