Skip to content

Commit

Permalink
fix: check for error before reading parent (#84)
Browse files Browse the repository at this point in the history
Co-authored-by: Joe Chen <[email protected]>
  • Loading branch information
aymanbagabas and unknwon authored Oct 31, 2022
1 parent 34a6ca3 commit 58d9f16
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions repo_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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())
Expand Down

0 comments on commit 58d9f16

Please sign in to comment.