1
0
Fork 0
mirror of https://github.com/vbatts/git-validation.git synced 2025-03-03 07:28:42 +00:00

git & validation: skip git check on initial commit because it needs a range

Fixes #66

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2025-02-25 21:40:51 -05:00
parent 679e5cad8c
commit a41c47c06a
Signed by: vbatts
GPG key ID: E30EFAA812C6E5ED
2 changed files with 25 additions and 0 deletions

View file

@ -135,6 +135,15 @@ func gitVersionNewerThan(otherV string) (bool, error) {
// Check warns if changes introduce whitespace errors.
// Returns non-zero if any issues are found.
func Check(commit string) ([]byte, error) {
logs, err := LogUntil(commit)
if err != nil {
return nil, err
}
if len(logs) == 1 {
logrus.Debugf("[git.Check] %q is the initial commit. Skipping.", commit)
return []byte{}, nil
}
args := []string{
"--no-pager", "log", "--check",
fmt.Sprintf("%s^..%s", commit, commit),
@ -178,6 +187,21 @@ func Show(commit string) ([]byte, error) {
// See also FieldNames
type CommitEntry map[string]string
// LogUntil returns the array of oneline commits from initial until the provided commit
func LogUntil(commit string) ([]string, error) {
cmd := exec.Command("git", "--no-pager", "log", "--oneline", "--no-show-signature", commit)
if debug() {
logrus.Infof("[git] cmd: %q", strings.Join(cmd.Args, " "))
}
cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
logrus.Errorf("[git] cmd: %q", strings.Join(cmd.Args, " "))
return nil, err
}
return strings.Split(strings.TrimSpace(string(out)), "\n"), nil
}
// LogCommit assembles the full information on a commit from its commit hash
func LogCommit(commit string) (*CommitEntry, error) {
c := CommitEntry{}

View file

@ -47,6 +47,7 @@ func NewRunner(root string, rules []Rule, commitrange string, verbose bool) (*Ru
}
}
}
logrus.Debugf("[NewRunner] commitrange: %q", commitrange)
return &Runner{
Root: newroot,
Rules: rules,