Skip to content

Commit 6aaeab1

Browse files
committed
*: prepping for checking a diff
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
1 parent 61a4420 commit 6aaeab1

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

git/commits.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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
6376
type CommitEntry map[string]string

rules/danglingwhitespace/rule.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

0 commit comments

Comments
 (0)