fix: refactor git error handling and make archive streaming handle non-existing commit id (#38007)

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Sandro
2026-06-06 13:06:08 +02:00
committed by GitHub
parent e88650cfcf
commit 743bbaa9c2
10 changed files with 57 additions and 50 deletions
+1 -1
View File
@@ -1435,7 +1435,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
compareInfo, err = git_service.GetCompareInfo(ctx, pr.BaseRepo, pr.BaseRepo, baseGitRepo, git.RefNameFromBranch(pr.BaseBranch), git.RefName(pr.GetGitHeadRefName()), false, false)
}
if gitcmd.StderrHasPrefix(err, "fatal: bad revision") {
if gitcmd.IsStderr(err, gitcmd.StderrBadRevision) {
ctx.APIError(http.StatusNotFound, "invalid base branch or revision")
return
} else if err != nil {
+1 -3
View File
@@ -376,9 +376,7 @@ func (prInfo *pullRequestViewInfo) prepareViewFillCompareInfo(ctx *context.Conte
pull := prInfo.issue.PullRequest
prInfo.CompareInfo, err = git_service.GetCompareInfo(ctx, ctx.Repo.Repository, ctx.Repo.Repository, ctx.Repo.GitRepo, baseRef, git.RefName(pull.GetGitHeadRefName()), false, false)
if err != nil {
isKnownErrorForBroken := gitcmd.IsStdErrorNotValidObjectName(err) ||
// fatal: ambiguous argument 'origin': unknown revision or path not in the working tree.
gitcmd.StderrContains(err, "unknown revision or path not in the working tree")
isKnownErrorForBroken := gitcmd.IsStderr(err, gitcmd.StderrNotValidObjectName) || gitcmd.IsStderr(err, gitcmd.StderrUnknownRevisionOrPath)
if !isKnownErrorForBroken {
log.Error("GetCompareInfo: %v", err)
}