Skip to content

Commit d39b516

Browse files
guillep2k6543
authored andcommitted
Fix editor commit to new branch if PR disabled (go-gitea#8375)
1 parent 5bac1a6 commit d39b516

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

Diff for: options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ editor.delete = Delete '%s'
694694
editor.commit_message_desc = Add an optional extended description…
695695
editor.commit_directly_to_this_branch = Commit directly to the <strong class="branch-name">%s</strong> branch.
696696
editor.create_new_branch = Create a <strong>new branch</strong> for this commit and start a pull request.
697+
editor.create_new_branch_np = Create a <strong>new branch</strong> for this commit.
697698
editor.propose_file_change = Propose file change
698699
editor.new_branch_name_desc = New branch name…
699700
editor.cancel = Cancel

Diff for: routers/repo/editor.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
269269
}
270270
}
271271

272-
if form.CommitChoice == frmCommitChoiceNewBranch {
272+
if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) {
273273
ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + ctx.Repo.BranchName + "..." + form.NewBranchName)
274274
} else {
275275
ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(branchName) + "/" + util.PathEscapeSegments(form.TreePath))
@@ -434,7 +434,7 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
434434
}
435435

436436
ctx.Flash.Success(ctx.Tr("repo.editor.file_delete_success", ctx.Repo.TreePath))
437-
if form.CommitChoice == frmCommitChoiceNewBranch {
437+
if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) {
438438
ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + ctx.Repo.BranchName + "..." + form.NewBranchName)
439439
} else {
440440
treePath := filepath.Dir(ctx.Repo.TreePath)
@@ -589,7 +589,7 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
589589
return
590590
}
591591

592-
if form.CommitChoice == frmCommitChoiceNewBranch {
592+
if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) {
593593
ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + ctx.Repo.BranchName + "..." + form.NewBranchName)
594594
} else {
595595
ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(branchName) + "/" + util.PathEscapeSegments(form.TreePath))

Diff for: templates/repo/editor/commit_form.tmpl

+12-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,21 @@
1919
</div>
2020
</div>
2121
<div class="field">
22+
{{$pullRequestEnabled := .Repository.UnitEnabled $.UnitTypePullRequests}}
23+
{{$prUnit := .Repository.MustGetUnit $.UnitTypePullRequests}}
2224
<div class="ui radio checkbox">
23-
<input type="radio" class="js-quick-pull-choice-option" name="commit_choice" value="commit-to-new-branch" button_text="{{.i18n.Tr "repo.editor.propose_file_change"}}" {{if eq .commit_choice "commit-to-new-branch"}}checked{{end}}>
25+
{{if $pullRequestEnabled}}
26+
<input type="radio" class="js-quick-pull-choice-option" name="commit_choice" value="commit-to-new-branch" button_text="{{.i18n.Tr "repo.editor.propose_file_change"}}" {{if eq .commit_choice "commit-to-new-branch"}}checked{{end}}>
27+
{{else}}
28+
<input type="radio" class="js-quick-pull-choice-option" name="commit_choice" value="commit-to-new-branch" button_text="{{.i18n.Tr "repo.editor.commit_changes"}}" {{if eq .commit_choice "commit-to-new-branch"}}checked{{end}}>
29+
{{end}}
2430
<label>
2531
<i class="octicon octicon-git-pull-request" height="16" width="12"></i>
26-
{{.i18n.Tr "repo.editor.create_new_branch" | Safe}}
32+
{{if $pullRequestEnabled}}
33+
{{.i18n.Tr "repo.editor.create_new_branch" | Safe}}
34+
{{else}}
35+
{{.i18n.Tr "repo.editor.create_new_branch_np" | Safe}}
36+
{{end}}
2737
</label>
2838
</div>
2939
</div>

0 commit comments

Comments
 (0)