Skip to content

Commit

Permalink
Redirect to the commit page after applying patch (#23056) (#23127)
Browse files Browse the repository at this point in the history
Backport #23056

Fixes #22621

Co-authored-by: yp05327 <576951401@qq.com>
  • Loading branch information
yardenshoham and yp05327 authored Feb 25, 2023
1 parent 7c3196c commit 28625fb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions routers/web/repo/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ func NewDiffPatch(ctx *context.Context) {

ctx.Data["PageIsPatch"] = true

ctx.Data["TreePath"] = ""

ctx.Data["commit_summary"] = ""
ctx.Data["commit_message"] = ""
if canCommit {
Expand All @@ -54,7 +52,6 @@ func NewDiffPatchPost(ctx *context.Context) {
branchName = form.NewBranchName
}
ctx.Data["PageIsPatch"] = true
ctx.Data["TreePath"] = ""
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
ctx.Data["FileContent"] = form.Content
ctx.Data["commit_summary"] = form.CommitSummary
Expand Down Expand Up @@ -89,13 +86,14 @@ func NewDiffPatchPost(ctx *context.Context) {
message += "\n\n" + form.CommitMessage
}

if _, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, &files.ApplyDiffPatchOptions{
fileResponse, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, &files.ApplyDiffPatchOptions{
LastCommitID: form.LastCommit,
OldBranch: ctx.Repo.BranchName,
NewBranch: branchName,
Message: message,
Content: strings.ReplaceAll(form.Content, "\r", ""),
}); err != nil {
})
if err != nil {
if models.IsErrBranchAlreadyExists(err) {
// User has specified a branch that already exists
branchErr := err.(models.ErrBranchAlreadyExists)
Expand All @@ -114,6 +112,6 @@ func NewDiffPatchPost(ctx *context.Context) {
if form.CommitChoice == frmCommitChoiceNewBranch && ctx.Repo.Repository.UnitEnabled(ctx, unit.TypePullRequests) {
ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + util.PathEscapeSegments(ctx.Repo.BranchName) + "..." + util.PathEscapeSegments(form.NewBranchName))
} else {
ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(branchName) + "/" + util.PathEscapeSegments(form.TreePath))
ctx.Redirect(ctx.Repo.RepoLink + "/commit/" + fileResponse.Commit.SHA)
}
}

0 comments on commit 28625fb

Please sign in to comment.