Skip to content

Commit ddda6f7

Browse files
committed
.tools: Run 'git show --check ...' on each commit
Watch for accidentally-injected trailing whitespace. The stdout for failing checks is a bit hard to read: not ok 2 - git show --check 2652b57a368e8fdd6745f2354f25c56e57326b16 --- message: "commit 2652b57a368e8fdd6745f2354f25c56e57326b16\nAuthor: W. Trevor King <[email protected]>\nDate: Sat Sep 12 08:32:15 2015 -0700\n\n .tools: Run 'git show --check ...' on each commit\n \n Watch for accidentally-injected trailing whitespace. The stdout for\n failing checks is a bit hard to read:\n \n not ok 2 - exit status 2\n ---\n message: \"commit 09748ebfd739dbcee35a585a75f896a74aa1c2f0\\nAuthor: W. Trevor King\n <[email protected]>\\nDate: Sat Sep 12 08:32:15 2015 -0700\\n\\n \ .tools: Run 'git\n show --check ...' on each commit\\n \\n Watch for accidentally-injected trailing\n whitespace.\\n \\n Signed-off-by: W. Trevor King <[email protected]>\\n\\n.tools/validate.go:56:\n trailing whitespace.\\n+\\t\\t\\treturn vr \\n\"\n ...\n \n Signed-off-by: W. Trevor King <[email protected]>\n\n.tools/validate.go:57: trailing whitespace.\n+\t\t\treturn vr \n" ... But having the command in the "not ok" line should make it easy for folks to reproduce locally if they're not collecting the YAML blocks with a TAP harness. Signed-off-by: W. Trevor King <[email protected]>
1 parent 404a639 commit ddda6f7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

.tools/validate.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ var DefaultRules = []ValidateRule{
4343
return vr
4444
},
4545
// TODO add something for the cleanliness of the c.Subject
46+
func(c CommitEntry) (vr ValidateResult) {
47+
vr.CommitEntry = c
48+
buf := bytes.NewBuffer([]byte{})
49+
args := []string{"git", "show", "--check", c["commit"]}
50+
cmd := exec.Command(args[0], args[1:]...)
51+
cmd.Stdout = buf
52+
cmd.Stderr = os.Stderr
53+
if err := cmd.Run(); err != nil {
54+
vr.Pass = false
55+
vr.Msg = strings.Join(args, " ")
56+
vr.Detail = string(buf.Bytes())
57+
return vr
58+
}
59+
vr.Pass = true
60+
vr.Msg = "passes Git --check"
61+
return vr
62+
},
4663
func(c CommitEntry) (vr ValidateResult) {
4764
return ExecTree(c, "go", "vet", "./...")
4865
},

0 commit comments

Comments
 (0)