Skip to content

Commit 7dc8db9

Browse files
Global default branch setting (#11918) (#11937)
* Global default branch setting (#11918) * Global default branch setting * add to app.ini example per @silverwind * update per @lunny Co-authored-by: John Olheiser <[email protected]> * Update modules/setting/repository.go Co-authored-by: John Olheiser <[email protected]>
1 parent ecad970 commit 7dc8db9

File tree

7 files changed

+11
-3
lines changed

7 files changed

+11
-3
lines changed

custom/conf/app.ini.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ DISABLED_REPO_UNITS =
5050
DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki
5151
; Prefix archive files by placing them in a directory named after the repository
5252
PREFIX_ARCHIVE_FILES = true
53+
; The default branch name of new repositories
54+
DEFAULT_BRANCH=master
5355

5456
[repository.editor]
5557
; List of file extensions for which lines should be wrapped in the Monaco editor

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
6969
- `ENABLE_PUSH_CREATE_USER`: **false**: Allow users to push local repositories to Gitea and have them automatically created for a user.
7070
- `ENABLE_PUSH_CREATE_ORG`: **false**: Allow users to push local repositories to Gitea and have them automatically created for an org.
7171
- `PREFIX_ARCHIVE_FILES`: **true**: Prefix archive files by placing them in a directory named after the repository.
72+
- `DEFAULT_BRANCH`: **master**: Default branch name of all repositories.
7273

7374
### Repository - Pull Request (`repository.pull-request`)
7475

modules/repository/init.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"code.gitea.io/gitea/models"
1717
"code.gitea.io/gitea/modules/git"
1818
"code.gitea.io/gitea/modules/log"
19+
"code.gitea.io/gitea/modules/setting"
1920

2021
"github.com/mcuadros/go-version"
2122
"github.com/unknwon/com"
@@ -147,7 +148,7 @@ func initRepoCommit(tmpPath string, repo *models.Repository, u *models.User, def
147148
}
148149

149150
if len(defaultBranch) == 0 {
150-
defaultBranch = "master"
151+
defaultBranch = setting.Repository.DefaultBranch
151152
}
152153

153154
if stdout, err := git.NewCommand("push", "origin", "master:"+defaultBranch).

modules/setting/repository.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var (
4040
DisabledRepoUnits []string
4141
DefaultRepoUnits []string
4242
PrefixArchiveFiles bool
43+
DefaultBranch string
4344

4445
// Repository editor settings
4546
Editor struct {
@@ -201,6 +202,7 @@ func newRepository() {
201202
Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
202203
Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool()
203204
Repository.MaxCreationLimit = sec.Key("MAX_CREATION_LIMIT").MustInt(-1)
205+
Repository.DefaultBranch = sec.Key("DEFAULT_BRANCH").MustString("master")
204206
RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gitea-repositories"))
205207
forcePathSeparator(RepoRootPath)
206208
if !filepath.IsAbs(RepoRootPath) {

routers/repo/repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ func Create(ctx *context.Context) {
134134
ctx.Data["readme"] = "Default"
135135
ctx.Data["private"] = getRepoPrivate(ctx)
136136
ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
137+
ctx.Data["default_branch"] = setting.Repository.DefaultBranch
137138

138139
ctxUser := checkContextUser(ctx, ctx.QueryInt64("org"))
139140
if ctx.Written() {

templates/repo/create.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
</div>
166166
<div class="inline field">
167167
<label for="default_branch">{{.i18n.Tr "repo.default_branch"}}</label>
168-
<input id="default_branch" name="default_branch" value="{{.default_branch}}" placeholder="master">
168+
<input id="default_branch" name="default_branch" value="{{.default_branch}}" placeholder="{{.default_branch}}">
169169
</div>
170170
</div>
171171

templates/repo/empty.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@
4949
<div class="markdown">
5050
<pre><code>touch README.md
5151
git init
52+
{{if ne .Repository.DefaultBranch "master"}}git branch -m master {{.Repository.DefaultBranch}}{{end}}
5253
git add README.md
5354
git commit -m "first commit"
5455
git remote add origin <span class="clone-url">{{if $.DisableSSH}}{{$.CloneLink.HTTPS}}{{else}}{{$.CloneLink.SSH}}{{end}}</span>
55-
git push -u origin {{if ne .Repository.DefaultBranch "master"}}master:{{.Repository.DefaultBranch}}{{else}}master{{end}}</code></pre>
56+
git push -u origin {{.Repository.DefaultBranch}}</code></pre>
5657
</div>
5758
</div>
5859
<div class="ui divider"></div>

0 commit comments

Comments
 (0)