Skip to content

Commit a269d9d

Browse files
committed
git-validation: do not fail on an empty commit range
The error could be reproduced with "git-validation -range HEAD..HEAD" Closes: #36 Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 3fd57e3 commit a269d9d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

git/commits.go

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
// Commits returns a set of commits.
1212
// If commitrange is a git still range 12345...54321, then it will be isolated set of commits.
1313
// If commitrange is a single commit, all ancestor commits up through the hash provided.
14+
// If commitrange is an empty commit range, then nil is returned.
1415
func Commits(commitrange string) ([]CommitEntry, error) {
1516
cmdArgs := []string{"git", "log", `--pretty=format:%H`, commitrange}
1617
if debug() {
@@ -20,6 +21,9 @@ func Commits(commitrange string) ([]CommitEntry, error) {
2021
if err != nil {
2122
return nil, err
2223
}
24+
if len(output) == 0 {
25+
return nil, nil
26+
}
2327
commitHashes := strings.Split(strings.TrimSpace(string(output)), "\n")
2428
commits := make([]CommitEntry, len(commitHashes))
2529
for i, commitHash := range commitHashes {

0 commit comments

Comments
 (0)