1
0
Fork 0
mirror of https://github.com/vbatts/git-validation.git synced 2024-11-25 17:45:40 +00:00

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

View file

@ -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, " "))
}