Skip to content

Commit 8b36324

Browse files
authored
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.
1 parent 2ad9ef4 commit 8b36324

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

routers/web/repo/pull.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -863,21 +863,21 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
863863

864864
if pull.HeadRepo != nil {
865865
ctx.Data["SourcePath"] = pull.HeadRepo.Link() + "/src/branch/" + util.PathEscapeSegments(pull.HeadBranch)
866-
}
867866

868-
if !pull.HasMerged && ctx.Doer != nil {
869-
perm, err := access_model.GetUserRepoPermission(ctx, pull.HeadRepo, ctx.Doer)
870-
if err != nil {
871-
ctx.ServerError("GetUserRepoPermission", err)
872-
return
873-
}
867+
if !pull.HasMerged && ctx.Doer != nil {
868+
perm, err := access_model.GetUserRepoPermission(ctx, pull.HeadRepo, ctx.Doer)
869+
if err != nil {
870+
ctx.ServerError("GetUserRepoPermission", err)
871+
return
872+
}
874873

875-
if perm.CanWrite(unit.TypeCode) || issues_model.CanMaintainerWriteToBranch(ctx, perm, pull.HeadBranch, ctx.Doer) {
876-
ctx.Data["CanEditFile"] = true
877-
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
878-
ctx.Data["HeadRepoLink"] = pull.HeadRepo.Link()
879-
ctx.Data["HeadBranchName"] = pull.HeadBranch
880-
ctx.Data["BackToLink"] = setting.AppSubURL + ctx.Req.URL.RequestURI()
874+
if perm.CanWrite(unit.TypeCode) || issues_model.CanMaintainerWriteToBranch(ctx, perm, pull.HeadBranch, ctx.Doer) {
875+
ctx.Data["CanEditFile"] = true
876+
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
877+
ctx.Data["HeadRepoLink"] = pull.HeadRepo.Link()
878+
ctx.Data["HeadBranchName"] = pull.HeadBranch
879+
ctx.Data["BackToLink"] = setting.AppSubURL + ctx.Req.URL.RequestURI()
880+
}
881881
}
882882
}
883883
}

0 commit comments

Comments
 (0)