Skip to content

Commit 75109bb

Browse files
committed
Fix panic when no master branch
1 parent 0a187db commit 75109bb

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language
55

66
![Demo](http://gowalker.org/public/gogs_demo.gif)
77

8-
##### Current version: 0.3.1 Alpha
8+
##### Current version: 0.3.2 Alpha
99

1010
### NOTICES
1111

README_ZH.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。
55

66
![Demo](http://gowalker.org/public/gogs_demo.gif)
77

8-
##### 当前版本:0.3.1 Alpha
8+
##### 当前版本:0.3.2 Alpha
99

1010
## 开发目的
1111

gogs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
// Test that go1.2 tag above is included in builds. main.go refers to this definition.
2020
const go12tag = true
2121

22-
const APP_VER = "0.3.1.0501 Alpha"
22+
const APP_VER = "0.3.2.0501 Alpha"
2323

2424
func init() {
2525
base.AppVer = APP_VER

models/repo.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,17 @@ func CreateRepository(user *User, name, desc, lang, license string, private, mir
246246
}
247247

248248
repo := &Repository{
249-
OwnerId: user.Id,
250-
Name: name,
251-
LowerName: strings.ToLower(name),
252-
Description: desc,
253-
IsPrivate: private,
254-
IsBare: lang == "" && license == "" && !initReadme,
255-
DefaultBranch: "master",
249+
OwnerId: user.Id,
250+
Name: name,
251+
LowerName: strings.ToLower(name),
252+
Description: desc,
253+
IsPrivate: private,
254+
IsBare: lang == "" && license == "" && !initReadme,
256255
}
256+
if !repo.IsBare {
257+
repo.DefaultBranch = "master"
258+
}
259+
257260
repoPath := RepoPath(user.Name, repo.Name)
258261

259262
sess := orm.NewSession()

modules/middleware/repo.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,17 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
194194
}
195195

196196
} else {
197-
refName = ctx.Repo.Repository.DefaultBranch
198197
if len(refName) == 0 {
199-
refName = "master"
198+
if gitRepo.IsBranchExist(ctx.Repo.Repository.DefaultBranch) {
199+
refName = ctx.Repo.Repository.DefaultBranch
200+
} else {
201+
brs, err := gitRepo.GetBranches()
202+
if err != nil {
203+
ctx.Handle(500, "RepoAssignment(GetBranches))", err)
204+
return
205+
}
206+
refName = brs[0]
207+
}
200208
}
201209
goto detect
202210
}

templates/repo/setting.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<label class="col-md-3 text-right">Default Branch</label>
4242
<div class="col-md-3">
4343
<select name="branch" id="repo-default-branch" class="form-control">
44-
<option value="{{.Repository.DefaultBranch}}">{{.Repository.DefaultBranch}}</option>
44+
{{if .Repository.DefaultBranch}}<option value="{{.Repository.DefaultBranch}}">{{.Repository.DefaultBranch}}</option>{{end}}
4545
{{range .Branches}}
4646
{{if eq . $.Repository.DefaultBranch}}{{else}}<option value="{{.}}">{{.}}</option>{{end}}
4747
{{end}}

0 commit comments

Comments
 (0)