diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/conf/static.go | 1 | ||||
-rw-r--r-- | internal/conf/testdata/TestInit.golden.ini | 1 | ||||
-rw-r--r-- | internal/db/repo.go | 21 | ||||
-rw-r--r-- | internal/form/user.go | 1 | ||||
-rw-r--r-- | internal/route/install.go | 2 |
5 files changed, 21 insertions, 5 deletions
diff --git a/internal/conf/static.go b/internal/conf/static.go index a514f7a6..24e9acab 100644 --- a/internal/conf/static.go +++ b/internal/conf/static.go @@ -321,6 +321,7 @@ type RepositoryOpts struct { EnableLocalPathMigration bool EnableRawFileRenderMode bool CommitsFetchConcurrency int + DefaultBranch string // Repository editor settings Editor struct { diff --git a/internal/conf/testdata/TestInit.golden.ini b/internal/conf/testdata/TestInit.golden.ini index 54178bf9..80f222df 100644 --- a/internal/conf/testdata/TestInit.golden.ini +++ b/internal/conf/testdata/TestInit.golden.ini @@ -44,6 +44,7 @@ DISABLE_HTTP_GIT=false ENABLE_LOCAL_PATH_MIGRATION=false ENABLE_RAW_FILE_RENDER_MODE=false COMMITS_FETCH_CONCURRENCY=0 +DEFAULT_BRANCH=master [repository.editor] LINE_WRAP_EXTENSIONS=.txt,.md,.markdown,.mdown,.mkd diff --git a/internal/db/repo.go b/internal/db/repo.go index cc73ae29..dbda2089 100644 --- a/internal/db/repo.go +++ b/internal/db/repo.go @@ -223,7 +223,7 @@ func (repo *Repository) AfterSet(colName string, _ xorm.Cell) { case "default_branch": // FIXME: use db migration to solve all at once. if repo.DefaultBranch == "" { - repo.DefaultBranch = "master" + repo.DefaultBranch = conf.Repository.DefaultBranch } case "num_closed_issues": repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues @@ -975,10 +975,9 @@ func getRepoInitFile(tp, name string) ([]byte, error) { func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptionsLegacy) error { // Clone to temporary path and do the init commit. - _, stderr, err := process.Exec( - fmt.Sprintf("initRepository(git clone): %s", repoPath), "git", "clone", repoPath, tmpDir) + err := git.Clone(repoPath, tmpDir, git.CloneOptions{}) if err != nil { - return fmt.Errorf("git clone: %v - %s", err, stderr) + return errors.Wrap(err, "clone") } // README @@ -1049,6 +1048,18 @@ func initRepository(e Engine, repoPath string, doer *User, repo *Repository, opt return fmt.Errorf("createDelegateHooks: %v", err) } + // Set default branch + _, err = git.SymbolicRef( + repoPath, + git.SymbolicRefOptions{ + Name: "HEAD", + Ref: git.RefsHeads + conf.Repository.DefaultBranch, + }, + ) + if err != nil { + return errors.Wrap(err, "set default branch") + } + tmpDir := filepath.Join(os.TempDir(), "gogs-"+repo.Name+"-"+com.ToStr(time.Now().Nanosecond())) // Initialize repository according to user's choice. @@ -1086,7 +1097,7 @@ func initRepository(e Engine, repoPath string, doer *User, repo *Repository, opt repo.IsBare = true } - repo.DefaultBranch = "master" + repo.DefaultBranch = conf.Repository.DefaultBranch if err = updateRepository(e, repo, false); err != nil { return fmt.Errorf("updateRepository: %v", err) } diff --git a/internal/form/user.go b/internal/form/user.go index fee0569d..1e3c4678 100644 --- a/internal/form/user.go +++ b/internal/form/user.go @@ -31,6 +31,7 @@ type Install struct { AppUrl string `binding:"Required"` LogRootPath string `binding:"Required"` EnableConsoleMode bool + DefaultBranch string SMTPHost string SMTPFrom string diff --git a/internal/route/install.go b/internal/route/install.go index 34a7cffc..15ff4439 100644 --- a/internal/route/install.go +++ b/internal/route/install.go @@ -161,6 +161,7 @@ func Install(c *context.Context) { f.HTTPPort = conf.Server.HTTPPort f.AppUrl = conf.Server.ExternalURL f.LogRootPath = conf.Log.RootPath + f.DefaultBranch = conf.Repository.DefaultBranch // E-mail service settings if conf.Email.Enabled { @@ -321,6 +322,7 @@ func InstallPost(c *context.Context, f form.Install) { cfg.Section("").Key("BRAND_NAME").SetValue(f.AppName) cfg.Section("repository").Key("ROOT").SetValue(f.RepoRootPath) + cfg.Section("repository").Key("DEFAULT_BRANCH").SetValue(f.DefaultBranch) cfg.Section("").Key("RUN_USER").SetValue(f.RunUser) cfg.Section("server").Key("DOMAIN").SetValue(f.Domain) cfg.Section("server").Key("HTTP_PORT").SetValue(f.HTTPPort) |