Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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 modules/setting/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func DefaultOpenWithEditorApps() OpenWithEditorAppsType {

type RepositoryStruct struct {
OpenWithEditorApps *config.Value[OpenWithEditorAppsType]
SnippetRemoteName *config.Value[string]
}

type ConfigStruct struct {
Expand All @@ -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"),
},
}
}
Expand Down
4 changes: 4 additions & 0 deletions modules/setting/config/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions routers/web/admin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions routers/web/repo/issue_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Config().Repository.SnippetRemoteName.Value(ctx)
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
ctx.HTML(http.StatusOK, tplPullMergeBox)
}
Expand Down
1 change: 1 addition & 0 deletions services/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Config().Repository.SnippetRemoteName.Value(ctx)

canSignedUserFork, err := repo_module.CanUserForkRepo(ctx, ctx.Doer, ctx.Repo.Repository)
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions templates/admin/config_settings.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,19 @@
</div>
</form>
</div>

<h4 class="ui top attached header">
{{ctx.Locale.Tr "admin.config.repository_snippets"}}
</h4>
<div class="ui attached segment">
<form class="ui form form-fetch-action" method="post" action="{{AppSubUrl}}/-/admin/config?key={{.SystemConfig.Repository.SnippetRemoteName.DynKey}}">
<div class="field" data-field-patched="true">
<label for="remote_name">{{ctx.Locale.Tr "admin.config.repository_snippets.remote_name"}}</label>
<input id="remote_name" name="value" value="{{.SystemConfig.Repository.SnippetRemoteName.Value ctx}}" maxlength="100" dir="auto" placeholder="{{.SystemConfig.Repository.SnippetRemoteName.Def}}">
</div>
<div class="field">
<button class="ui primary button">{{ctx.Locale.Tr "save"}}</button>
</div>
</form>
</div>
{{template "admin/layout_footer" .}}
8 changes: 4 additions & 4 deletions templates/repo/empty.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ 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 <span class="js-clone-url">{{$.CloneButtonOriginLink.HTTPS}}</span>
git push -u origin {{.Repository.DefaultBranch}}</code></pre>
git remote add {{.SnippetRemoteName}} <span class="js-clone-url">{{$.CloneButtonOriginLink.HTTPS}}</span>
git push -u {{.SnippetRemoteName}} {{.Repository.DefaultBranch}}</code></pre>
</div>
</div>
<div class="divider"></div>

<div class="item">
<h3>{{ctx.Locale.Tr "repo.push_exist_repo"}}</h3>
<div class="markup">
<pre><code>git remote add origin <span class="js-clone-url">{{$.CloneButtonOriginLink.HTTPS}}</span>
git push -u origin {{.Repository.DefaultBranch}}</code></pre>
<pre><code>git remote add {{.SnippetRemoteName}} <span class="js-clone-url">{{$.CloneButtonOriginLink.HTTPS}}</span>
git push -u {{.SnippetRemoteName}} {{.Repository.DefaultBranch}}</code></pre>
</div>
</div>
{{end}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/issue/view_content/pull_merge_box.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions templates/repo/issue/view_content/pull_merge_instruction.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
{{end}}
<div class="ui secondary segment tw-font-mono">
{{if eq .PullRequest.Flow 0}}
<div>git fetch -u {{if ne .PullRequest.HeadRepo.ID .PullRequest.BaseRepo.ID}}<origin-url data-url="{{.PullRequest.HeadRepo.Link}}"></origin-url>{{else}}origin{{end}} {{.PullRequest.HeadBranch}}:{{$localBranch}}</div>
<div>git fetch -u {{if ne .PullRequest.HeadRepo.ID .PullRequest.BaseRepo.ID}}<origin-url data-url="{{.PullRequest.HeadRepo.Link}}"></origin-url>{{else}}{{.SnippetRemoteName}}{{end}} {{.PullRequest.HeadBranch}}:{{$localBranch}}</div>
{{else}}
<div>git fetch -u origin {{.PullRequest.GetGitHeadRefName}}:{{$localBranch}}</div>
<div>git fetch -u {{.SnippetRemoteName}} {{.PullRequest.GetGitHeadRefName}}:{{$localBranch}}</div>
{{end}}
<div>git checkout {{$localBranch}}</div>
</div>
Expand Down Expand Up @@ -50,7 +50,7 @@
<div>git checkout {{.PullRequest.BaseBranch}}</div>
<div>git merge {{$localBranch}}</div>
</div>
<div>git push origin {{.PullRequest.BaseBranch}}</div>
<div>git push {{.SnippetRemoteName}} {{.PullRequest.BaseBranch}}</div>
</div>
{{end}}
</div>
Expand Down