fix: [CODE-2501] Return 200 with an empty list for commits on non-existing references (#3366)

This commit is contained in:
Atefeh Mohseni Ejiyeh 2025-02-01 02:28:29 +00:00 committed by Harness
parent 92e39dee79
commit a75e6ec4ec

View File

@ -189,14 +189,10 @@ func (g *Git) listCommitSHAs(
output := &bytes.Buffer{}
err := cmd.Run(ctx, command.WithDir(repoPath), command.WithStdout(output))
if cErr := command.AsError(err); cErr != nil && cErr.IsExitCode(128) {
if cErr.IsAmbiguousArgErr() {
return nil, errors.NotFound("reference %q is ambiguous", ref)
}
if cErr.IsBadObject() {
return nil, errors.NotFound("commit not found")
if cErr.IsAmbiguousArgErr() || cErr.IsBadObject() {
return []string{}, nil // return an empty list if reference doesn't exist
}
}
if err != nil {
return nil, processGitErrorf(err, "failed to trigger rev-list command")
}