From a269d9d42deefbd68634cbe27122d86dece49537 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 8 Nov 2018 14:13:57 +0100 Subject: [PATCH] git-validation: do not fail on an empty commit range The error could be reproduced with "git-validation -range HEAD..HEAD" Closes: https://github.com/vbatts/git-validation/issues/36 Signed-off-by: Giuseppe Scrivano --- git/commits.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/git/commits.go b/git/commits.go index f0a392a..3c30dcf 100644 --- a/git/commits.go +++ b/git/commits.go @@ -11,6 +11,7 @@ import ( // Commits returns a set of commits. // If commitrange is a git still range 12345...54321, then it will be isolated set of commits. // If commitrange is a single commit, all ancestor commits up through the hash provided. +// If commitrange is an empty commit range, then nil is returned. func Commits(commitrange string) ([]CommitEntry, error) { cmdArgs := []string{"git", "log", `--pretty=format:%H`, commitrange} if debug() { @@ -20,6 +21,9 @@ func Commits(commitrange string) ([]CommitEntry, error) { if err != nil { return nil, err } + if len(output) == 0 { + return nil, nil + } commitHashes := strings.Split(strings.TrimSpace(string(output)), "\n") commits := make([]CommitEntry, len(commitHashes)) for i, commitHash := range commitHashes {