summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-01 12:03:10 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-01 12:03:10 -0400
commit75109bbd653f69e4a924b6654e564341e4bcf229 (patch)
treefa3a334790fc5ed244ffa9fd0fff6ea8733a3a25
parent0a187dbef5d2480f8d47b8013f6e21e06ea18cbd (diff)
downloadgitea-75109bbd653f69e4a924b6654e564341e4bcf229.tar.gz
gitea-75109bbd653f69e4a924b6654e564341e4bcf229.zip
Fix panic when no master branch
-rw-r--r--README.md2
-rw-r--r--README_ZH.md2
-rw-r--r--gogs.go2
-rw-r--r--models/repo.go17
-rw-r--r--modules/middleware/repo.go12
-rw-r--r--templates/repo/setting.tmpl2
6 files changed, 24 insertions, 13 deletions
diff --git a/README.md b/README.md
index ec3621c838..fbee7769dd 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language
![Demo](http://gowalker.org/public/gogs_demo.gif)
-##### Current version: 0.3.1 Alpha
+##### Current version: 0.3.2 Alpha
### NOTICES
diff --git a/README_ZH.md b/README_ZH.md
index 5d2da44aa4..a58bb1b54e 100644
--- a/README_ZH.md
+++ b/README_ZH.md
@@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。
![Demo](http://gowalker.org/public/gogs_demo.gif)
-##### 当前版本:0.3.1 Alpha
+##### 当前版本:0.3.2 Alpha
## 开发目的
diff --git a/gogs.go b/gogs.go
index af707862ad..5d44632773 100644
--- a/gogs.go
+++ b/gogs.go
@@ -19,7 +19,7 @@ import (
// Test that go1.2 tag above is included in builds. main.go refers to this definition.
const go12tag = true
-const APP_VER = "0.3.1.0501 Alpha"
+const APP_VER = "0.3.2.0501 Alpha"
func init() {
base.AppVer = APP_VER
diff --git a/models/repo.go b/models/repo.go
index be889cba5f..35b3fde155 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -246,14 +246,17 @@ func CreateRepository(user *User, name, desc, lang, license string, private, mir
}
repo := &Repository{
- OwnerId: user.Id,
- Name: name,
- LowerName: strings.ToLower(name),
- Description: desc,
- IsPrivate: private,
- IsBare: lang == "" && license == "" && !initReadme,
- DefaultBranch: "master",
+ OwnerId: user.Id,
+ Name: name,
+ LowerName: strings.ToLower(name),
+ Description: desc,
+ IsPrivate: private,
+ IsBare: lang == "" && license == "" && !initReadme,
}
+ if !repo.IsBare {
+ repo.DefaultBranch = "master"
+ }
+
repoPath := RepoPath(user.Name, repo.Name)
sess := orm.NewSession()
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
}
diff --git a/templates/repo/setting.tmpl b/templates/repo/setting.tmpl
index afa66d1de1..f0f041dee8 100644
--- a/templates/repo/setting.tmpl
+++ b/templates/repo/setting.tmpl
@@ -41,7 +41,7 @@
<label class="col-md-3 text-right">Default Branch</label>
<div class="col-md-3">
<select name="branch" id="repo-default-branch" class="form-control">
- <option value="{{.Repository.DefaultBranch}}">{{.Repository.DefaultBranch}}</option>
+ {{if .Repository.DefaultBranch}}<option value="{{.Repository.DefaultBranch}}">{{.Repository.DefaultBranch}}</option>{{end}}
{{range .Branches}}
{{if eq . $.Repository.DefaultBranch}}{{else}}<option value="{{.}}">{{.}}</option>{{end}}
{{end}}