From 3962c61d8aa757256256293a2a154cc194b3387f Mon Sep 17 00:00:00 2001 From: Ahrav Dutta Date: Fri, 9 Feb 2024 14:36:52 -0800 Subject: [PATCH] correctly set commit and diff --- pkg/gitparse/gitparse.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/gitparse/gitparse.go b/pkg/gitparse/gitparse.go index c01f57a5c206..0eb91031f4e6 100644 --- a/pkg/gitparse/gitparse.go +++ b/pkg/gitparse/gitparse.go @@ -380,7 +380,7 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, diffChan chan latestState = CommitLine // If there is a currentDiff, add it to currentCommit. - if currentDiff.Commit.Hash != "" || currentDiff.IsBinary { + if currentDiff.Commit != nil && currentDiff.Commit.Hash != "" || currentDiff.IsBinary { if err := currentDiff.finalize(); err != nil { ctx.Logger().Error( err, @@ -433,9 +433,6 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, diffChan chan latestState = DiffLine // This should never be nil, but check in case the stdin stream is messed up. - if currentCommit == nil { - currentCommit = &Commit{} - } if currentDiff.Commit.Hash != "" || currentDiff.IsBinary { if err := currentDiff.finalize(); err != nil { ctx.Logger().Error(err, @@ -448,6 +445,9 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, diffChan chan } diffChan <- currentDiff } + if currentCommit == nil { + currentCommit = &Commit{} + } currentDiff = diff(currentCommit) case isModeLine(latestState, line): latestState = ModeLine