Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global default branch setting #11918

Merged
merged 6 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions custom/conf/app.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)

Expand Down
3 changes: 2 additions & 1 deletion modules/repository/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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).
Expand Down
2 changes: 2 additions & 0 deletions modules/setting/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
DefaultRepoUnits []string
PrefixArchiveFiles bool
DisableMirrors bool
DefaultBranch string

// Repository editor settings
Editor struct {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions routers/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/create.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
3 changes: 2 additions & 1 deletion templates/repo/empty.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down