summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-03-03 14:22:45 -0500
committerUnknwon <u@gogs.io>2016-03-03 14:22:45 -0500
commit434614506e7edee8d75d747dfe2ac59458f669fe (patch)
treec1765c0afbeade76bad6c8dc805116bb2cc8ca03
parentc9901bbba5dd2761f2920d6a122799ee051fc7cd (diff)
parent7f2733fa1b412593f676cd04a1c9166b51e56640 (diff)
downloadgitea-434614506e7edee8d75d747dfe2ac59458f669fe.tar.gz
gitea-434614506e7edee8d75d747dfe2ac59458f669fe.zip
Merge pull request #2744 from joshfng/mirror-default-branch
Set DefaultBranch to master when importing a new repo.
-rw-r--r--models/repo.go50
1 files changed, 25 insertions, 25 deletions
diff --git a/models/repo.go b/models/repo.go
index cb040d5b34..22336d3c1a 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -662,6 +662,31 @@ func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) {
return repo, fmt.Errorf("Clone: %v", err)
}
+ // Check if repository is empty.
+ _, stderr, err := com.ExecCmdDir(repoPath, "git", "log", "-1")
+ if err != nil {
+ if strings.Contains(stderr, "fatal: bad default revision 'HEAD'") {
+ repo.IsBare = true
+ } else {
+ return repo, fmt.Errorf("check bare: %v - %s", err, stderr)
+ }
+ }
+
+ if !repo.IsBare {
+ // Try to get HEAD branch and set it as default branch.
+ gitRepo, err := git.OpenRepository(repoPath)
+ if err != nil {
+ return repo, fmt.Errorf("OpenRepository: %v", err)
+ }
+ headBranch, err := gitRepo.GetHEADBranch()
+ if err != nil {
+ return repo, fmt.Errorf("GetHEADBranch: %v", err)
+ }
+ if headBranch != nil {
+ repo.DefaultBranch = headBranch.Name
+ }
+ }
+
if opts.IsMirror {
if _, err = x.InsertOne(&Mirror{
RepoID: repo.ID,
@@ -696,31 +721,6 @@ func CleanUpMigrateInfo(repo *Repository, repoPath string) (*Repository, error)
return repo, fmt.Errorf("save config file: %v", err)
}
- // Check if repository is empty.
- _, stderr, err := com.ExecCmdDir(repoPath, "git", "log", "-1")
- if err != nil {
- if strings.Contains(stderr, "fatal: bad default revision 'HEAD'") {
- repo.IsBare = true
- } else {
- return repo, fmt.Errorf("check bare: %v - %s", err, stderr)
- }
- }
-
- // Try to get HEAD branch and set it as default branch.
- gitRepo, err := git.OpenRepository(repoPath)
- if err != nil {
- log.Error(4, "OpenRepository: %v", err)
- return repo, nil
- }
- headBranch, err := gitRepo.GetHEADBranch()
- if err != nil {
- log.Error(4, "GetHEADBranch: %v", err)
- return repo, nil
- }
- if headBranch != nil {
- repo.DefaultBranch = headBranch.Name
- }
-
return repo, UpdateRepository(repo, false)
}