Skip to content

Commit 680639a

Browse files
committed
fix
1 parent 7eae056 commit 680639a

File tree

9 files changed

+35
-33
lines changed

9 files changed

+35
-33
lines changed

modules/setting/config.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,12 @@ func DefaultOpenWithEditorApps() OpenWithEditorAppsType {
4949

5050
type RepositoryStruct struct {
5151
OpenWithEditorApps *config.Value[OpenWithEditorAppsType]
52-
}
53-
54-
type TemplateStruct struct {
55-
GitRemoteName *config.Value[string]
52+
GitGuideRemoteName *config.Value[string]
5653
}
5754

5855
type ConfigStruct struct {
5956
Picture *PictureStruct
6057
Repository *RepositoryStruct
61-
Template *TemplateStruct
6258
}
6359

6460
var (
@@ -75,9 +71,7 @@ func initDefaultConfig() {
7571
},
7672
Repository: &RepositoryStruct{
7773
OpenWithEditorApps: config.ValueJSON[OpenWithEditorAppsType]("repository.open-with.editor-apps"),
78-
},
79-
Template: &TemplateStruct{
80-
GitRemoteName: config.ValueJSON[string]("template.git-remote-name").WithDefault("origin"),
74+
GitGuideRemoteName: config.ValueJSON[string]("repository.git-guide-remote-name").WithDefault("origin"),
8175
},
8276
}
8377
}

modules/setting/config/value.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Value[T any] struct {
2828

2929
func (value *Value[T]) parse(key, valStr string) (v T) {
3030
v = value.def
31-
if valStr != "" && valStr != "null" {
31+
if valStr != "" {
3232
if err := json.Unmarshal(util.UnsafeStringToBytes(valStr), &v); err != nil {
3333
log.Error("Unable to unmarshal json config for key %q, err: %v", key, err)
3434
}
@@ -46,7 +46,7 @@ func (value *Value[T]) Value(ctx context.Context) (v T) {
4646

4747
rev := dg.GetRevision(ctx)
4848

49-
// if the revision in database doesn't change, use the last value
49+
// if the revision in the database doesn't change, use the last value
5050
value.mu.RLock()
5151
if rev == value.revision {
5252
v = value.value
@@ -84,6 +84,10 @@ func (value *Value[T]) WithDefault(def T) *Value[T] {
8484
return value
8585
}
8686

87+
func (value *Value[T]) DefaultValue() T {
88+
return value.def
89+
}
90+
8791
func (value *Value[T]) WithFileConfig(cfgSecKey CfgSecKey) *Value[T] {
8892
value.cfgSecKey = cfgSecKey
8993
return value

routers/web/admin/config.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,17 @@ func ChangeConfig(ctx *context.Context) {
205205
return "false", nil
206206
}
207207

208-
marshalString := func(v string) (string, error) {
209-
if strings.TrimSpace(v) == "" {
210-
return "null", nil
211-
}
212-
b, err := json.Marshal(v)
213-
if err != nil {
214-
return "", err
208+
marshalString := func(emptyDefault string) func(v string) (string, error) {
209+
return func(v string) (string, error) {
210+
if v == "" {
211+
v = emptyDefault
212+
}
213+
b, err := json.Marshal(v)
214+
if err != nil {
215+
return "", err
216+
}
217+
return string(b), nil
215218
}
216-
return string(b), nil
217219
}
218220

219221
marshalOpenWithApps := func(value string) (string, error) {
@@ -244,7 +246,7 @@ func ChangeConfig(ctx *context.Context) {
244246
cfg.Picture.DisableGravatar.DynKey(): marshalBool,
245247
cfg.Picture.EnableFederatedAvatar.DynKey(): marshalBool,
246248
cfg.Repository.OpenWithEditorApps.DynKey(): marshalOpenWithApps,
247-
cfg.Template.GitRemoteName.DynKey(): marshalString,
249+
cfg.Repository.GitGuideRemoteName.DynKey(): marshalString(cfg.Repository.GitGuideRemoteName.DefaultValue()),
248250
}
249251

250252
_ = ctx.Req.ParseForm()

routers/web/repo/issue_view.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ func ViewPullMergeBox(ctx *context.Context) {
446446

447447
// TODO: it should use a dedicated struct to render the pull merge box, to make sure all data is prepared correctly
448448
ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.Doer.ID)
449-
ctx.Data["GitRemoteName"] = setting.Config().Template.GitRemoteName.Value(ctx)
450449
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
451450
ctx.HTML(http.StatusOK, tplPullMergeBox)
452451
}

services/context/repo.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ func RepoAssignment(ctx *Context) {
542542
ctx.Data["CanWriteIssues"] = ctx.Repo.CanWrite(unit_model.TypeIssues)
543543
ctx.Data["CanWritePulls"] = ctx.Repo.CanWrite(unit_model.TypePullRequests)
544544
ctx.Data["CanWriteActions"] = ctx.Repo.CanWrite(unit_model.TypeActions)
545-
ctx.Data["GitRemoteName"] = setting.Config().Template.GitRemoteName.Value(ctx)
546545

547546
canSignedUserFork, err := repo_module.CanUserForkRepo(ctx, ctx.Doer, ctx.Repo.Repository)
548547
if err != nil {

templates/admin/config_settings.tmpl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@
3232
</details>
3333
</div>
3434
<div class="field">
35-
<input type="hidden" name="key" value="{{.SystemConfig.Repository.OpenWithEditorApps.DynKey}}">
36-
<textarea name="value">{{(.SystemConfig.Repository.OpenWithEditorApps.Value ctx).ToTextareaString}}</textarea>
35+
{{$cfg := .SystemConfig.Repository.OpenWithEditorApps}}
36+
<input type="hidden" name="key" value="{{$cfg.DynKey}}">
37+
<textarea name="value">{{($cfg.Value ctx).ToTextareaString}}</textarea>
3738
</div>
3839

3940
<div class="field">
4041
<label>{{ctx.Locale.Tr "admin.config.git_guide_remote_name"}}</label>
41-
<input type="hidden" name="key" value="{{.SystemConfig.Template.GitRemoteName.DynKey}}">
42-
<input name="value" value="{{.SystemConfig.Template.GitRemoteName.Value ctx}}" maxlength="100" dir="auto" required pattern="^[A-Za-z0-9][\-_A-Za-z0-9]*$">
42+
{{$cfg = .SystemConfig.Repository.GitGuideRemoteName}}
43+
<input type="hidden" name="key" value="{{$cfg.DynKey}}">
44+
<input name="value" value="{{$cfg.Value ctx}}" placeholder="{{$cfg.DefaultValue}}" maxlength="100" dir="auto" required pattern="^[A-Za-z0-9][\-_A-Za-z0-9]*$">
4345
</div>
4446
<div class="field">
4547
<button class="ui primary button">{{ctx.Locale.Tr "save"}}</button>

templates/repo/empty.tmpl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,23 @@
4646
<div class="item">
4747
<h3>{{ctx.Locale.Tr "repo.create_new_repo_command"}}</h3>
4848
<div class="markup">
49+
{{$gitRemoteName := $.SystemConfig.Repository.GitGuideRemoteName.Value ctx}}
4950
<pre><code>touch README.md
5051
git init{{if ne .Repository.ObjectFormatName "sha1"}} --object-format={{.Repository.ObjectFormatName}}{{end}}{{/* for sha256 repo, it needs to set "object-format" explicitly*/}}
5152
{{if ne .Repository.DefaultBranch "master"}}git checkout -b {{.Repository.DefaultBranch}}{{end}}
5253
git add README.md
5354
git commit -m "first commit"
54-
git remote add {{.GitRemoteName}} <span class="js-clone-url">{{$.CloneButtonOriginLink.HTTPS}}</span>
55-
git push -u {{.GitRemoteName}} {{.Repository.DefaultBranch}}</code></pre>
55+
git remote add {{$gitRemoteName}} <span class="js-clone-url">{{$.CloneButtonOriginLink.HTTPS}}</span>
56+
git push -u {{$gitRemoteName}} {{.Repository.DefaultBranch}}</code></pre>
5657
</div>
5758
</div>
5859
<div class="divider"></div>
5960

6061
<div class="item">
6162
<h3>{{ctx.Locale.Tr "repo.push_exist_repo"}}</h3>
6263
<div class="markup">
63-
<pre><code>git remote add {{.GitRemoteName}} <span class="js-clone-url">{{$.CloneButtonOriginLink.HTTPS}}</span>
64-
git push -u {{.GitRemoteName}} {{.Repository.DefaultBranch}}</code></pre>
64+
<pre><code>git remote add {{$gitRemoteName}} <span class="js-clone-url">{{$.CloneButtonOriginLink.HTTPS}}</span>
65+
git push -u {{$gitRemoteName}} {{.Repository.DefaultBranch}}</code></pre>
6566
</div>
6667
</div>
6768
{{end}}

templates/repo/issue/view_content/pull_merge_box.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@
396396
{{end}}
397397

398398
{{if and .Issue.PullRequest.HeadRepo (not .Issue.PullRequest.HasMerged) (not .Issue.IsClosed)}}
399-
{{template "repo/issue/view_content/pull_merge_instruction" dict "PullRequest" .Issue.PullRequest "ShowMergeInstructions" .ShowMergeInstructions "GitRemoteName" .GitRemoteName}}
399+
{{template "repo/issue/view_content/pull_merge_instruction" dict "PullRequest" .Issue.PullRequest "ShowMergeInstructions" .ShowMergeInstructions}}
400400
{{end}}
401401
</div>
402402
</div>

templates/repo/issue/view_content/pull_merge_instruction.tmpl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
{{$localBranch = print .PullRequest.HeadRepo.OwnerName "-" .PullRequest.HeadBranch}}
99
{{end}}
1010
<div class="ui secondary segment tw-font-mono">
11+
{{$gitRemoteName := ctx.RootData.SystemConfig.Repository.GitGuideRemoteName.Value ctx}}
1112
{{if eq .PullRequest.Flow 0}}
12-
<div>git fetch -u {{if ne .PullRequest.HeadRepo.ID .PullRequest.BaseRepo.ID}}<origin-url data-url="{{.PullRequest.HeadRepo.Link}}"></origin-url>{{else}}{{.GitRemoteName}}{{end}} {{.PullRequest.HeadBranch}}:{{$localBranch}}</div>
13+
<div>git fetch -u {{if ne .PullRequest.HeadRepo.ID .PullRequest.BaseRepo.ID}}<origin-url data-url="{{.PullRequest.HeadRepo.Link}}"></origin-url>{{else}}{{$gitRemoteName}}{{end}} {{.PullRequest.HeadBranch}}:{{$localBranch}}</div>
1314
{{else}}
14-
<div>git fetch -u {{.GitRemoteName}} {{.PullRequest.GetGitHeadRefName}}:{{$localBranch}}</div>
15+
<div>git fetch -u {{$gitRemoteName}} {{.PullRequest.GetGitHeadRefName}}:{{$localBranch}}</div>
1516
{{end}}
1617
<div>git checkout {{$localBranch}}</div>
1718
</div>
@@ -50,7 +51,7 @@
5051
<div>git checkout {{.PullRequest.BaseBranch}}</div>
5152
<div>git merge {{$localBranch}}</div>
5253
</div>
53-
<div>git push {{.GitRemoteName}} {{.PullRequest.BaseBranch}}</div>
54+
<div>git push {{$gitRemoteName}} {{.PullRequest.BaseBranch}}</div>
5455
</div>
5556
{{end}}
5657
</div>

0 commit comments

Comments
 (0)