diff options
author | techknowlogick <techknowlogick@gitea.io> | 2020-06-17 16:53:55 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-17 16:53:55 -0400 |
commit | 6bf78d2b576a5caa77a670db9bbf2572d0272f25 (patch) | |
tree | 36b547e948ac0c1aed41c5088f397ea50fa905ee | |
parent | 9e6a79bea9d7911c81b86a6d3715d340fc19032a (diff) | |
download | gitea-6bf78d2b576a5caa77a670db9bbf2572d0272f25.tar.gz gitea-6bf78d2b576a5caa77a670db9bbf2572d0272f25.zip |
Global default branch setting (#11918)
* Global default branch setting
* add to app.ini example per @silverwind
* update per @lunny
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
-rw-r--r-- | custom/conf/app.ini.sample | 2 | ||||
-rw-r--r-- | docs/content/doc/advanced/config-cheat-sheet.en-us.md | 1 | ||||
-rw-r--r-- | modules/repository/init.go | 3 | ||||
-rw-r--r-- | modules/setting/repository.go | 2 | ||||
-rw-r--r-- | routers/repo/repo.go | 1 | ||||
-rw-r--r-- | templates/repo/create.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/empty.tmpl | 3 |
7 files changed, 11 insertions, 3 deletions
diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 2d3aab1489..512073d43d 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -57,6 +57,8 @@ DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki PREFIX_ARCHIVE_FILES = true ; Disable the creation of new mirrors. Pre-existing mirrors remain valid. DISABLE_MIRRORS = false +; The default branch name of new repositories +DEFAULT_BRANCH=master [repository.editor] ; List of file extensions for which lines should be wrapped in the Monaco editor diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 5cc148f419..13c5f987ad 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -71,6 +71,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `ENABLE_PUSH_CREATE_ORG`: **false**: Allow users to push local repositories to Gitea and have them automatically created for an org. - `PREFIX_ARCHIVE_FILES`: **true**: Prefix archive files by placing them in a directory named after the repository. - `DISABLE_MIRRORS`: **false**: Disable the creation of **new** mirrors. Pre-existing mirrors remain valid. +- `DEFAULT_BRANCH`: **master**: Default branch name of all repositories. ### Repository - Pull Request (`repository.pull-request`) diff --git a/modules/repository/init.go b/modules/repository/init.go index f468ca0435..8f3f2f0590 100644 --- a/modules/repository/init.go +++ b/modules/repository/init.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" "github.com/mcuadros/go-version" "github.com/unknwon/com" @@ -147,7 +148,7 @@ func initRepoCommit(tmpPath string, repo *models.Repository, u *models.User, def } if len(defaultBranch) == 0 { - defaultBranch = "master" + defaultBranch = setting.Repository.DefaultBranch } if stdout, err := git.NewCommand("push", "origin", "master:"+defaultBranch). diff --git a/modules/setting/repository.go b/modules/setting/repository.go index 3e63d458f8..eb1501d7b8 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -43,6 +43,7 @@ var ( DefaultRepoUnits []string PrefixArchiveFiles bool DisableMirrors bool + DefaultBranch string // Repository editor settings Editor struct { @@ -241,6 +242,7 @@ func newRepository() { Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool() Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool() Repository.MaxCreationLimit = sec.Key("MAX_CREATION_LIMIT").MustInt(-1) + Repository.DefaultBranch = sec.Key("DEFAULT_BRANCH").MustString("master") RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gitea-repositories")) forcePathSeparator(RepoRootPath) if !filepath.IsAbs(RepoRootPath) { diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 4ded75db6c..27c8ff1e03 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -134,6 +134,7 @@ func Create(ctx *context.Context) { ctx.Data["readme"] = "Default" ctx.Data["private"] = getRepoPrivate(ctx) ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate + ctx.Data["default_branch"] = setting.Repository.DefaultBranch ctxUser := checkContextUser(ctx, ctx.QueryInt64("org")) if ctx.Written() { diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl index cad60126ef..c4b25c73d8 100644 --- a/templates/repo/create.tmpl +++ b/templates/repo/create.tmpl @@ -165,7 +165,7 @@ </div> <div class="inline field"> <label for="default_branch">{{.i18n.Tr "repo.default_branch"}}</label> - <input id="default_branch" name="default_branch" value="{{.default_branch}}" placeholder="master"> + <input id="default_branch" name="default_branch" value="{{.default_branch}}" placeholder="{{.default_branch}}"> </div> </div> diff --git a/templates/repo/empty.tmpl b/templates/repo/empty.tmpl index 8efb6d2866..9aa0706c29 100644 --- a/templates/repo/empty.tmpl +++ b/templates/repo/empty.tmpl @@ -49,10 +49,11 @@ <div class="markdown"> <pre><code>touch README.md git init +{{if ne .Repository.DefaultBranch "master"}}git branch -m master {{.Repository.DefaultBranch}}{{end}} git add README.md git commit -m "first commit" git remote add origin <span class="clone-url">{{if $.DisableSSH}}{{$.CloneLink.HTTPS}}{{else}}{{$.CloneLink.SSH}}{{end}}</span> -git push -u origin {{if ne .Repository.DefaultBranch "master"}}master:{{.Repository.DefaultBranch}}{{else}}master{{end}}</code></pre> +git push -u origin {{.Repository.DefaultBranch}}</code></pre> </div> </div> <div class="ui divider"></div> |