From 973b7f62989d16960fa918f5758ff2998317c352 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Wed, 4 Oct 2023 22:27:42 +0800 Subject: [PATCH] When comparing with an non-exist repository, return 404 but 500 (#27437) (#27441) Backport #27437 by @lunny Co-authored-by: Lunny Xiao --- routers/web/repo/compare.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 4f2e0594be..e3aa94e394 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -251,7 +251,6 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { isSameRepo = true ci.HeadUser = ctx.Repo.Owner ci.HeadBranch = headInfos[0] - } else if len(headInfos) == 2 { headInfosSplit := strings.Split(headInfos[0], "/") if len(headInfosSplit) == 1 { @@ -406,6 +405,9 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { return nil } defer ci.HeadGitRepo.Close() + } else { + ctx.NotFound("ParseCompareInfo", nil) + return nil } ctx.Data["HeadRepo"] = ci.HeadRepo