Add exclude pattern for git checks

Allows excluding of vendor directories for whitespace checks

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan 2017-04-26 14:29:57 -07:00
parent cf8d44cfd7
commit 742f9db7ae
1 changed files with 9 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package git package git
import ( import (
"fmt"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
@ -61,7 +62,14 @@ var FieldNames = map[string]string{
// Check warns if changes introduce whitespace errors. // Check warns if changes introduce whitespace errors.
// Returns non-zero if any issues are found. // Returns non-zero if any issues are found.
func Check(commit string) ([]byte, error) { 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() { if debug() {
logrus.Infof("[git] cmd: %q", strings.Join(cmd.Args, " ")) logrus.Infof("[git] cmd: %q", strings.Join(cmd.Args, " "))
} }