diff --git a/modules/setting/config.go b/modules/setting/config.go index 03558574c2110..25ceeac2a9f2e 100644 --- a/modules/setting/config.go +++ b/modules/setting/config.go @@ -51,9 +51,14 @@ type RepositoryStruct struct { OpenWithEditorApps *config.Value[OpenWithEditorAppsType] } +type TemplateStruct struct { + GitRemoteName *config.Value[string] +} + type ConfigStruct struct { Picture *PictureStruct Repository *RepositoryStruct + Template *TemplateStruct } var ( @@ -71,6 +76,9 @@ func initDefaultConfig() { Repository: &RepositoryStruct{ OpenWithEditorApps: config.ValueJSON[OpenWithEditorAppsType]("repository.open-with.editor-apps"), }, + Template: &TemplateStruct{ + GitRemoteName: config.ValueJSON[string]("template.git-remote-name").WithDefault("origin"), + }, } } diff --git a/modules/setting/config/value.go b/modules/setting/config/value.go index f0ec12054478d..0a111ca83c322 100644 --- a/modules/setting/config/value.go +++ b/modules/setting/config/value.go @@ -79,6 +79,10 @@ func (value *Value[T]) DynKey() string { return value.dynKey } +func (value *Value[T]) Def() T { + return value.def +} + func (value *Value[T]) WithDefault(def T) *Value[T] { value.def = def return value diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 53fbf0af767ad..d68b4edd20b77 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3419,6 +3419,9 @@ config.disable_gravatar = Disable Gravatar config.enable_federated_avatar = Enable Federated Avatars config.open_with_editor_app_help = The "Open with" editors for the clone menu. If left empty, the default will be used. Expand to see the default. +config.empty_repo_page = Empty Repo Page +config.empty_repo_page.git_remote_name = Git Remote Name (default: origin) + config.git_config = Git Configuration config.git_disable_diff_highlight = Disable Diff Syntax Highlight config.git_max_diff_lines = Max Diff Lines (for a single file) diff --git a/routers/web/admin/config.go b/routers/web/admin/config.go index 0e5b23db6d562..b0a4cf9670998 100644 --- a/routers/web/admin/config.go +++ b/routers/web/admin/config.go @@ -206,6 +206,20 @@ func ChangeConfig(ctx *context.Context) { } return "false", nil } + + marshalStringWithDefault := func(def string) func(v string) (string, error) { + return func(v string) (string, error) { + if strings.TrimSpace(v) == "" { + v = def + } + b, err := json.Marshal(v) + if err != nil { + return "", err + } + return string(b), nil + } + } + marshalOpenWithApps := func(value string) (string, error) { lines := strings.Split(value, "\n") var openWithEditorApps setting.OpenWithEditorAppsType @@ -234,6 +248,7 @@ func ChangeConfig(ctx *context.Context) { cfg.Picture.DisableGravatar.DynKey(): marshalBool, cfg.Picture.EnableFederatedAvatar.DynKey(): marshalBool, cfg.Repository.OpenWithEditorApps.DynKey(): marshalOpenWithApps, + cfg.Template.GitRemoteName.DynKey(): marshalStringWithDefault(cfg.Template.GitRemoteName.Def()), } marshaller, hasMarshaller := marshallers[key] if !hasMarshaller { diff --git a/routers/web/repo/issue_view.go b/routers/web/repo/issue_view.go index d0064e763ef82..17712a053bf1b 100644 --- a/routers/web/repo/issue_view.go +++ b/routers/web/repo/issue_view.go @@ -446,6 +446,7 @@ func ViewPullMergeBox(ctx *context.Context) { // TODO: it should use a dedicated struct to render the pull merge box, to make sure all data is prepared correctly ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.Doer.ID) + ctx.Data["GitRemoteName"] = setting.Config().Template.GitRemoteName.Value(ctx) ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) ctx.HTML(http.StatusOK, tplPullMergeBox) } diff --git a/services/context/repo.go b/services/context/repo.go index afc6de9b1666d..e4cfad8ee6f9e 100644 --- a/services/context/repo.go +++ b/services/context/repo.go @@ -542,6 +542,7 @@ func RepoAssignment(ctx *Context) { ctx.Data["CanWriteIssues"] = ctx.Repo.CanWrite(unit_model.TypeIssues) ctx.Data["CanWritePulls"] = ctx.Repo.CanWrite(unit_model.TypePullRequests) ctx.Data["CanWriteActions"] = ctx.Repo.CanWrite(unit_model.TypeActions) + ctx.Data["GitRemoteName"] = setting.Config().Template.GitRemoteName.Value(ctx) canSignedUserFork, err := repo_module.CanUserForkRepo(ctx, ctx.Doer, ctx.Repo.Repository) if err != nil { diff --git a/templates/admin/config_settings.tmpl b/templates/admin/config_settings.tmpl index 6b9bb8275cca5..16bb89e8ad423 100644 --- a/templates/admin/config_settings.tmpl +++ b/templates/admin/config_settings.tmpl @@ -39,4 +39,19 @@ + +

+ {{ctx.Locale.Tr "admin.config.empty_repo_page"}} +

+
+
+
+ + +
+
+ +
+
+
{{template "admin/layout_footer" .}} diff --git a/templates/repo/empty.tmpl b/templates/repo/empty.tmpl index 32b5c8401b3f2..98d09774bf1f1 100644 --- a/templates/repo/empty.tmpl +++ b/templates/repo/empty.tmpl @@ -51,8 +51,8 @@ git init{{if ne .Repository.ObjectFormatName "sha1"}} --object-format={{.Reposit {{if ne .Repository.DefaultBranch "master"}}git checkout -b {{.Repository.DefaultBranch}}{{end}} git add README.md git commit -m "first commit" -git remote add origin {{$.CloneButtonOriginLink.HTTPS}} -git push -u origin {{.Repository.DefaultBranch}} +git remote add {{.GitRemoteName}} {{$.CloneButtonOriginLink.HTTPS}} +git push -u {{.GitRemoteName}} {{.Repository.DefaultBranch}}
@@ -60,8 +60,8 @@ git push -u origin {{.Repository.DefaultBranch}}

{{ctx.Locale.Tr "repo.push_exist_repo"}}

-
git remote add origin {{$.CloneButtonOriginLink.HTTPS}}
-git push -u origin {{.Repository.DefaultBranch}}
+
git remote add {{.GitRemoteName}} {{$.CloneButtonOriginLink.HTTPS}}
+git push -u {{.GitRemoteName}} {{.Repository.DefaultBranch}}
{{end}} diff --git a/templates/repo/issue/view_content/pull_merge_box.tmpl b/templates/repo/issue/view_content/pull_merge_box.tmpl index 113bfb732ecee..4e4ff70d99d8b 100644 --- a/templates/repo/issue/view_content/pull_merge_box.tmpl +++ b/templates/repo/issue/view_content/pull_merge_box.tmpl @@ -396,7 +396,7 @@ {{end}} {{if and .Issue.PullRequest.HeadRepo (not .Issue.PullRequest.HasMerged) (not .Issue.IsClosed)}} - {{template "repo/issue/view_content/pull_merge_instruction" dict "PullRequest" .Issue.PullRequest "ShowMergeInstructions" .ShowMergeInstructions}} + {{template "repo/issue/view_content/pull_merge_instruction" dict "PullRequest" .Issue.PullRequest "ShowMergeInstructions" .ShowMergeInstructions "GitRemoteName" .GitRemoteName}} {{end}} diff --git a/templates/repo/issue/view_content/pull_merge_instruction.tmpl b/templates/repo/issue/view_content/pull_merge_instruction.tmpl index 9dbcbeee21da3..ef1252f1f044b 100644 --- a/templates/repo/issue/view_content/pull_merge_instruction.tmpl +++ b/templates/repo/issue/view_content/pull_merge_instruction.tmpl @@ -9,9 +9,9 @@ {{end}}
{{if eq .PullRequest.Flow 0}} -
git fetch -u {{if ne .PullRequest.HeadRepo.ID .PullRequest.BaseRepo.ID}}{{else}}origin{{end}} {{.PullRequest.HeadBranch}}:{{$localBranch}}
+
git fetch -u {{if ne .PullRequest.HeadRepo.ID .PullRequest.BaseRepo.ID}}{{else}}{{.GitRemoteName}}{{end}} {{.PullRequest.HeadBranch}}:{{$localBranch}}
{{else}} -
git fetch -u origin {{.PullRequest.GetGitHeadRefName}}:{{$localBranch}}
+
git fetch -u {{.GitRemoteName}} {{.PullRequest.GetGitHeadRefName}}:{{$localBranch}}
{{end}}
git checkout {{$localBranch}}
@@ -50,7 +50,7 @@
git checkout {{.PullRequest.BaseBranch}}
git merge {{$localBranch}}
-
git push origin {{.PullRequest.BaseBranch}}
+
git push {{.GitRemoteName}} {{.PullRequest.BaseBranch}}
{{end}}