mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Fix panic when no master branch
This commit is contained in:
		@@ -5,7 +5,7 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language
 | 
				
			|||||||
 | 
					
 | 
				
			||||||

 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
##### Current version: 0.3.1 Alpha
 | 
					##### Current version: 0.3.2 Alpha
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### NOTICES
 | 
					### NOTICES
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。
 | 
				
			|||||||
 | 
					
 | 
				
			||||||

 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
##### 当前版本:0.3.1 Alpha
 | 
					##### 当前版本:0.3.2 Alpha
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 开发目的
 | 
					## 开发目的
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							@@ -19,7 +19,7 @@ import (
 | 
				
			|||||||
// Test that go1.2 tag above is included in builds. main.go refers to this definition.
 | 
					// Test that go1.2 tag above is included in builds. main.go refers to this definition.
 | 
				
			||||||
const go12tag = true
 | 
					const go12tag = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const APP_VER = "0.3.1.0501 Alpha"
 | 
					const APP_VER = "0.3.2.0501 Alpha"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
	base.AppVer = APP_VER
 | 
						base.AppVer = APP_VER
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -246,14 +246,17 @@ func CreateRepository(user *User, name, desc, lang, license string, private, mir
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	repo := &Repository{
 | 
						repo := &Repository{
 | 
				
			||||||
		OwnerId:       user.Id,
 | 
							OwnerId:     user.Id,
 | 
				
			||||||
		Name:          name,
 | 
							Name:        name,
 | 
				
			||||||
		LowerName:     strings.ToLower(name),
 | 
							LowerName:   strings.ToLower(name),
 | 
				
			||||||
		Description:   desc,
 | 
							Description: desc,
 | 
				
			||||||
		IsPrivate:     private,
 | 
							IsPrivate:   private,
 | 
				
			||||||
		IsBare:        lang == "" && license == "" && !initReadme,
 | 
							IsBare:      lang == "" && license == "" && !initReadme,
 | 
				
			||||||
		DefaultBranch: "master",
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if !repo.IsBare {
 | 
				
			||||||
 | 
							repo.DefaultBranch = "master"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	repoPath := RepoPath(user.Name, repo.Name)
 | 
						repoPath := RepoPath(user.Name, repo.Name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sess := orm.NewSession()
 | 
						sess := orm.NewSession()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -194,9 +194,17 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				refName = ctx.Repo.Repository.DefaultBranch
 | 
					 | 
				
			||||||
				if len(refName) == 0 {
 | 
									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
 | 
									goto detect
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,7 +41,7 @@
 | 
				
			|||||||
                        <label class="col-md-3 text-right">Default Branch</label>
 | 
					                        <label class="col-md-3 text-right">Default Branch</label>
 | 
				
			||||||
                        <div class="col-md-3">
 | 
					                        <div class="col-md-3">
 | 
				
			||||||
                            <select name="branch" id="repo-default-branch" class="form-control">
 | 
					                            <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}}
 | 
					                                {{range .Branches}}
 | 
				
			||||||
                                {{if eq . $.Repository.DefaultBranch}}{{else}}<option value="{{.}}">{{.}}</option>{{end}}
 | 
					                                {{if eq . $.Repository.DefaultBranch}}{{else}}<option value="{{.}}">{{.}}</option>{{end}}
 | 
				
			||||||
                                {{end}}
 | 
					                                {{end}}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user