Skip to content

Commit ef1fe1b

Browse files
vamc19unknwon
andauthored
conf: add new config option for default branch name (gogs#7291)
Co-authored-by: Vamsi Atluri <me@vamc19.dev> Co-authored-by: Joe Chen <jc@unknwon.io>
1 parent 8350daf commit ef1fe1b

File tree

12 files changed

+34
-11
lines changed

12 files changed

+34
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All notable changes to Gogs are documented in this file.
1111
- New API endpoint `PUT /repos/:owner/:repo/contents/:path` for creating and update repository contents. [#5967](https://github.com/gogs/gogs/issues/5967)
1212
- New configuration option `[git.timeout] DIFF` for customizing operation timeout of `git diff`. [#6315](https://github.com/gogs/gogs/issues/6315)
1313
- New configuration option `[server] SSH_SERVER_MACS` for setting list of accepted MACs for connections to builtin SSH server. [#6434](https://github.com/gogs/gogs/issues/6434)
14+
- New configuration option `[repository] DEFAULT_BRANCH` for setting default branch name for new repositories. [#7291](https://github.com/gogs/gogs/issues/7291)
1415
- Support specifying custom schema for PostgreSQL. [#6695](https://github.com/gogs/gogs/pull/6695)
1516
- Support rendering Mermaid diagrams in Markdown. [#6776](https://github.com/gogs/gogs/pull/6776)
1617
- Docker: Allow passing extra arguments to the `backup` command. [#7060](https://github.com/gogs/gogs/pull/7060)

conf/app.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ ENABLE_RAW_FILE_RENDER_MODE = false
115115
; fetch request. Usually, the value depend of how many CPU (cores) you have. If
116116
; the value is non-positive, it matches the number of CPUs available to the application.
117117
COMMITS_FETCH_CONCURRENCY = 0
118+
; Default branch name when creating new repositories.
119+
DEFAULT_BRANCH = master
118120

119121
[repository.editor]
120122
; List of file extensions that should have line wraps in the CodeMirror editor.

conf/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ log_root_path = Log Path
8888
log_root_path_helper = Directory to write log files to.
8989
enable_console_mode = Enable Console Mode
9090
enable_console_mode_popup = In addition to file mode, also print logs to console.
91+
default_branch = Default Branch
9192
9293
optional_title = Optional Settings
9394
email_title = Email Service Settings

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/go-macaron/toolbox v0.0.0-20190813233741-94defb8383c6
1818
github.com/gogs/chardet v0.0.0-20150115103509-2404f7772561
1919
github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14
20-
github.com/gogs/git-module v1.7.1
20+
github.com/gogs/git-module v1.7.2
2121
github.com/gogs/go-gogs-client v0.0.0-20200128182646-c69cb7680fd4
2222
github.com/gogs/go-libravatar v0.0.0-20191106065024-33a75213d0a0
2323
github.com/gogs/minwinsvc v0.0.0-20170301035411-95be6356811a

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ github.com/gogs/chardet v0.0.0-20150115103509-2404f7772561 h1:aBzukfDxQlCTVS0NBU
153153
github.com/gogs/chardet v0.0.0-20150115103509-2404f7772561/go.mod h1:Pcatq5tYkCW2Q6yrR2VRHlbHpZ/R4/7qyL1TCF7vl14=
154154
github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14 h1:yXtpJr/LV6PFu4nTLgfjQdcMdzjbqqXMEnHfq0Or6p8=
155155
github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14/go.mod h1:jPoNZLWDAqA5N3G5amEoiNbhVrmM+ZQEcnQvNQ2KaZk=
156-
github.com/gogs/git-module v1.7.1 h1:KzK3oZ9YMVV6HyWxStFTTcFpCKsFRb8424qKTpa59XM=
157-
github.com/gogs/git-module v1.7.1/go.mod h1:Y3rsSqtFZEbn7lp+3gWf42GKIY1eNTtLt7JrmOy0yAQ=
156+
github.com/gogs/git-module v1.7.2 h1:9SJ5imgMRtPrqu2ubmn9Ll5t7zZPftlNfnPOK32fFsQ=
157+
github.com/gogs/git-module v1.7.2/go.mod h1:Y3rsSqtFZEbn7lp+3gWf42GKIY1eNTtLt7JrmOy0yAQ=
158158
github.com/gogs/go-gogs-client v0.0.0-20200128182646-c69cb7680fd4 h1:C7NryI/RQhsIWwC2bHN601P1wJKeuQ6U/UCOYTn3Cic=
159159
github.com/gogs/go-gogs-client v0.0.0-20200128182646-c69cb7680fd4/go.mod h1:fR6z1Ie6rtF7kl/vBYMfgD5/G5B1blui7z426/sj2DU=
160160
github.com/gogs/go-libravatar v0.0.0-20191106065024-33a75213d0a0 h1:K02vod+sn3M1OOkdqi2tPxN2+xESK4qyITVQ3JkGEv4=

internal/conf/static.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ type RepositoryOpts struct {
321321
EnableLocalPathMigration bool
322322
EnableRawFileRenderMode bool
323323
CommitsFetchConcurrency int
324+
DefaultBranch string
324325

325326
// Repository editor settings
326327
Editor struct {

internal/conf/testdata/TestInit.golden.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ DISABLE_HTTP_GIT=false
4444
ENABLE_LOCAL_PATH_MIGRATION=false
4545
ENABLE_RAW_FILE_RENDER_MODE=false
4646
COMMITS_FETCH_CONCURRENCY=0
47+
DEFAULT_BRANCH=master
4748

4849
[repository.editor]
4950
LINE_WRAP_EXTENSIONS=.txt,.md,.markdown,.mdown,.mkd

internal/db/repo.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
223223
case "default_branch":
224224
// FIXME: use db migration to solve all at once.
225225
if repo.DefaultBranch == "" {
226-
repo.DefaultBranch = "master"
226+
repo.DefaultBranch = conf.Repository.DefaultBranch
227227
}
228228
case "num_closed_issues":
229229
repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
@@ -975,10 +975,9 @@ func getRepoInitFile(tp, name string) ([]byte, error) {
975975

976976
func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptionsLegacy) error {
977977
// Clone to temporary path and do the init commit.
978-
_, stderr, err := process.Exec(
979-
fmt.Sprintf("initRepository(git clone): %s", repoPath), "git", "clone", repoPath, tmpDir)
978+
err := git.Clone(repoPath, tmpDir, git.CloneOptions{})
980979
if err != nil {
981-
return fmt.Errorf("git clone: %v - %s", err, stderr)
980+
return errors.Wrap(err, "clone")
982981
}
983982

984983
// README
@@ -1049,6 +1048,18 @@ func initRepository(e Engine, repoPath string, doer *User, repo *Repository, opt
10491048
return fmt.Errorf("createDelegateHooks: %v", err)
10501049
}
10511050

1051+
// Set default branch
1052+
_, err = git.SymbolicRef(
1053+
repoPath,
1054+
git.SymbolicRefOptions{
1055+
Name: "HEAD",
1056+
Ref: git.RefsHeads + conf.Repository.DefaultBranch,
1057+
},
1058+
)
1059+
if err != nil {
1060+
return errors.Wrap(err, "set default branch")
1061+
}
1062+
10521063
tmpDir := filepath.Join(os.TempDir(), "gogs-"+repo.Name+"-"+com.ToStr(time.Now().Nanosecond()))
10531064

10541065
// Initialize repository according to user's choice.
@@ -1086,7 +1097,7 @@ func initRepository(e Engine, repoPath string, doer *User, repo *Repository, opt
10861097
repo.IsBare = true
10871098
}
10881099

1089-
repo.DefaultBranch = "master"
1100+
repo.DefaultBranch = conf.Repository.DefaultBranch
10901101
if err = updateRepository(e, repo, false); err != nil {
10911102
return fmt.Errorf("updateRepository: %v", err)
10921103
}

internal/form/user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Install struct {
3131
AppUrl string `binding:"Required"`
3232
LogRootPath string `binding:"Required"`
3333
EnableConsoleMode bool
34+
DefaultBranch string
3435

3536
SMTPHost string
3637
SMTPFrom string

internal/route/install.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func Install(c *context.Context) {
161161
f.HTTPPort = conf.Server.HTTPPort
162162
f.AppUrl = conf.Server.ExternalURL
163163
f.LogRootPath = conf.Log.RootPath
164+
f.DefaultBranch = conf.Repository.DefaultBranch
164165

165166
// E-mail service settings
166167
if conf.Email.Enabled {
@@ -321,6 +322,7 @@ func InstallPost(c *context.Context, f form.Install) {
321322

322323
cfg.Section("").Key("BRAND_NAME").SetValue(f.AppName)
323324
cfg.Section("repository").Key("ROOT").SetValue(f.RepoRootPath)
325+
cfg.Section("repository").Key("DEFAULT_BRANCH").SetValue(f.DefaultBranch)
324326
cfg.Section("").Key("RUN_USER").SetValue(f.RunUser)
325327
cfg.Section("server").Key("DOMAIN").SetValue(f.Domain)
326328
cfg.Section("server").Key("HTTP_PORT").SetValue(f.HTTPPort)

0 commit comments

Comments
 (0)