Skip to content

Commit 8313490

Browse files
committed
show "Add File", check branch name, move prompt, handle json error
1 parent 03b3e53 commit 8313490

File tree

13 files changed

+71
-37
lines changed

13 files changed

+71
-37
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,7 @@ editor.fork_create_description = You can not edit this repository directly. Inst
14041404
editor.fork_edit_description = You can not edit this repository directly. The changes will be written to your fork <b>%s</b>, so you can create a pull request.
14051405
editor.fork_not_editable = You have forked this repository but your fork is not editable.
14061406
editor.fork_failed_to_push_branch = Failed to push branch %s to your repository.
1407+
editor.fork_branch_exists = Branch "%s" already exists in your fork, please choose a new branch name.
14071408
14081409
commits.desc = Browse source code change history.
14091410
commits.commits = Commits

routers/web/repo/editor.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,17 @@ func prepareEditorCommitSubmittedForm[T forms.CommitCommonFormInterface](ctx *co
146146
oldBranchName := ctx.Repo.BranchName
147147
fromBaseBranch := ctx.FormString("from_base_branch")
148148
if fromBaseBranch != "" {
149-
err = editorPushBranchToForkedRepository(ctx, ctx.Doer, ctx.Repo.Repository.BaseRepo, fromBaseBranch, ctx.Repo.Repository, targetBranchName)
149+
// if target branch exists, we should warn users
150+
targetBranchExists, err := git_model.IsBranchExist(ctx, commitFormOptions.TargetRepo.ID, targetBranchName)
151+
if err != nil {
152+
ctx.ServerError("IsBranchExist", err)
153+
return nil
154+
}
155+
if targetBranchExists {
156+
ctx.JSONError(ctx.Tr("repo.editor.fork_branch_exists", targetBranchName))
157+
return nil
158+
}
159+
err = editorPushBranchToForkedRepository(ctx, ctx.Doer, ctx.Repo.Repository.BaseRepo, fromBaseBranch, commitFormOptions.TargetRepo, targetBranchName)
150160
if err != nil {
151161
log.Error("Unable to editorPushBranchToForkedRepository: %v", err)
152162
ctx.JSONError(ctx.Tr("repo.editor.fork_failed_to_push_branch", targetBranchName))

templates/repo/editor/cherry_pick.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{{template "base/alert" .}}
66
<form class="ui edit form form-fetch-action" method="post" action="{{.CommitFormOptions.TargetFormAction}}">
77
{{.CsrfTokenHtml}}
8+
{{template "repo/editor/common_top" .}}
89
<input type="hidden" name="revert" value="{{if eq .CherryPickType "revert"}}true{{else}}false{{end}}">
910
<div class="repo-editor-header">
1011
<div class="breadcrumb">

templates/repo/editor/commit_form.tmpl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@
7878
{{end}}
7979
</div>
8080
<input type="hidden" name="last_commit" value="{{.last_commit}}">
81-
82-
{{if .CommitFormOptions.WillSubmitToFork}}
83-
<div class="ui blue message">
84-
<p>{{ctx.Locale.Tr "repo.editor.fork_edit_description" .CommitFormOptions.TargetRepo.FullName}}</p>
85-
</div>
86-
{{end}}
8781
<button id="commit-button" type="submit" class="ui primary button">
8882
{{if eq .commit_choice "commit-to-new-branch"}}{{ctx.Locale.Tr "repo.editor.propose_file_change"}}{{else}}{{ctx.Locale.Tr "repo.editor.commit_changes"}}{{end}}
8983
</button>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{{if .CommitFormOptions.WillSubmitToFork}}
2+
<div class="ui blue message">
3+
{{ctx.Locale.Tr "repo.editor.fork_edit_description" .CommitFormOptions.TargetRepo.FullName}}
4+
</div>
5+
{{end}}

templates/repo/editor/delete.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{{template "base/alert" .}}
66
<form class="ui form form-fetch-action" method="post" action="{{.CommitFormOptions.TargetFormAction}}">
77
{{.CsrfTokenHtml}}
8+
{{template "repo/editor/common_top" .}}
89
{{template "repo/editor/commit_form" .}}
910
</form>
1011
</div>

templates/repo/editor/edit.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
{{template "repo/editor/common_breadcrumb" .}}
1313
</div>
1414
{{if not .NotEditableReason}}
15+
{{template "repo/editor/common_top" .}}
1516
<div class="field">
1617
<div class="ui top attached header">
1718
<div class="ui compact small menu small-menu-items repo-editor-menu">

templates/repo/editor/patch.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<input id="file-name" type="hidden" value="diff.patch">
2020
</div>
2121
</div>
22+
{{template "repo/editor/common_top" .}}
2223
<div class="field">
2324
<div class="ui compact small menu small-menu-items repo-editor-menu">
2425
<a class="active item" data-tab="write">{{svg "octicon-code" 16 "tw-mr-1"}}{{ctx.Locale.Tr "repo.editor.new_patch"}}</a>

templates/repo/editor/upload.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<div class="repo-editor-header">
99
{{template "repo/editor/common_breadcrumb" .}}
1010
</div>
11+
{{template "repo/editor/common_top" .}}
1112
<div class="field">
1213
{{template "repo/upload" .}}
1314
</div>

templates/repo/view_content.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
<a href="{{.Repository.Link}}/find/{{.RefTypeNameSubURL}}" class="ui compact basic button">{{ctx.Locale.Tr "repo.find_file.go_to_file"}}</a>
4242
{{end}}
4343

44-
{{if and .CanWriteCode .RefFullName.IsBranch (not .Repository.IsMirror) (not .Repository.IsArchived) (not .IsViewFile)}}
45-
<button class="ui dropdown basic compact jump button"{{if not .Repository.CanEnableEditor}} disabled{{end}}>
44+
{{if and .RefFullName.IsBranch (not .IsViewFile)}}
45+
<button class="ui dropdown basic compact jump button repo-add-file" {{if not .Repository.CanEnableEditor}}disabled{{end}}>
4646
{{ctx.Locale.Tr "repo.editor.add_file"}}
4747
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
4848
<div class="menu">

0 commit comments

Comments
 (0)