Skip to content

Commit 6bf78d2

Browse files
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]>
1 parent 9e6a79b commit 6bf78d2

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
@@ -57,6 +57,8 @@ DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki
5757
PREFIX_ARCHIVE_FILES = true
5858
; Disable the creation of new mirrors. Pre-existing mirrors remain valid.
5959
DISABLE_MIRRORS = false
60+
; The default branch name of new repositories
61+
DEFAULT_BRANCH=master
6062

6163
[repository.editor]
6264
; 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
@@ -71,6 +71,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
7171
- `ENABLE_PUSH_CREATE_ORG`: **false**: Allow users to push local repositories to Gitea and have them automatically created for an org.
7272
- `PREFIX_ARCHIVE_FILES`: **true**: Prefix archive files by placing them in a directory named after the repository.
7373
- `DISABLE_MIRRORS`: **false**: Disable the creation of **new** mirrors. Pre-existing mirrors remain valid.
74+
- `DEFAULT_BRANCH`: **master**: Default branch name of all repositories.
7475

7576
### Repository - Pull Request (`repository.pull-request`)
7677

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
@@ -43,6 +43,7 @@ var (
4343
DefaultRepoUnits []string
4444
PrefixArchiveFiles bool
4545
DisableMirrors bool
46+
DefaultBranch string
4647

4748
// Repository editor settings
4849
Editor struct {
@@ -241,6 +242,7 @@ func newRepository() {
241242
Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
242243
Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool()
243244
Repository.MaxCreationLimit = sec.Key("MAX_CREATION_LIMIT").MustInt(-1)
245+
Repository.DefaultBranch = sec.Key("DEFAULT_BRANCH").MustString("master")
244246
RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gitea-repositories"))
245247
forcePathSeparator(RepoRootPath)
246248
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)