1
0
Fork 0
mirror of https://github.com/vbatts/git-validation.git synced 2025-06-02 10:02:29 +00:00

*: run tests in a runner

for cleanliness and ease of testing

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2015-10-06 10:44:04 -04:00
parent b9413c60c8
commit d614ccf997
4 changed files with 119 additions and 52 deletions

View file

@ -17,7 +17,7 @@ import (
// If commitrange is a single commit, all ancestor commits up through the hash provided.
func Commits(commitrange string) ([]CommitEntry, error) {
cmdArgs := []string{"git", "log", prettyFormat + formatCommit, commitrange}
if Verbose {
if debug() {
logrus.Infof("[git] cmd: %q", strings.Join(cmdArgs, " "))
}
output, err := exec.Command(cmdArgs[0], cmdArgs[1:]...).Output()
@ -40,9 +40,6 @@ func Commits(commitrange string) ([]CommitEntry, error) {
type CommitEntry map[string]string
var (
// Verbose output of commands run
Verbose = false
prettyFormat = `--pretty=format:`
formatSubject = `%s`
formatBody = `%b`
@ -60,7 +57,7 @@ var (
func LogCommit(commit string) (*CommitEntry, error) {
buf := bytes.NewBuffer([]byte{})
cmdArgs := []string{"git", "log", "-1", prettyFormat + formatMap, commit}
if Verbose {
if debug() {
logrus.Infof("[git] cmd: %q", strings.Join(cmdArgs, " "))
}
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
@ -99,10 +96,14 @@ func LogCommit(commit string) (*CommitEntry, error) {
return &c, nil
}
func debug() bool {
return len(os.Getenv("DEBUG")) > 0
}
// FetchHeadCommit returns the hash of FETCH_HEAD
func FetchHeadCommit() (string, error) {
cmdArgs := []string{"git", "rev-parse", "--verify", "FETCH_HEAD"}
if Verbose {
if debug() {
logrus.Infof("[git] cmd: %q", strings.Join(cmdArgs, " "))
}
output, err := exec.Command(cmdArgs[0], cmdArgs[1:]...).Output()
@ -115,7 +116,7 @@ func FetchHeadCommit() (string, error) {
// HeadCommit returns the hash of HEAD
func HeadCommit() (string, error) {
cmdArgs := []string{"git", "rev-parse", "--verify", "HEAD"}
if Verbose {
if debug() {
logrus.Infof("[git] cmd: %q", strings.Join(cmdArgs, " "))
}
output, err := exec.Command(cmdArgs[0], cmdArgs[1:]...).Output()