diff options
author | Vamsi Atluri <vamc19@gmail.com> | 2023-02-11 14:07:24 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-11 16:37:24 +0800 |
commit | ef1fe1bb3bb495cef55c67f9af13065e2415bea0 (patch) | |
tree | c97cf90200c47f9ed8fc5a0785d30c65583d6621 /internal/db | |
parent | 8350daf505b837984397679f07ccc2324b4d2451 (diff) |
conf: add new config option for default branch name (#7291)
Co-authored-by: Vamsi Atluri <me@vamc19.dev>
Co-authored-by: Joe Chen <jc@unknwon.io>
Diffstat (limited to 'internal/db')
-rw-r--r-- | internal/db/repo.go | 21 |
1 files changed, 16 insertions, 5 deletions
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) } |