From c71185d11eb68261b9c210b5feb4bdf7b0d8c90a Mon Sep 17 00:00:00 2001 From: Thomas Miceli Date: Mon, 20 Mar 2023 14:05:56 +0100 Subject: [PATCH] Fix empty commit revision --- internal/git/output_parser.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/internal/git/output_parser.go b/internal/git/output_parser.go index 4075838..99ea793 100644 --- a/internal/git/output_parser.go +++ b/internal/git/output_parser.go @@ -69,8 +69,16 @@ func parseLog(out io.Reader) []*Commit { var currentFile *File var isContent bool var bytesRead = 0 + scanNext := true + + for { + if scanNext && !scanner.Scan() { + break + } + scanNext = true + + fmt.Println("> " + string(scanner.Bytes())) - for scanner.Scan() { // new commit found currentFile = nil currentCommit = &Commit{Hash: string(scanner.Bytes()[2:]), Files: []File{}} @@ -85,6 +93,16 @@ func parseLog(out io.Reader) []*Commit { currentCommit.Timestamp = string(scanner.Bytes()[2:]) scanner.Scan() + + // if there is no shortstat, it means that the commit is empty, we add it and move onto the next one + if scanner.Bytes()[0] != ' ' { + commits = append(commits, currentCommit) + + // avoid scanning the next line, as we already did it + scanNext = false + continue + } + changed := scanner.Bytes()[1:] changed = bytes.ReplaceAll(changed, []byte("(+)"), []byte("")) changed = bytes.ReplaceAll(changed, []byte("(-)"), []byte("")) @@ -158,9 +176,8 @@ func parseLog(out io.Reader) []*Commit { scanner.Scan() } - if currentCommit != nil { - commits = append(commits, currentCommit) - } + commits = append(commits, currentCommit) + } return commits