Browse Source

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 <john.olheiser@gmail.com>

* Update modules/setting/repository.go

Co-authored-by: John Olheiser <john.olheiser@gmail.com>
tags/v1.12.0
techknowlogick 3 years ago
parent
commit
7dc8db9ea8
No account linked to committer's email address

+ 2
- 0
custom/conf/app.ini.sample View File

DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki
; Prefix archive files by placing them in a directory named after the repository ; Prefix archive files by placing them in a directory named after the repository
PREFIX_ARCHIVE_FILES = true PREFIX_ARCHIVE_FILES = true
; The default branch name of new repositories
DEFAULT_BRANCH=master


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

+ 1
- 0
docs/content/doc/advanced/config-cheat-sheet.en-us.md View File

- `ENABLE_PUSH_CREATE_USER`: **false**: Allow users to push local repositories to Gitea and have them automatically created for a user. - `ENABLE_PUSH_CREATE_USER`: **false**: Allow users to push local repositories to Gitea and have them automatically created for a user.
- `ENABLE_PUSH_CREATE_ORG`: **false**: Allow users to push local repositories to Gitea and have them automatically created for an org. - `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. - `PREFIX_ARCHIVE_FILES`: **true**: Prefix archive files by placing them in a directory named after the repository.
- `DEFAULT_BRANCH`: **master**: Default branch name of all repositories.


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



+ 2
- 1
modules/repository/init.go View File

"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"


"github.com/mcuadros/go-version" "github.com/mcuadros/go-version"
"github.com/unknwon/com" "github.com/unknwon/com"
} }


if len(defaultBranch) == 0 { if len(defaultBranch) == 0 {
defaultBranch = "master"
defaultBranch = setting.Repository.DefaultBranch
} }


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

+ 2
- 0
modules/setting/repository.go View File

DisabledRepoUnits []string DisabledRepoUnits []string
DefaultRepoUnits []string DefaultRepoUnits []string
PrefixArchiveFiles bool PrefixArchiveFiles bool
DefaultBranch string


// Repository editor settings // Repository editor settings
Editor struct { Editor struct {
Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool() Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool() Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool()
Repository.MaxCreationLimit = sec.Key("MAX_CREATION_LIMIT").MustInt(-1) 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")) RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gitea-repositories"))
forcePathSeparator(RepoRootPath) forcePathSeparator(RepoRootPath)
if !filepath.IsAbs(RepoRootPath) { if !filepath.IsAbs(RepoRootPath) {

+ 1
- 0
routers/repo/repo.go View File

ctx.Data["readme"] = "Default" ctx.Data["readme"] = "Default"
ctx.Data["private"] = getRepoPrivate(ctx) ctx.Data["private"] = getRepoPrivate(ctx)
ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
ctx.Data["default_branch"] = setting.Repository.DefaultBranch


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

+ 1
- 1
templates/repo/create.tmpl View File

</div> </div>
<div class="inline field"> <div class="inline field">
<label for="default_branch">{{.i18n.Tr "repo.default_branch"}}</label> <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>
</div> </div>



+ 2
- 1
templates/repo/empty.tmpl View File

<div class="markdown"> <div class="markdown">
<pre><code>touch README.md <pre><code>touch README.md
git init git init
{{if ne .Repository.DefaultBranch "master"}}git branch -m master {{.Repository.DefaultBranch}}{{end}}
git add README.md git add README.md
git commit -m "first commit" git commit -m "first commit"
git remote add origin <span class="clone-url">{{if $.DisableSSH}}{{$.CloneLink.HTTPS}}{{else}}{{$.CloneLink.SSH}}{{end}}</span> 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> </div>
<div class="ui divider"></div> <div class="ui divider"></div>

Loading…
Cancel
Save