mirror of https://github.com/harness/drone.git
feat: [CODE-3061]: make git functions return not found if commit is not found (#3304)
* linter fix * make git functions return not found if commit is not foundpull/3616/head
parent
9290cf559e
commit
40dd6a19ed
|
@ -192,6 +192,9 @@ func (g *Git) listCommitSHAs(
|
|||
if cErr.IsExitCode(128) && cErr.IsAmbiguousArgErr() {
|
||||
return nil, errors.NotFound("reference %q is ambiguous", ref)
|
||||
}
|
||||
if cErr.IsExitCode(128) && cErr.IsBadObject() {
|
||||
return nil, errors.NotFound("commit not found")
|
||||
}
|
||||
return nil, processGitErrorf(err, "failed to trigger rev-list command")
|
||||
}
|
||||
|
||||
|
|
|
@ -156,6 +156,7 @@ func cutLinesFromFullFileDiff(w io.Writer, r io.Reader, startLine, endLine int)
|
|||
return scanner.Err()
|
||||
}
|
||||
|
||||
//nolint:gocognit
|
||||
func (g *Git) RawDiff(
|
||||
ctx context.Context,
|
||||
w io.Writer,
|
||||
|
@ -235,11 +236,14 @@ again:
|
|||
_ = pipeWrite.CloseWithError(err)
|
||||
}()
|
||||
|
||||
if err = newCmd.Run(ctx,
|
||||
command.WithDir(repoPath),
|
||||
command.WithStdout(pipeWrite),
|
||||
); err != nil {
|
||||
err = newCmd.Run(ctx, command.WithDir(repoPath), command.WithStdout(pipeWrite))
|
||||
if err != nil {
|
||||
err = processGitErrorf(err, "git diff failed between %q and %q", baseRef, headRef)
|
||||
if cErr := command.AsError(err); cErr != nil {
|
||||
if cErr.IsExitCode(128) && cErr.IsBadObject() {
|
||||
err = errors.NotFound("commit not found")
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -57,6 +57,10 @@ func (e *Error) IsAmbiguousArgErr() bool {
|
|||
return strings.Contains(e.Error(), "ambiguous argument")
|
||||
}
|
||||
|
||||
func (e *Error) IsBadObject() bool {
|
||||
return strings.Contains(e.Error(), "bad object")
|
||||
}
|
||||
|
||||
func (e *Error) IsInvalidRefErr() bool {
|
||||
return strings.Contains(e.Error(), "not a valid ref")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue