diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-04-24 13:26:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-24 13:26:50 +0800 |
commit | 8b3632435ef72c351af34a154b13511b34323471 (patch) | |
tree | 7bf8a6c75ad6dbf52881c4b5de6533062fe9a7f2 | |
parent | 2ad9ef4984f0b68ef38241fd6b557d8427d851d8 (diff) | |
download | gitea-8b3632435ef72c351af34a154b13511b34323471.tar.gz gitea-8b3632435ef72c351af34a154b13511b34323471.zip |
Fix a panic bug when head repository deleting (#30674)
When visiting a pull request files which head repository has been
deleted, it will panic because headrepo is nil.
-rw-r--r-- | routers/web/repo/pull.go | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 71f25db11b..acdba4bcdc 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -863,21 +863,21 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi if pull.HeadRepo != nil { ctx.Data["SourcePath"] = pull.HeadRepo.Link() + "/src/branch/" + util.PathEscapeSegments(pull.HeadBranch) - } - if !pull.HasMerged && ctx.Doer != nil { - perm, err := access_model.GetUserRepoPermission(ctx, pull.HeadRepo, ctx.Doer) - if err != nil { - ctx.ServerError("GetUserRepoPermission", err) - return - } + if !pull.HasMerged && ctx.Doer != nil { + perm, err := access_model.GetUserRepoPermission(ctx, pull.HeadRepo, ctx.Doer) + if err != nil { + ctx.ServerError("GetUserRepoPermission", err) + return + } - if perm.CanWrite(unit.TypeCode) || issues_model.CanMaintainerWriteToBranch(ctx, perm, pull.HeadBranch, ctx.Doer) { - ctx.Data["CanEditFile"] = true - ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file") - ctx.Data["HeadRepoLink"] = pull.HeadRepo.Link() - ctx.Data["HeadBranchName"] = pull.HeadBranch - ctx.Data["BackToLink"] = setting.AppSubURL + ctx.Req.URL.RequestURI() + if perm.CanWrite(unit.TypeCode) || issues_model.CanMaintainerWriteToBranch(ctx, perm, pull.HeadBranch, ctx.Doer) { + ctx.Data["CanEditFile"] = true + ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file") + ctx.Data["HeadRepoLink"] = pull.HeadRepo.Link() + ctx.Data["HeadBranchName"] = pull.HeadBranch + ctx.Data["BackToLink"] = setting.AppSubURL + ctx.Req.URL.RequestURI() + } } } } |