git-codereview: do not check vendor folder with gofmt
The go command already skips the vendor folder when running
go fmt. The "go mod vendor" command updates all vendor packages
at once, so this becomes more of an issue.
Change-Id: I0b2d51d2f1f01998e9ca7a244af491bd18150e8a
Reviewed-on: https://go-review.googlesource.com/c/158839
Run-TryBot: Daniel Theophanes <kardianos@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
diff --git a/git-codereview/gofmt.go b/git-codereview/gofmt.go
index 287bfa8..12ea801 100644
--- a/git-codereview/gofmt.go
+++ b/git-codereview/gofmt.go
@@ -345,6 +345,9 @@
if !strings.HasSuffix(file, ".go") {
return false
}
+ if strings.HasPrefix(file, "vendor/") || strings.Contains(file, "/vendor/") {
+ return false
+ }
if !strings.HasPrefix(file, "test/") {
return true
}
diff --git a/git-codereview/gofmt_test.go b/git-codereview/gofmt_test.go
index b9cd7b9..bdd0620 100644
--- a/git-codereview/gofmt_test.go
+++ b/git-codereview/gofmt_test.go
@@ -31,8 +31,12 @@
if err := os.MkdirAll(gt.client+"/test/bench", 0755); err != nil {
t.Fatal(err)
}
+ if err := os.MkdirAll(gt.client+"/vendor", 0755); err != nil {
+ t.Fatal(err)
+ }
write(t, gt.client+"/bad.go", badGo)
write(t, gt.client+"/good.go", goodGo)
+ write(t, gt.client+"/vendor/bad.go", badGo)
write(t, gt.client+"/test/bad.go", badGo)
write(t, gt.client+"/test/good.go", goodGo)
write(t, gt.client+"/test/bench/bad.go", badGo)
@@ -40,10 +44,9 @@
trun(t, gt.client, "git", "add", ".") // make files tracked
testMain(t, "gofmt", "-l")
- testPrintedStdout(t, "bad.go\n", "!good.go", fromSlash("!test/bad"), fromSlash("test/bench/bad.go"))
-
+ testPrintedStdout(t, "bad.go\n", "!good.go", fromSlash("!test/bad"), fromSlash("test/bench/bad.go"), fromSlash("!vendor/bad.go"))
testMain(t, "gofmt", "-l")
- testPrintedStdout(t, "bad.go\n", "!good.go", fromSlash("!test/bad"), fromSlash("test/bench/bad.go"))
+ testPrintedStdout(t, "bad.go\n", "!good.go", fromSlash("!test/bad"), fromSlash("test/bench/bad.go"), fromSlash("!vendor/bad.go"))
testMain(t, "gofmt")
testNoStdout(t)