diff options
author | Unknown <joe2010xtmf@163.com> | 2014-05-01 12:03:10 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-05-01 12:03:10 -0400 |
commit | 75109bbd653f69e4a924b6654e564341e4bcf229 (patch) | |
tree | fa3a334790fc5ed244ffa9fd0fff6ea8733a3a25 /modules/middleware | |
parent | 0a187dbef5d2480f8d47b8013f6e21e06ea18cbd (diff) | |
download | gitea-75109bbd653f69e4a924b6654e564341e4bcf229.tar.gz gitea-75109bbd653f69e4a924b6654e564341e4bcf229.zip |
Fix panic when no master branch
Diffstat (limited to 'modules/middleware')
-rw-r--r-- | modules/middleware/repo.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index e31deac557..c31090b4d5 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -194,9 +194,17 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler { } } else { - refName = ctx.Repo.Repository.DefaultBranch if len(refName) == 0 { - refName = "master" + if gitRepo.IsBranchExist(ctx.Repo.Repository.DefaultBranch) { + refName = ctx.Repo.Repository.DefaultBranch + } else { + brs, err := gitRepo.GetBranches() + if err != nil { + ctx.Handle(500, "RepoAssignment(GetBranches))", err) + return + } + refName = brs[0] + } } goto detect } |