Skip to content

Commit ebd172d

Browse files
committed
Prefer creating PR for base, disable editing default branch in fork
1 parent 85d4bef commit ebd172d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

routers/web/repo/editor.go

Lines changed: 8 additions & 7 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
}
@@ -62,13 +63,13 @@ func redirectToPullRequest(ctx *context.Context, newBranchName string) bool {
6263
repo := ctx.Repo.Repository
6364
baseBranch := util.PathEscapeSegments(ctx.Repo.BranchName)
6465
headBranch := util.PathEscapeSegments(newBranchName)
65-
if !repo.UnitEnabled(ctx, unit.TypePullRequests) {
66-
if !canCreateBasePullRequest(ctx) {
67-
return false
68-
}
66+
if repo.UnitEnabled(ctx, unit.TypePullRequests) {
67+
} else if canCreateBasePullRequest(ctx) {
6968
baseBranch = util.PathEscapeSegments(repo.BaseRepo.DefaultBranch)
7069
headBranch = util.PathEscapeSegments(repo.Owner.Name) + "/" + util.PathEscapeSegments(repo.Name) + ":" + headBranch
7170
repo = repo.BaseRepo
71+
} else {
72+
return false
7273
}
7374
ctx.Redirect(repo.Link() + "/compare/" + baseBranch + "..." + headBranch)
7475
return true
@@ -172,7 +173,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
172173
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
173174
ctx.Data["commit_summary"] = ""
174175
ctx.Data["commit_message"] = ""
175-
if canCommit {
176+
if canCommit && !canCreateBasePullRequest(ctx) {
176177
ctx.Data["commit_choice"] = frmCommitChoiceDirect
177178
} else {
178179
ctx.Data["commit_choice"] = frmCommitChoiceNewBranch
@@ -421,7 +422,7 @@ func DeleteFile(ctx *context.Context) {
421422
ctx.Data["commit_summary"] = ""
422423
ctx.Data["commit_message"] = ""
423424
ctx.Data["last_commit"] = ctx.Repo.CommitID
424-
if canCommit {
425+
if canCommit && !canCreateBasePullRequest(ctx) {
425426
ctx.Data["commit_choice"] = frmCommitChoiceDirect
426427
} else {
427428
ctx.Data["commit_choice"] = frmCommitChoiceNewBranch
@@ -581,7 +582,7 @@ func UploadFile(ctx *context.Context) {
581582
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
582583
ctx.Data["commit_summary"] = ""
583584
ctx.Data["commit_message"] = ""
584-
if canCommit {
585+
if canCommit && !canCreateBasePullRequest(ctx) {
585586
ctx.Data["commit_choice"] = frmCommitChoiceDirect
586587
} else {
587588
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="{{.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 not .Repository.IsEmpty}}
4345
<div class="field">
4446
<div class="ui radio checkbox">

0 commit comments

Comments
 (0)