Skip to content

Commit cd674b0

Browse files
brechtvlbartvdbraak
authored andcommitted
BLENDER: Prefer creating PR for base, disable editing default branch in fork
To make online editing a bit more fool proof.
1 parent 2e6193c commit cd674b0

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

routers/web/repo/editor.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func renderCommitRights(ctx *context.Context) bool {
5353
}
5454
ctx.Data["CanCommitToBranch"] = canCommitToBranch
5555
ctx.Data["CanCreatePullRequest"] = ctx.Repo.Repository.UnitEnabled(ctx, unit.TypePullRequests) || canCreateBasePullRequest(ctx)
56+
ctx.Data["IsForkDefaultBranch"] = canCreateBasePullRequest(ctx) && ctx.Repo.BranchName == ctx.Repo.Repository.BaseRepo.DefaultBranch
5657

5758
return canCommitToBranch.CanCommitToBranch
5859
}
@@ -184,7 +185,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
184185
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
185186
ctx.Data["commit_summary"] = ""
186187
ctx.Data["commit_message"] = ""
187-
if canCommit {
188+
if canCommit && !canCreateBasePullRequest(ctx) {
188189
ctx.Data["commit_choice"] = frmCommitChoiceDirect
189190
} else {
190191
ctx.Data["commit_choice"] = frmCommitChoiceNewBranch
@@ -443,7 +444,7 @@ func DeleteFile(ctx *context.Context) {
443444
ctx.Data["commit_summary"] = ""
444445
ctx.Data["commit_message"] = ""
445446
ctx.Data["last_commit"] = ctx.Repo.CommitID
446-
if canCommit {
447+
if canCommit && !canCreateBasePullRequest(ctx) {
447448
ctx.Data["commit_choice"] = frmCommitChoiceDirect
448449
} else {
449450
ctx.Data["commit_choice"] = frmCommitChoiceNewBranch
@@ -608,7 +609,7 @@ func UploadFile(ctx *context.Context) {
608609
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
609610
ctx.Data["commit_summary"] = ""
610611
ctx.Data["commit_message"] = ""
611-
if canCommit {
612+
if canCommit && !canCreateBasePullRequest(ctx) {
612613
ctx.Data["commit_choice"] = frmCommitChoiceDirect
613614
} else {
614615
ctx.Data["commit_choice"] = frmCommitChoiceNewBranch

templates/repo/editor/commit_form.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
</div>
2222
</div>
2323
<div class="quick-pull-choice js-quick-pull-choice">
24+
{{if not .IsForkDefaultBranch}}
2425
<div class="field">
2526
<div class="ui radio checkbox {{if not .CanCommitToBranch.CanCommitToBranch}}disabled{{end}}">
2627
<input type="radio" class="js-quick-pull-choice-option" name="commit_choice" value="direct" button_text="{{ctx.Locale.Tr "repo.editor.commit_changes"}}" {{if eq .commit_choice "direct"}}checked{{end}}>
@@ -39,6 +40,7 @@
3940
</label>
4041
</div>
4142
</div>
43+
{{end}}
4244
{{if and (not .Repository.IsEmpty) (not .IsEditingFileOnly)}}
4345
<div class="field">
4446
<div class="ui radio checkbox">

0 commit comments

Comments
 (0)