From 4d8c0dfc030eefded6b3bc51d84ceaac9c6f8dff Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 27 Oct 2022 15:28:20 -0400 Subject: [PATCH 1/2] fix: check for error before reading parent --- repo_diff.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/repo_diff.go b/repo_diff.go index 03d4f2bc..a7550b93 100644 --- a/repo_diff.go +++ b/repo_diff.go @@ -45,7 +45,10 @@ func (r *Repository) Diff(rev string, maxFiles, maxFileLines, maxLineChars int, AddOptions(opt.CommandOptions). AddArgs("--full-index", rev) } else { - c, _ := commit.Parent(0) + c, err := commit.Parent(0) + if err != nil { + return nil, err + } cmd = cmd.AddArgs("diff"). AddOptions(opt.CommandOptions). AddArgs("--full-index", "-M", c.ID.String(), rev) @@ -111,7 +114,10 @@ func (r *Repository) RawDiff(rev string, diffType RawDiffFormat, w io.Writer, op AddOptions(opt.CommandOptions). AddArgs("--full-index", rev) } else { - c, _ := commit.Parent(0) + c, err := commit.Parent(0) + if err != nil { + return err + } cmd = cmd.AddArgs("diff"). AddOptions(opt.CommandOptions). AddArgs("--full-index", "-M", c.ID.String(), rev) @@ -122,7 +128,10 @@ func (r *Repository) RawDiff(rev string, diffType RawDiffFormat, w io.Writer, op AddOptions(opt.CommandOptions). AddArgs("--full-index", "--no-signature", "--stdout", "--root", rev) } else { - c, _ := commit.Parent(0) + c, err := commit.Parent(0) + if err != nil { + return err + } cmd = cmd.AddArgs("format-patch"). AddOptions(opt.CommandOptions). AddArgs("--full-index", "--no-signature", "--stdout", rev+"..."+c.ID.String()) From 37d95e18d6655d3e9d49184c39d290565226472a Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 27 Oct 2022 15:36:43 -0400 Subject: [PATCH 2/2] chore: fix lint --- diff_test.go | 20 ++++++++++---------- signature.go | 6 ++++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/diff_test.go b/diff_test.go index eaa1ba93..db8a7b51 100644 --- a/diff_test.go +++ b/diff_test.go @@ -102,8 +102,8 @@ func TestDiffFile(t *testing.T) { LeftLine: 0, RightLine: 1, }, { - Type: DiffLineAdd, - Content: `+ path = gogs/docs-api`, + Type: DiffLineAdd, + Content: `+ path = gogs/docs-api`, LeftLine: 0, RightLine: 2, }, @@ -203,13 +203,13 @@ index 0000000..6b08f76 LeftLine: 0, RightLine: 1, }, { - Type: DiffLineAdd, - Content: `+ path = gogs/docs-api`, + Type: DiffLineAdd, + Content: `+ path = gogs/docs-api`, LeftLine: 0, RightLine: 2, }, { - Type: DiffLineAdd, - Content: `+ url = https://github.com/gogs/docs-api.git`, + Type: DiffLineAdd, + Content: `+ url = https://github.com/gogs/docs-api.git`, LeftLine: 0, RightLine: 3, }, @@ -719,8 +719,8 @@ index 0000000..6abde17 LeftLine: 0, RightLine: 1, }, { - Type: DiffLineAdd, - Content: `+ path = gogs/docs-api`, + Type: DiffLineAdd, + Content: `+ path = gogs/docs-api`, LeftLine: 0, RightLine: 2, }, @@ -783,8 +783,8 @@ index 0000000..6b08f76 LeftLine: 0, RightLine: 1, }, { - Type: DiffLineAdd, - Content: `+ path = gogs/docs-api`, + Type: DiffLineAdd, + Content: `+ path = gogs/docs-api`, LeftLine: 0, RightLine: 2, }, diff --git a/signature.go b/signature.go index 981a4919..a35f7bab 100644 --- a/signature.go +++ b/signature.go @@ -23,8 +23,10 @@ type Signature struct { // parseSignature parses signature information from the (uncompressed) commit // line, which looks like the following but without the "author " at the // beginning: -// author Patrick Gundlach 1378823654 +0200 -// author Patrick Gundlach Thu Apr 07 22:13:13 2005 +0200 +// +// author Patrick Gundlach 1378823654 +0200 +// author Patrick Gundlach Thu Apr 07 22:13:13 2005 +0200 +// // This method should only be used for parsing author and committer. func parseSignature(line []byte) (*Signature, error) { emailStart := bytes.IndexByte(line, '<')