summaryrefslogtreecommitdiffstats
path: root/modules/middleware/repo.go
diff options
context:
space:
mode:
authorJustin Nuß <justin.nuss@hmmh.de>2014-07-22 14:46:04 +0200
committerJustin Nuß <justin.nuss@hmmh.de>2014-07-22 14:46:04 +0200
commit267870537dd7dc3cc0b7b81c2ac1a7be835c0f92 (patch)
tree22e64464bff3d6487b7ddd0130b7308e10992973 /modules/middleware/repo.go
parent536f65b8ad700dc919295562dd72d5d4ea750506 (diff)
downloadgitea-267870537dd7dc3cc0b7b81c2ac1a7be835c0f92.tar.gz
gitea-267870537dd7dc3cc0b7b81c2ac1a7be835c0f92.zip
Fix issue #278. Fall back to (default) branch for context data, if no branch selected
Diffstat (limited to 'modules/middleware/repo.go')
-rw-r--r--modules/middleware/repo.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go
index cf8ce412e5..c6febffb2e 100644
--- a/modules/middleware/repo.go
+++ b/modules/middleware/repo.go
@@ -248,13 +248,24 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
ctx.Repo.IsWatching = models.IsWatching(ctx.User.Id, repo.Id)
}
- ctx.Data["BranchName"] = ctx.Repo.BranchName
ctx.Data["TagName"] = ctx.Repo.TagName
brs, err := ctx.Repo.GitRepo.GetBranches()
if err != nil {
log.Error("RepoAssignment(GetBranches): %v", err)
}
ctx.Data["Branches"] = brs
+
+ // If not branch selected, try default one.
+ // If default branch doesn't exists, fall back to some other branch.
+ if ctx.Repo.BranchName == "" {
+ if ctx.Repo.Repository.DefaultBranch != "" && gitRepo.IsBranchExist(ctx.Repo.Repository.DefaultBranch) {
+ ctx.Repo.BranchName = ctx.Repo.Repository.DefaultBranch
+ } else if len(brs) > 0 {
+ ctx.Repo.BranchName = brs[0]
+ }
+ }
+
+ ctx.Data["BranchName"] = ctx.Repo.BranchName
ctx.Data["CommitId"] = ctx.Repo.CommitId
ctx.Data["IsRepositoryWatching"] = ctx.Repo.IsWatching
}