File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,19 @@ var FieldNames = map[string]string{
5858 "%G?" : "verification_flag" ,
5959}
6060
61+ // Show returns the diff of a commit.
62+ //
63+ // NOTE: This could be expensive for very large commits.
64+ func Show (commit string ) ([]byte , error ) {
65+ cmd := exec .Command ("git" , "show" , commit )
66+ cmd .Stderr = os .Stderr
67+ out , err := cmd .Output ()
68+ if err != nil {
69+ return nil , err
70+ }
71+ return out , nil
72+ }
73+
6174// CommitEntry represents a single commit's information from `git`.
6275// See also FieldNames
6376type CommitEntry map [string ]string
Original file line number Diff line number Diff line change 1+ package danglingwhitespace
2+
3+ import (
4+ "github.com/vbatts/git-validation/git"
5+ "github.com/vbatts/git-validation/validate"
6+ )
7+
8+ var (
9+ // DanglingWhitespace is the rule for checking the presence of dangling
10+ // whitespaces on line endings.
11+ DanglingWhitespace = validate.Rule {
12+ Name : "dangling-whitespace" ,
13+ Description : "checking the presence of dangling whitespaces on line endings" ,
14+ Run : ValidateDanglingWhitespace ,
15+ }
16+ )
17+
18+ func init () {
19+ validate .RegisterRule (DanglingWhitespace )
20+ }
21+
22+ func ValidateDanglingWhitespace (c git.CommitEntry ) (vr validate.Result ) {
23+ diff , err := git .Show (c ["commit" ])
24+
25+ return
26+ }
You can’t perform that action at this time.
0 commit comments