Skip to content

Commit 742f9db

Browse files
committed
Add exclude pattern for git checks
Allows excluding of vendor directories for whitespace checks Signed-off-by: Derek McGowan <[email protected]>
1 parent cf8d44c commit 742f9db

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

git/commits.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package git
22

33
import (
4+
"fmt"
45
"os"
56
"os/exec"
67
"strings"
@@ -61,7 +62,14 @@ var FieldNames = map[string]string{
6162
// Check warns if changes introduce whitespace errors.
6263
// Returns non-zero if any issues are found.
6364
func Check(commit string) ([]byte, error) {
64-
cmd := exec.Command("git", "--no-pager", "show", "--check", commit)
65+
args := []string{
66+
"--no-pager", "log", "--check",
67+
fmt.Sprintf("%s^..%s", commit, commit),
68+
}
69+
if exclude := os.Getenv("GIT_CHECK_EXCLUDE"); exclude != "" {
70+
args = append(args, "--", ".", fmt.Sprintf(":(exclude)%s", exclude))
71+
}
72+
cmd := exec.Command("git", args...)
6573
if debug() {
6674
logrus.Infof("[git] cmd: %q", strings.Join(cmd.Args, " "))
6775
}

0 commit comments

Comments
 (0)