Browse Source

Do not crash repo main page if the repo has no branch but has tag

pull/4551/head
Linquize 8 years ago
parent
commit
ded771331f
  1. 21
      pkg/context/repo.go

21
pkg/context/repo.go

@ -249,9 +249,13 @@ func RepoAssignment(pages ...bool) macaron.Handler {
c.Data["TagName"] = c.Repo.TagName
brs, err := c.Repo.GitRepo.GetBranches()
if err != nil {
c.ServerError("GetBranches", err)
brs = make([]string, 0)
_, err = c.Repo.GitRepo.GetTags()
if err != nil {
c.Handle(500, "GetBranches|GetTags", err)
return
}
}
c.Data["Branches"] = brs
c.Data["BrancheCount"] = len(brs)
@ -296,22 +300,35 @@ func RepoRef() macaron.Handler {
// Get default branch.
if len(c.Params("*")) == 0 {
isBranch := true
refName = c.Repo.Repository.DefaultBranch
if !c.Repo.GitRepo.IsBranchExist(refName) {
brs, err := c.Repo.GitRepo.GetBranches()
if err != nil {
c.Handle(500, "GetBranches", err)
brs, err = c.Repo.GitRepo.GetTags()
if err != nil {
c.Handle(500, "GetBranches|GetTags", err)
return
}
isBranch = false
}
refName = brs[0]
}
if isBranch {
c.Repo.Commit, err = c.Repo.GitRepo.GetBranchCommit(refName)
} else {
c.Repo.Commit, err = c.Repo.GitRepo.GetTagCommit(refName)
}
if err != nil {
c.Handle(500, "GetBranchCommit", err)
return
}
c.Repo.CommitID = c.Repo.Commit.ID.String()
if (isBranch) {
c.Repo.IsViewBranch = true
} else {
c.Repo.IsViewTag = true
}
} else {
hasMatched := false

Loading…
Cancel
Save