Skip to content

Commit

Permalink
*: prepping for checking a diff
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
  • Loading branch information
vbatts committed Apr 5, 2016
1 parent 61a4420 commit 6aaeab1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions git/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ var FieldNames = map[string]string{
"%G?": "verification_flag",
}

// Show returns the diff of a commit.
//
// NOTE: This could be expensive for very large commits.
func Show(commit string) ([]byte, error) {
cmd := exec.Command("git", "show", commit)
cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
return nil, err
}
return out, nil
}

// CommitEntry represents a single commit's information from `git`.
// See also FieldNames
type CommitEntry map[string]string
Expand Down
26 changes: 26 additions & 0 deletions rules/danglingwhitespace/rule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package danglingwhitespace

import (
"github.com/vbatts/git-validation/git"
"github.com/vbatts/git-validation/validate"
)

var (
// DanglingWhitespace is the rule for checking the presence of dangling
// whitespaces on line endings.
DanglingWhitespace = validate.Rule{
Name: "dangling-whitespace",
Description: "checking the presence of dangling whitespaces on line endings",
Run: ValidateDanglingWhitespace,
}
)

func init() {
validate.RegisterRule(DanglingWhitespace)
}

func ValidateDanglingWhitespace(c git.CommitEntry) (vr validate.Result) {
diff, err := git.Show(c["commit"])

return
}

0 comments on commit 6aaeab1

Please sign in to comment.