From 59a518edd7522f3e2ecbc09db804689b5832d7a4 Mon Sep 17 00:00:00 2001 From: Ahrav Dutta Date: Tue, 23 Apr 2024 14:40:02 -0700 Subject: [PATCH] return --- pkg/gitparse/gitparse.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/gitparse/gitparse.go b/pkg/gitparse/gitparse.go index d52cb9b55..49b3d27b2 100644 --- a/pkg/gitparse/gitparse.go +++ b/pkg/gitparse/gitparse.go @@ -101,7 +101,21 @@ func (d *Diff) write(p []byte) error { // handle the final flush in the finalize method, in case there's data remaining in the buffer. // This method should be called to release resources, especially when writing to a file. func (d *Diff) finalize() error { - return d.contentWriter.CloseForWriting() + if err := d.contentWriter.CloseForWriting(); err != nil { + return fmt.Errorf("failed to finalize diff: %w", err) + } + + if !d.IsBinary { + return nil + } + + // If the diff is binary, the contentWriter will NOT contain any diff content. + // We should close it to release resources. + rdr, err := d.ReadCloser() + if err != nil { + return fmt.Errorf("failed to finalize diff: %w", err) + } + return rdr.Close() } // Commit contains commit header info and diffs.