From 5d5df27457e00680e8efa78d9078a61ef2c27d2b Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Wed, 16 Oct 2019 10:43:35 +0100 Subject: [PATCH] Ensure that GitRepo is set on Empty repositories Both issues/new and settings/hooks/git expect `ctx.Repo.GitRepo` to be set. This PR changes the context code to open the GitRepo. Fixes #8538 --- modules/context/repo.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index e891e7b85cd58..e2aebc019cddf 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -414,8 +414,8 @@ func RepoAssignment() macaron.Handler { } } - // repo is empty and display enable - if ctx.Repo.Repository.IsEmpty || ctx.Repo.Repository.IsBeingCreated() { + // Disable everything when the repo is being created + if ctx.Repo.Repository.IsBeingCreated() { ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch return } @@ -427,6 +427,12 @@ func RepoAssignment() macaron.Handler { } ctx.Repo.GitRepo = gitRepo + // Stop at this point when the repo is empty. + if ctx.Repo.Repository.IsEmpty { + ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch + return + } + tags, err := ctx.Repo.GitRepo.GetTags() if err != nil { ctx.ServerError("GetTags", err)