]> source.dussan.org Git - gitea.git/commitdiff
Fix panic when no master branch
authorUnknown <joe2010xtmf@163.com>
Thu, 1 May 2014 16:03:10 +0000 (12:03 -0400)
committerUnknown <joe2010xtmf@163.com>
Thu, 1 May 2014 16:03:10 +0000 (12:03 -0400)
README.md
README_ZH.md
gogs.go
models/repo.go
modules/middleware/repo.go
templates/repo/setting.tmpl

index ec3621c83829b0bf8c563213daa5c5fc3c2d4a98..fbee7769dd0e589370526fbd9acda998bf4bd876 100644 (file)
--- 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
 
index 5d2da44aa4a6d684a985577604d7aeb852f39762..a58bb1b54e0f5b8e030e5612441e8673288e7de1 100644 (file)
@@ -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 af707862add0b853ef4a277a142a6d554db2bc69..5d44632773b89a1a63d842e7ae7fc4edf846bba8 100644 (file)
--- 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
index be889cba5f69cefa8387ef43983214b61420d852..35b3fde155ddafb9407a2278d683a316b1a67e5b 100644 (file)
@@ -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()
index e31deac5577174dc564984214fc3ea912c8c32d3..c31090b4d5976112eb91fe24410052bdcc65108a 100644 (file)
@@ -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
                        }
index afa66d1de14c011efb81773ce4fe1aa57fc34624..f0f041dee897016b7cf7e92f97ad511df0bc2b91 100644 (file)
@@ -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}}