From 742f9db7aef4fb82a0e627e7d3255a926d4e8152 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Wed, 26 Apr 2017 14:29:57 -0700 Subject: [PATCH] Add exclude pattern for git checks Allows excluding of vendor directories for whitespace checks Signed-off-by: Derek McGowan --- git/commits.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/git/commits.go b/git/commits.go index 5249e0b..2331c31 100644 --- a/git/commits.go +++ b/git/commits.go @@ -1,6 +1,7 @@ package git import ( + "fmt" "os" "os/exec" "strings" @@ -61,7 +62,14 @@ var FieldNames = map[string]string{ // Check warns if changes introduce whitespace errors. // Returns non-zero if any issues are found. func Check(commit string) ([]byte, error) { - cmd := exec.Command("git", "--no-pager", "show", "--check", commit) + args := []string{ + "--no-pager", "log", "--check", + fmt.Sprintf("%s^..%s", commit, commit), + } + if exclude := os.Getenv("GIT_CHECK_EXCLUDE"); exclude != "" { + args = append(args, "--", ".", fmt.Sprintf(":(exclude)%s", exclude)) + } + cmd := exec.Command("git", args...) if debug() { logrus.Infof("[git] cmd: %q", strings.Join(cmd.Args, " ")) }