From c483167bff4e1ee65620f7eb935fe04648371784 Mon Sep 17 00:00:00 2001 From: Ilya Nurullin Date: Mon, 28 Jul 2025 11:10:22 +0300 Subject: [PATCH 01/12] Use configurable remote name in snippets --- modules/setting/repository.go | 2 ++ routers/web/repo/issue_view.go | 1 + services/context/repo.go | 1 + templates/repo/empty.tmpl | 8 ++++---- templates/repo/issue/view_content/pull_merge_box.tmpl | 2 +- .../repo/issue/view_content/pull_merge_instruction.tmpl | 6 +++--- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/setting/repository.go b/modules/setting/repository.go index 318cf4110855c..d4cbe7664a7b7 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -48,6 +48,7 @@ var ( DisableMigrations bool DisableStars bool `ini:"DISABLE_STARS"` DefaultBranch string + SnippetRemoteName string AllowAdoptionOfUnadoptedRepositories bool AllowDeleteOfUnadoptedRepositories bool DisableDownloadSourceArchives bool @@ -166,6 +167,7 @@ var ( DisableMigrations: false, DisableStars: false, DefaultBranch: "main", + SnippetRemoteName: "origin", AllowForkWithoutMaximumLimit: true, // Repository editor settings diff --git a/routers/web/repo/issue_view.go b/routers/web/repo/issue_view.go index d0064e763ef82..a1d513a8f2324 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["SnippetRemoteName"] = setting.Repository.SnippetRemoteName 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..67b834b378b5a 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["SnippetRemoteName"] = setting.Repository.SnippetRemoteName canSignedUserFork, err := repo_module.CanUserForkRepo(ctx, ctx.Doer, ctx.Repo.Repository) if err != nil { diff --git a/templates/repo/empty.tmpl b/templates/repo/empty.tmpl index 32b5c8401b3f2..487d1368a8b6c 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 {{.SnippetRemoteName}} {{$.CloneButtonOriginLink.HTTPS}} +git push -u {{.SnippetRemoteName}} {{.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 {{.SnippetRemoteName}} {{$.CloneButtonOriginLink.HTTPS}}
+git push -u {{.SnippetRemoteName}} {{.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..6998bc0d63d42 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 "SnippetRemoteName" .SnippetRemoteName}} {{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..70f597ca5a8a3 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}}{{.SnippetRemoteName}}{{end}} {{.PullRequest.HeadBranch}}:{{$localBranch}}
{{else}} -
git fetch -u origin {{.PullRequest.GetGitHeadRefName}}:{{$localBranch}}
+
git fetch -u {{.SnippetRemoteName}} {{.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 {{.SnippetRemoteName}} {{.PullRequest.BaseBranch}}
{{end}} From 765b2c6355866c4ad7e642aa79c9f045f0a6936d Mon Sep 17 00:00:00 2001 From: Ilya Nurullin Date: Tue, 29 Jul 2025 17:36:40 +0300 Subject: [PATCH 02/12] Store remote name in config database --- modules/setting/config.go | 2 ++ modules/setting/config/value.go | 4 ++++ modules/setting/repository.go | 2 -- routers/web/admin/config.go | 15 +++++++++++++++ routers/web/repo/issue_view.go | 2 +- services/context/repo.go | 2 +- templates/admin/config_settings.tmpl | 15 +++++++++++++++ 7 files changed, 38 insertions(+), 4 deletions(-) diff --git a/modules/setting/config.go b/modules/setting/config.go index 03558574c2110..32d36044ae00c 100644 --- a/modules/setting/config.go +++ b/modules/setting/config.go @@ -49,6 +49,7 @@ func DefaultOpenWithEditorApps() OpenWithEditorAppsType { type RepositoryStruct struct { OpenWithEditorApps *config.Value[OpenWithEditorAppsType] + SnippetRemoteName *config.Value[string] } type ConfigStruct struct { @@ -70,6 +71,7 @@ func initDefaultConfig() { }, Repository: &RepositoryStruct{ OpenWithEditorApps: config.ValueJSON[OpenWithEditorAppsType]("repository.open-with.editor-apps"), + SnippetRemoteName: config.ValueJSON[string]("repository.snippet-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/modules/setting/repository.go b/modules/setting/repository.go index d4cbe7664a7b7..318cf4110855c 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -48,7 +48,6 @@ var ( DisableMigrations bool DisableStars bool `ini:"DISABLE_STARS"` DefaultBranch string - SnippetRemoteName string AllowAdoptionOfUnadoptedRepositories bool AllowDeleteOfUnadoptedRepositories bool DisableDownloadSourceArchives bool @@ -167,7 +166,6 @@ var ( DisableMigrations: false, DisableStars: false, DefaultBranch: "main", - SnippetRemoteName: "origin", AllowForkWithoutMaximumLimit: true, // Repository editor settings diff --git a/routers/web/admin/config.go b/routers/web/admin/config.go index 0e5b23db6d562..482dea61a81ae 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.Repository.SnippetRemoteName.DynKey(): marshalStringWithDefault(cfg.Repository.SnippetRemoteName.Def()), } marshaller, hasMarshaller := marshallers[key] if !hasMarshaller { diff --git a/routers/web/repo/issue_view.go b/routers/web/repo/issue_view.go index a1d513a8f2324..71fbb3db197ec 100644 --- a/routers/web/repo/issue_view.go +++ b/routers/web/repo/issue_view.go @@ -446,7 +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["SnippetRemoteName"] = setting.Repository.SnippetRemoteName + ctx.Data["SnippetRemoteName"] = setting.Config().Repository.SnippetRemoteName.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 67b834b378b5a..9c1c19abbb33e 100644 --- a/services/context/repo.go +++ b/services/context/repo.go @@ -542,7 +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["SnippetRemoteName"] = setting.Repository.SnippetRemoteName + ctx.Data["SnippetRemoteName"] = setting.Config().Repository.SnippetRemoteName.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..ccdd5327d674c 100644 --- a/templates/admin/config_settings.tmpl +++ b/templates/admin/config_settings.tmpl @@ -39,4 +39,19 @@ + +

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

+
+
+
+ + +
+
+ +
+
+
{{template "admin/layout_footer" .}} From 88776de67eff4c809660f5a587ee36215491a756 Mon Sep 17 00:00:00 2001 From: Ilya Nurullin Date: Tue, 29 Jul 2025 18:17:54 +0300 Subject: [PATCH 03/12] run: make fmt --- modules/setting/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/setting/config.go b/modules/setting/config.go index 32d36044ae00c..e6dfcfc0cc79c 100644 --- a/modules/setting/config.go +++ b/modules/setting/config.go @@ -49,7 +49,7 @@ func DefaultOpenWithEditorApps() OpenWithEditorAppsType { type RepositoryStruct struct { OpenWithEditorApps *config.Value[OpenWithEditorAppsType] - SnippetRemoteName *config.Value[string] + SnippetRemoteName *config.Value[string] } type ConfigStruct struct { @@ -71,7 +71,7 @@ func initDefaultConfig() { }, Repository: &RepositoryStruct{ OpenWithEditorApps: config.ValueJSON[OpenWithEditorAppsType]("repository.open-with.editor-apps"), - SnippetRemoteName: config.ValueJSON[string]("repository.snippet-remote-name").WithDefault("origin"), + SnippetRemoteName: config.ValueJSON[string]("repository.snippet-remote-name").WithDefault("origin"), }, } } From fcae5b5790ccb2d8446172eea269a16e7814077f Mon Sep 17 00:00:00 2001 From: Ilya Nurullin Date: Tue, 29 Jul 2025 18:25:26 +0300 Subject: [PATCH 04/12] Add translations --- options/locale/locale_en-US.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 65ba4e9cd3fc5..162d427721aee 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.repository_snippets = Repository Snippets +config.repository_snippets.remote_name = 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) From eb02be960185be784d16afa3ccf49f46e30d0e5c Mon Sep 17 00:00:00 2001 From: Ilya Nurullin Date: Fri, 8 Aug 2025 18:30:49 +0300 Subject: [PATCH 05/12] use `GitRemoteName` --- modules/setting/config.go | 10 ++++++++-- options/locale/locale_en-US.ini | 4 ++-- routers/web/admin/config.go | 2 +- routers/web/repo/issue_view.go | 2 +- services/context/repo.go | 2 +- templates/admin/config_settings.tmpl | 8 ++++---- templates/repo/empty.tmpl | 8 ++++---- templates/repo/issue/view_content/pull_merge_box.tmpl | 2 +- .../issue/view_content/pull_merge_instruction.tmpl | 6 +++--- 9 files changed, 25 insertions(+), 19 deletions(-) diff --git a/modules/setting/config.go b/modules/setting/config.go index e6dfcfc0cc79c..25ceeac2a9f2e 100644 --- a/modules/setting/config.go +++ b/modules/setting/config.go @@ -49,12 +49,16 @@ func DefaultOpenWithEditorApps() OpenWithEditorAppsType { type RepositoryStruct struct { OpenWithEditorApps *config.Value[OpenWithEditorAppsType] - SnippetRemoteName *config.Value[string] +} + +type TemplateStruct struct { + GitRemoteName *config.Value[string] } type ConfigStruct struct { Picture *PictureStruct Repository *RepositoryStruct + Template *TemplateStruct } var ( @@ -71,7 +75,9 @@ func initDefaultConfig() { }, Repository: &RepositoryStruct{ OpenWithEditorApps: config.ValueJSON[OpenWithEditorAppsType]("repository.open-with.editor-apps"), - SnippetRemoteName: config.ValueJSON[string]("repository.snippet-remote-name").WithDefault("origin"), + }, + Template: &TemplateStruct{ + GitRemoteName: config.ValueJSON[string]("template.git-remote-name").WithDefault("origin"), }, } } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 162d427721aee..9cd6cd4a4cd76 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3419,8 +3419,8 @@ 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.repository_snippets = Repository Snippets -config.repository_snippets.remote_name = Remote name (default: origin) +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 diff --git a/routers/web/admin/config.go b/routers/web/admin/config.go index 482dea61a81ae..b0a4cf9670998 100644 --- a/routers/web/admin/config.go +++ b/routers/web/admin/config.go @@ -248,7 +248,7 @@ func ChangeConfig(ctx *context.Context) { cfg.Picture.DisableGravatar.DynKey(): marshalBool, cfg.Picture.EnableFederatedAvatar.DynKey(): marshalBool, cfg.Repository.OpenWithEditorApps.DynKey(): marshalOpenWithApps, - cfg.Repository.SnippetRemoteName.DynKey(): marshalStringWithDefault(cfg.Repository.SnippetRemoteName.Def()), + 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 71fbb3db197ec..17712a053bf1b 100644 --- a/routers/web/repo/issue_view.go +++ b/routers/web/repo/issue_view.go @@ -446,7 +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["SnippetRemoteName"] = setting.Config().Repository.SnippetRemoteName.Value(ctx) + 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 9c1c19abbb33e..e4cfad8ee6f9e 100644 --- a/services/context/repo.go +++ b/services/context/repo.go @@ -542,7 +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["SnippetRemoteName"] = setting.Config().Repository.SnippetRemoteName.Value(ctx) + 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 ccdd5327d674c..16bb89e8ad423 100644 --- a/templates/admin/config_settings.tmpl +++ b/templates/admin/config_settings.tmpl @@ -41,13 +41,13 @@

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

-
+
- - + +
diff --git a/templates/repo/empty.tmpl b/templates/repo/empty.tmpl index 487d1368a8b6c..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 {{.SnippetRemoteName}} {{$.CloneButtonOriginLink.HTTPS}} -git push -u {{.SnippetRemoteName}} {{.Repository.DefaultBranch}} +git remote add {{.GitRemoteName}} {{$.CloneButtonOriginLink.HTTPS}} +git push -u {{.GitRemoteName}} {{.Repository.DefaultBranch}}
@@ -60,8 +60,8 @@ git push -u {{.SnippetRemoteName}} {{.Repository.DefaultBranch}}

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

-
git remote add {{.SnippetRemoteName}} {{$.CloneButtonOriginLink.HTTPS}}
-git push -u {{.SnippetRemoteName}} {{.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 6998bc0d63d42..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 "SnippetRemoteName" .SnippetRemoteName}} + {{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 70f597ca5a8a3..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}}{{.SnippetRemoteName}}{{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 {{.SnippetRemoteName}} {{.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 {{.SnippetRemoteName}} {{.PullRequest.BaseBranch}}
+
git push {{.GitRemoteName}} {{.PullRequest.BaseBranch}}
{{end}} From f96d49f9ff4be9af68f9c25d9a75c379187aa7d5 Mon Sep 17 00:00:00 2001 From: Ilya Nurullin Date: Sat, 16 Aug 2025 01:47:23 +0300 Subject: [PATCH 06/12] remove val.Def() --- modules/setting/config/value.go | 6 +----- routers/web/admin/config.go | 21 ++++++++++----------- templates/admin/config_settings.tmpl | 2 +- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/modules/setting/config/value.go b/modules/setting/config/value.go index 0a111ca83c322..85637470f178d 100644 --- a/modules/setting/config/value.go +++ b/modules/setting/config/value.go @@ -28,7 +28,7 @@ type Value[T any] struct { func (value *Value[T]) parse(key, valStr string) (v T) { v = value.def - if valStr != "" { + if valStr != "" && valStr != "null" { if err := json.Unmarshal(util.UnsafeStringToBytes(valStr), &v); err != nil { log.Error("Unable to unmarshal json config for key %q, err: %v", key, err) } @@ -79,10 +79,6 @@ 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/routers/web/admin/config.go b/routers/web/admin/config.go index b0a4cf9670998..7c9a321bc2626 100644 --- a/routers/web/admin/config.go +++ b/routers/web/admin/config.go @@ -207,19 +207,18 @@ 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 + marshalString := func(v string) (string, error) { + if strings.TrimSpace(v) == "" { + return "null", nil } + 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 @@ -248,7 +247,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()), + cfg.Template.GitRemoteName.DynKey(): marshalString, } marshaller, hasMarshaller := marshallers[key] if !hasMarshaller { diff --git a/templates/admin/config_settings.tmpl b/templates/admin/config_settings.tmpl index 16bb89e8ad423..6efaf47745927 100644 --- a/templates/admin/config_settings.tmpl +++ b/templates/admin/config_settings.tmpl @@ -47,7 +47,7 @@
- +
From e482a93699c80e804f171b950a694c071ab863e0 Mon Sep 17 00:00:00 2001 From: Ilya Nurullin Date: Sat, 16 Aug 2025 01:54:27 +0300 Subject: [PATCH 07/12] change translation to "Git Guide" --- options/locale/locale_en-US.ini | 4 ++-- templates/admin/config_settings.tmpl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index d68b4edd20b77..84e39d7f02240 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3419,8 +3419,8 @@ 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_guide = Git Guide +config.git_guide.remote_name = Git Remote Name config.git_config = Git Configuration config.git_disable_diff_highlight = Disable Diff Syntax Highlight diff --git a/templates/admin/config_settings.tmpl b/templates/admin/config_settings.tmpl index 6efaf47745927..14a25966aca2c 100644 --- a/templates/admin/config_settings.tmpl +++ b/templates/admin/config_settings.tmpl @@ -41,12 +41,12 @@

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

- +
From 3d7c8947573c0e3a60b74771f17d37ec83916719 Mon Sep 17 00:00:00 2001 From: Ilya Nurullin Date: Sat, 16 Aug 2025 02:03:55 +0300 Subject: [PATCH 08/12] make fmt --- routers/web/admin/config.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/web/admin/config.go b/routers/web/admin/config.go index 7c9a321bc2626..862b9ddcd24c9 100644 --- a/routers/web/admin/config.go +++ b/routers/web/admin/config.go @@ -207,7 +207,7 @@ func ChangeConfig(ctx *context.Context) { return "false", nil } - marshalString := func(v string) (string, error) { + marshalString := func(v string) (string, error) { if strings.TrimSpace(v) == "" { return "null", nil } @@ -218,7 +218,6 @@ func ChangeConfig(ctx *context.Context) { return string(b), nil } - marshalOpenWithApps := func(value string) (string, error) { lines := strings.Split(value, "\n") var openWithEditorApps setting.OpenWithEditorAppsType From 7eae056a7e08f0fb241c6a0b16d5dd022f5fa888 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 21 Aug 2025 12:30:24 +0800 Subject: [PATCH 09/12] fix --- options/locale/locale_en-US.ini | 3 +- routers/web/admin/config.go | 47 ++++++++++++++++++---------- templates/admin/config_settings.tmpl | 20 ++++-------- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 215a79170b54f..6477690537a61 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3426,8 +3426,7 @@ 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.git_guide = Git Guide -config.git_guide.remote_name = Git Remote Name +config.git_guide_remote_name = Repository remote name for git commands in the guide config.git_config = Git Configuration config.git_disable_diff_highlight = Disable Diff Syntax Highlight diff --git a/routers/web/admin/config.go b/routers/web/admin/config.go index 862b9ddcd24c9..327d566f6a5b6 100644 --- a/routers/web/admin/config.go +++ b/routers/web/admin/config.go @@ -196,8 +196,6 @@ func ConfigSettings(ctx *context.Context) { } func ChangeConfig(ctx *context.Context) { - key := strings.TrimSpace(ctx.FormString("key")) - value := ctx.FormString("value") cfg := setting.Config() marshalBool := func(v string) (string, error) { //nolint:unparam // error is always nil @@ -248,21 +246,38 @@ func ChangeConfig(ctx *context.Context) { cfg.Repository.OpenWithEditorApps.DynKey(): marshalOpenWithApps, cfg.Template.GitRemoteName.DynKey(): marshalString, } - marshaller, hasMarshaller := marshallers[key] - if !hasMarshaller { - ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key)) - return - } - marshaledValue, err := marshaller(value) - if err != nil { - ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key)) - return - } - if err = system_model.SetSettings(ctx, map[string]string{key: marshaledValue}); err != nil { - ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key)) - return + + _ = ctx.Req.ParseForm() + queryKeys := ctx.Req.Form["key"] + queryValues := ctx.Req.Form["value"] +loop: + for i, key := range queryKeys { + if i >= len(queryValues) { + ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key)) + break loop + } + value := queryValues[i] + + marshaller, hasMarshaller := marshallers[key] + if !hasMarshaller { + ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key)) + break loop + } + + marshaledValue, err := marshaller(value) + if err != nil { + ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key)) + break loop + } + + if err = system_model.SetSettings(ctx, map[string]string{key: marshaledValue}); err != nil { + ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key)) + break loop + } } config.GetDynGetter().InvalidateCache() - ctx.JSONOK() + if !ctx.Written() { + ctx.JSONOK() + } } diff --git a/templates/admin/config_settings.tmpl b/templates/admin/config_settings.tmpl index 14a25966aca2c..5e7fbe22235a2 100644 --- a/templates/admin/config_settings.tmpl +++ b/templates/admin/config_settings.tmpl @@ -24,7 +24,7 @@ {{ctx.Locale.Tr "repository"}}
- +
{{ctx.Locale.Tr "admin.config.open_with_editor_app_help"}} @@ -32,22 +32,14 @@
+
-
- -
- -
-

- {{ctx.Locale.Tr "admin.config.git_guide"}} -

-
-
-
- - +
+ + +
From 680639a6abbd3261f568e3fe87afe90324e593d0 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 21 Aug 2025 12:51:42 +0800 Subject: [PATCH 10/12] fix --- modules/setting/config.go | 10 ++-------- modules/setting/config/value.go | 8 ++++++-- routers/web/admin/config.go | 20 ++++++++++--------- routers/web/repo/issue_view.go | 1 - services/context/repo.go | 1 - templates/admin/config_settings.tmpl | 10 ++++++---- templates/repo/empty.tmpl | 9 +++++---- .../issue/view_content/pull_merge_box.tmpl | 2 +- .../view_content/pull_merge_instruction.tmpl | 7 ++++--- 9 files changed, 35 insertions(+), 33 deletions(-) diff --git a/modules/setting/config.go b/modules/setting/config.go index 25ceeac2a9f2e..4c5d2df7d8a01 100644 --- a/modules/setting/config.go +++ b/modules/setting/config.go @@ -49,16 +49,12 @@ func DefaultOpenWithEditorApps() OpenWithEditorAppsType { type RepositoryStruct struct { OpenWithEditorApps *config.Value[OpenWithEditorAppsType] -} - -type TemplateStruct struct { - GitRemoteName *config.Value[string] + GitGuideRemoteName *config.Value[string] } type ConfigStruct struct { Picture *PictureStruct Repository *RepositoryStruct - Template *TemplateStruct } var ( @@ -75,9 +71,7 @@ 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"), + GitGuideRemoteName: config.ValueJSON[string]("repository.git-guide-remote-name").WithDefault("origin"), }, } } diff --git a/modules/setting/config/value.go b/modules/setting/config/value.go index 85637470f178d..301c60f5e8250 100644 --- a/modules/setting/config/value.go +++ b/modules/setting/config/value.go @@ -28,7 +28,7 @@ type Value[T any] struct { func (value *Value[T]) parse(key, valStr string) (v T) { v = value.def - if valStr != "" && valStr != "null" { + if valStr != "" { if err := json.Unmarshal(util.UnsafeStringToBytes(valStr), &v); err != nil { log.Error("Unable to unmarshal json config for key %q, err: %v", key, err) } @@ -46,7 +46,7 @@ func (value *Value[T]) Value(ctx context.Context) (v T) { rev := dg.GetRevision(ctx) - // if the revision in database doesn't change, use the last value + // if the revision in the database doesn't change, use the last value value.mu.RLock() if rev == value.revision { v = value.value @@ -84,6 +84,10 @@ func (value *Value[T]) WithDefault(def T) *Value[T] { return value } +func (value *Value[T]) DefaultValue() T { + return value.def +} + func (value *Value[T]) WithFileConfig(cfgSecKey CfgSecKey) *Value[T] { value.cfgSecKey = cfgSecKey return value diff --git a/routers/web/admin/config.go b/routers/web/admin/config.go index 327d566f6a5b6..476cebb307ef7 100644 --- a/routers/web/admin/config.go +++ b/routers/web/admin/config.go @@ -205,15 +205,17 @@ func ChangeConfig(ctx *context.Context) { return "false", nil } - marshalString := func(v string) (string, error) { - if strings.TrimSpace(v) == "" { - return "null", nil - } - b, err := json.Marshal(v) - if err != nil { - return "", err + marshalString := func(emptyDefault string) func(v string) (string, error) { + return func(v string) (string, error) { + if v == "" { + v = emptyDefault + } + b, err := json.Marshal(v) + if err != nil { + return "", err + } + return string(b), nil } - return string(b), nil } marshalOpenWithApps := func(value string) (string, error) { @@ -244,7 +246,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(): marshalString, + cfg.Repository.GitGuideRemoteName.DynKey(): marshalString(cfg.Repository.GitGuideRemoteName.DefaultValue()), } _ = ctx.Req.ParseForm() diff --git a/routers/web/repo/issue_view.go b/routers/web/repo/issue_view.go index 17712a053bf1b..d0064e763ef82 100644 --- a/routers/web/repo/issue_view.go +++ b/routers/web/repo/issue_view.go @@ -446,7 +446,6 @@ 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 e4cfad8ee6f9e..afc6de9b1666d 100644 --- a/services/context/repo.go +++ b/services/context/repo.go @@ -542,7 +542,6 @@ 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 5e7fbe22235a2..9bd37afa7d599 100644 --- a/templates/admin/config_settings.tmpl +++ b/templates/admin/config_settings.tmpl @@ -32,14 +32,16 @@
- - + {{$cfg := .SystemConfig.Repository.OpenWithEditorApps}} + +
- - + {{$cfg = .SystemConfig.Repository.GitGuideRemoteName}} + +
diff --git a/templates/repo/empty.tmpl b/templates/repo/empty.tmpl index 98d09774bf1f1..fd3cf2b3db6bd 100644 --- a/templates/repo/empty.tmpl +++ b/templates/repo/empty.tmpl @@ -46,13 +46,14 @@

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

+ {{$gitRemoteName := $.SystemConfig.Repository.GitGuideRemoteName.Value ctx}}
touch README.md
 git init{{if ne .Repository.ObjectFormatName "sha1"}} --object-format={{.Repository.ObjectFormatName}}{{end}}{{/* for sha256 repo, it needs to set "object-format" explicitly*/}}
 {{if ne .Repository.DefaultBranch "master"}}git checkout -b {{.Repository.DefaultBranch}}{{end}}
 git add README.md
 git commit -m "first commit"
-git remote add {{.GitRemoteName}} {{$.CloneButtonOriginLink.HTTPS}}
-git push -u {{.GitRemoteName}} {{.Repository.DefaultBranch}}
+git remote add {{$gitRemoteName}} {{$.CloneButtonOriginLink.HTTPS}} +git push -u {{$gitRemoteName}} {{.Repository.DefaultBranch}}
@@ -60,8 +61,8 @@ git push -u {{.GitRemoteName}} {{.Repository.DefaultBranch}}

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

-
git remote add {{.GitRemoteName}} {{$.CloneButtonOriginLink.HTTPS}}
-git push -u {{.GitRemoteName}} {{.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 4e4ff70d99d8b..113bfb732ecee 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 "GitRemoteName" .GitRemoteName}} + {{template "repo/issue/view_content/pull_merge_instruction" dict "PullRequest" .Issue.PullRequest "ShowMergeInstructions" .ShowMergeInstructions}} {{end}}
diff --git a/templates/repo/issue/view_content/pull_merge_instruction.tmpl b/templates/repo/issue/view_content/pull_merge_instruction.tmpl index ef1252f1f044b..5c6bd60a4079f 100644 --- a/templates/repo/issue/view_content/pull_merge_instruction.tmpl +++ b/templates/repo/issue/view_content/pull_merge_instruction.tmpl @@ -8,10 +8,11 @@ {{$localBranch = print .PullRequest.HeadRepo.OwnerName "-" .PullRequest.HeadBranch}} {{end}}
+ {{$gitRemoteName := ctx.RootData.SystemConfig.Repository.GitGuideRemoteName.Value ctx}} {{if eq .PullRequest.Flow 0}} -
git fetch -u {{if ne .PullRequest.HeadRepo.ID .PullRequest.BaseRepo.ID}}{{else}}{{.GitRemoteName}}{{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 {{.GitRemoteName}} {{.PullRequest.GetGitHeadRefName}}:{{$localBranch}}
+
git fetch -u {{$gitRemoteName}} {{.PullRequest.GetGitHeadRefName}}:{{$localBranch}}
{{end}}
git checkout {{$localBranch}}
@@ -50,7 +51,7 @@
git checkout {{.PullRequest.BaseBranch}}
git merge {{$localBranch}}
-
git push {{.GitRemoteName}} {{.PullRequest.BaseBranch}}
+
git push {{$gitRemoteName}} {{.PullRequest.BaseBranch}}
{{end}}
From 4793538b8b8fff566002e3b81fa8be1607c25c9c Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 21 Aug 2025 13:48:08 +0800 Subject: [PATCH 11/12] simplify --- options/locale/locale_en-US.ini | 1 - routers/web/admin/config.go | 60 +++++++++++++-------------------- 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 6477690537a61..315241a4174ab 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3425,7 +3425,6 @@ config.picture_service = Picture Service 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.git_guide_remote_name = Repository remote name for git commands in the guide config.git_config = Git Configuration diff --git a/routers/web/admin/config.go b/routers/web/admin/config.go index 476cebb307ef7..3427a32d5e976 100644 --- a/routers/web/admin/config.go +++ b/routers/web/admin/config.go @@ -198,27 +198,18 @@ func ConfigSettings(ctx *context.Context) { func ChangeConfig(ctx *context.Context) { cfg := setting.Config() - marshalBool := func(v string) (string, error) { //nolint:unparam // error is always nil - if b, _ := strconv.ParseBool(v); b { - return "true", nil - } - return "false", nil + marshalBool := func(v string) ([]byte, error) { //nolint:unparam // error is always nil + b, _ := strconv.ParseBool(v) + return json.Marshal(b) } - marshalString := func(emptyDefault string) func(v string) (string, error) { - return func(v string) (string, error) { - if v == "" { - v = emptyDefault - } - b, err := json.Marshal(v) - if err != nil { - return "", err - } - return string(b), nil + marshalString := func(emptyDefault string) func(v string) ([]byte, error) { + return func(v string) ([]byte, error) { + return json.Marshal(util.IfZero(v, emptyDefault)) } } - marshalOpenWithApps := func(value string) (string, error) { + marshalOpenWithApps := func(value string) ([]byte, error) { lines := strings.Split(value, "\n") var openWithEditorApps setting.OpenWithEditorAppsType for _, line := range lines { @@ -236,13 +227,9 @@ func ChangeConfig(ctx *context.Context) { OpenURL: strings.TrimSpace(openURL), }) } - b, err := json.Marshal(openWithEditorApps) - if err != nil { - return "", err - } - return string(b), nil + return json.Marshal(openWithEditorApps) } - marshallers := map[string]func(string) (string, error){ + marshallers := map[string]func(string) ([]byte, error){ cfg.Picture.DisableGravatar.DynKey(): marshalBool, cfg.Picture.EnableFederatedAvatar.DynKey(): marshalBool, cfg.Repository.OpenWithEditorApps.DynKey(): marshalOpenWithApps, @@ -250,15 +237,16 @@ func ChangeConfig(ctx *context.Context) { } _ = ctx.Req.ParseForm() - queryKeys := ctx.Req.Form["key"] - queryValues := ctx.Req.Form["value"] + configKeys := ctx.Req.Form["key"] + configValues := ctx.Req.Form["value"] + configSettings := map[string]string{} loop: - for i, key := range queryKeys { - if i >= len(queryValues) { + for i, key := range configKeys { + if i >= len(configValues) { ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key)) break loop } - value := queryValues[i] + value := configValues[i] marshaller, hasMarshaller := marshallers[key] if !hasMarshaller { @@ -271,15 +259,15 @@ loop: ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key)) break loop } - - if err = system_model.SetSettings(ctx, map[string]string{key: marshaledValue}); err != nil { - ctx.JSONError(ctx.Tr("admin.config.set_setting_failed", key)) - break loop - } + configSettings[key] = string(marshaledValue) } - - config.GetDynGetter().InvalidateCache() - if !ctx.Written() { - ctx.JSONOK() + if ctx.Written() { + return + } + if err := system_model.SetSettings(ctx, configSettings); err != nil { + ctx.ServerError("SetSettings", err) + return } + config.GetDynGetter().InvalidateCache() + ctx.JSONOK() } From 93315df850b30a3194bb759dfe80db6104bd8c9a Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 21 Aug 2025 14:03:21 +0800 Subject: [PATCH 12/12] fix lint --- routers/web/admin/config.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/routers/web/admin/config.go b/routers/web/admin/config.go index 3427a32d5e976..310ebd3f6d46d 100644 --- a/routers/web/admin/config.go +++ b/routers/web/admin/config.go @@ -198,7 +198,7 @@ func ConfigSettings(ctx *context.Context) { func ChangeConfig(ctx *context.Context) { cfg := setting.Config() - marshalBool := func(v string) ([]byte, error) { //nolint:unparam // error is always nil + marshalBool := func(v string) ([]byte, error) { b, _ := strconv.ParseBool(v) return json.Marshal(b) } @@ -210,6 +210,7 @@ func ChangeConfig(ctx *context.Context) { } marshalOpenWithApps := func(value string) ([]byte, error) { + // TODO: move the block alongside OpenWithEditorAppsType.ToTextareaString lines := strings.Split(value, "\n") var openWithEditorApps setting.OpenWithEditorAppsType for _, line := range lines {