summaryrefslogtreecommitdiffstats
path: root/modules/context/repo.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/context/repo.go')
-rw-r--r--modules/context/repo.go35
1 files changed, 20 insertions, 15 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 3caf583f83..f4af19a0e8 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -146,6 +146,9 @@ func (r *Repository) FileExists(path string, branch string) (bool, error) {
// GetEditorconfig returns the .editorconfig definition if found in the
// HEAD of the default repo branch.
func (r *Repository) GetEditorconfig() (*editorconfig.Editorconfig, error) {
+ if r.GitRepo == nil {
+ return nil, nil
+ }
commit, err := r.GitRepo.GetBranchCommit(r.Repository.DefaultBranch)
if err != nil {
return nil, err
@@ -358,12 +361,6 @@ func RepoAssignment() macaron.Handler {
return
}
- gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName))
- if err != nil {
- ctx.ServerError("RepoAssignment Invalid repo "+models.RepoPath(userName, repoName), err)
- return
- }
- ctx.Repo.GitRepo = gitRepo
ctx.Repo.RepoLink = repo.Link()
ctx.Data["RepoLink"] = ctx.Repo.RepoLink
ctx.Data["RepoRelPath"] = ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name
@@ -373,13 +370,6 @@ func RepoAssignment() macaron.Handler {
ctx.Data["RepoExternalIssuesLink"] = unit.ExternalTrackerConfig().ExternalTrackerURL
}
- tags, err := ctx.Repo.GitRepo.GetTags()
- if err != nil {
- ctx.ServerError("GetTags", err)
- return
- }
- ctx.Data["Tags"] = tags
-
count, err := models.GetReleaseCountByRepoID(ctx.Repo.Repository.ID, models.FindReleasesOptions{
IncludeDrafts: false,
IncludeTags: true,
@@ -425,12 +415,25 @@ func RepoAssignment() macaron.Handler {
}
// repo is empty and display enable
- if ctx.Repo.Repository.IsEmpty {
+ if ctx.Repo.Repository.IsEmpty || ctx.Repo.Repository.IsBeingCreated() {
ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
return
}
- ctx.Data["TagName"] = ctx.Repo.TagName
+ gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName))
+ if err != nil {
+ ctx.ServerError("RepoAssignment Invalid repo "+models.RepoPath(userName, repoName), err)
+ return
+ }
+ ctx.Repo.GitRepo = gitRepo
+
+ tags, err := ctx.Repo.GitRepo.GetTags()
+ if err != nil {
+ ctx.ServerError("GetTags", err)
+ return
+ }
+ ctx.Data["Tags"] = tags
+
brs, err := ctx.Repo.GitRepo.GetBranches()
if err != nil {
ctx.ServerError("GetBranches", err)
@@ -439,6 +442,8 @@ func RepoAssignment() macaron.Handler {
ctx.Data["Branches"] = brs
ctx.Data["BranchesCount"] = len(brs)
+ ctx.Data["TagName"] = ctx.Repo.TagName
+
// If not branch selected, try default one.
// If default branch doesn't exists, fall back to some other branch.
if len(ctx.Repo.BranchName) == 0 {