aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/context/repo.go10
-rw-r--r--routers/repo/editor.go12
2 files changed, 16 insertions, 6 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 710cbbf6..fdde6b92 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -98,6 +98,16 @@ func (r *Repository) GetEditorconfig() (*editorconfig.Editorconfig, error) {
return editorconfig.ParseBytes(data)
}
+// PullRequestURL returns URL for composing a pull request.
+// This function does not check if the repository can actually compose a pull request.
+func (r *Repository) PullRequestURL(baseBranch, headBranch string) string {
+ repoLink := r.RepoLink
+ if r.PullRequest.BaseRepo != nil {
+ repoLink = r.PullRequest.BaseRepo.Link()
+ }
+ return fmt.Sprintf("%s/compare/%s...%s:%s", repoLink, baseBranch, r.Owner.Name, headBranch)
+}
+
func RetrieveBaseRepo(ctx *Context, repo *models.Repository) {
// Non-fork repository will not return error in this method.
if err := repo.GetBaseRepo(); err != nil {
diff --git a/routers/repo/editor.go b/routers/repo/editor.go
index 326a8c7e..83302039 100644
--- a/routers/repo/editor.go
+++ b/routers/repo/editor.go
@@ -279,8 +279,8 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
return
}
- if form.IsNewBrnach() {
- ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + oldBranchName + "..." + form.NewBranchName)
+ if form.IsNewBrnach() && ctx.Repo.PullRequest.Allowed {
+ ctx.Redirect(ctx.Repo.PullRequestURL(oldBranchName, form.NewBranchName))
} else {
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + template.EscapePound(form.TreePath))
}
@@ -382,8 +382,8 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
return
}
- if form.IsNewBrnach() {
- ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + oldBranchName + "..." + form.NewBranchName)
+ if form.IsNewBrnach() && ctx.Repo.PullRequest.Allowed {
+ ctx.Redirect(ctx.Repo.PullRequestURL(oldBranchName, form.NewBranchName))
} else {
ctx.Flash.Success(ctx.Tr("repo.editor.file_delete_success", ctx.Repo.TreePath))
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName)
@@ -503,8 +503,8 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
return
}
- if form.IsNewBrnach() {
- ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + oldBranchName + "..." + form.NewBranchName)
+ if form.IsNewBrnach() && ctx.Repo.PullRequest.Allowed {
+ ctx.Redirect(ctx.Repo.PullRequestURL(oldBranchName, form.NewBranchName))
} else {
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + form.TreePath)
}