Skip to content

Commit 6838b29

Browse files
committed
Default to creating pull request for base repository on file edit
* When editing the default branch and there is a base repository, make the default commit choice creating a new branch. * When creating the pull request, default compare it against the base repository default branch. This matches the behavior of creating a pull request based on a branch elsewhere in the UI. This makes it easier to do the right thing for contributing changes from a fork.
1 parent 2683adf commit 6838b29

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

routers/web/repo/editor.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ func canCreateBasePullRequest(ctx *context.Context) bool {
4545
return baseRepo != nil && baseRepo.UnitEnabled(ctx, unit.TypePullRequests)
4646
}
4747

48+
func defaultCreateNewBranch(ctx *context.Context) bool {
49+
baseRepo := ctx.Repo.Repository.BaseRepo
50+
return canCreateBasePullRequest(ctx) && baseRepo != nil && ctx.Repo.BranchName == baseRepo.DefaultBranch
51+
}
52+
4853
func renderCommitRights(ctx *context.Context) bool {
4954
canCommitToBranch, err := ctx.Repo.CanCommitToBranch(ctx, ctx.Doer)
5055
if err != nil {
@@ -64,13 +69,13 @@ func redirectForCommitChoice(ctx *context.Context, commitChoice, newBranchName,
6469
repo := ctx.Repo.Repository
6570
baseBranch := ctx.Repo.BranchName
6671
headBranch := newBranchName
67-
if repo.UnitEnabled(ctx, unit.TypePullRequests) {
68-
redirectToPullRequest = true
69-
} else if canCreateBasePullRequest(ctx) {
72+
if canCreateBasePullRequest(ctx) {
7073
redirectToPullRequest = true
7174
baseBranch = repo.BaseRepo.DefaultBranch
7275
headBranch = repo.Owner.Name + "/" + repo.Name + ":" + headBranch
7376
repo = repo.BaseRepo
77+
} else if repo.UnitEnabled(ctx, unit.TypePullRequests) {
78+
redirectToPullRequest = true
7479
}
7580

7681
if redirectToPullRequest {
@@ -189,7 +194,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
189194
ctx.Data["TreePaths"] = treePaths
190195
ctx.Data["commit_summary"] = ""
191196
ctx.Data["commit_message"] = ""
192-
ctx.Data["commit_choice"] = util.Iif(canCommit, frmCommitChoiceDirect, frmCommitChoiceNewBranch)
197+
ctx.Data["commit_choice"] = util.Iif(canCommit && !defaultCreateNewBranch(ctx), frmCommitChoiceDirect, frmCommitChoiceNewBranch)
193198
ctx.Data["new_branch_name"] = GetUniquePatchBranchName(ctx)
194199
ctx.Data["last_commit"] = ctx.Repo.CommitID
195200

@@ -446,11 +451,7 @@ func DeleteFile(ctx *context.Context) {
446451
ctx.Data["commit_summary"] = ""
447452
ctx.Data["commit_message"] = ""
448453
ctx.Data["last_commit"] = ctx.Repo.CommitID
449-
if canCommit {
450-
ctx.Data["commit_choice"] = frmCommitChoiceDirect
451-
} else {
452-
ctx.Data["commit_choice"] = frmCommitChoiceNewBranch
453-
}
454+
ctx.Data["commit_choice"] = util.Iif(canCommit && !defaultCreateNewBranch(ctx), frmCommitChoiceDirect, frmCommitChoiceNewBranch)
454455
ctx.Data["new_branch_name"] = GetUniquePatchBranchName(ctx)
455456

456457
ctx.HTML(http.StatusOK, tplDeleteFile)
@@ -620,11 +621,7 @@ func UploadFile(ctx *context.Context) {
620621
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
621622
ctx.Data["commit_summary"] = ""
622623
ctx.Data["commit_message"] = ""
623-
if canCommit {
624-
ctx.Data["commit_choice"] = frmCommitChoiceDirect
625-
} else {
626-
ctx.Data["commit_choice"] = frmCommitChoiceNewBranch
627-
}
624+
ctx.Data["commit_choice"] = util.Iif(canCommit && !defaultCreateNewBranch(ctx), frmCommitChoiceDirect, frmCommitChoiceNewBranch)
628625
ctx.Data["new_branch_name"] = GetUniquePatchBranchName(ctx)
629626

630627
ctx.HTML(http.StatusOK, tplUploadFile)

0 commit comments

Comments
 (0)