From 5895d435747c75f17d0bbb9ec244e9ab883dabb6 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Mon, 20 Feb 2017 22:29:15 -0500 Subject: [PATCH] editor: redirect to new pull request page after create new branch --- gogs.go | 2 +- modules/auth/repo_form.go | 12 ++++++++++++ routers/repo/editor.go | 26 +++++++++++++++++++------- templates/.VERSION | 2 +- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/gogs.go b/gogs.go index 412c899eb..a507c6906 100644 --- a/gogs.go +++ b/gogs.go @@ -16,7 +16,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.9.162.0220" +const APP_VER = "0.9.163.0220" func init() { setting.AppVer = APP_VER diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index daec8a2ac..c93115308 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -327,6 +327,10 @@ func (f *EditRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) b return validate(errs, ctx.Data, f, ctx.Locale) } +func (f *EditRepoFileForm) IsNewBrnach() bool { + return f.CommitChoice == "commit-to-new-branch" +} + type EditPreviewDiffForm struct { Content string } @@ -356,6 +360,10 @@ func (f *UploadRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) return validate(errs, ctx.Data, f, ctx.Locale) } +func (f *UploadRepoFileForm) IsNewBrnach() bool { + return f.CommitChoice == "commit-to-new-branch" +} + type RemoveUploadFileForm struct { File string `binding:"Required;MaxSize(50)"` } @@ -381,3 +389,7 @@ type DeleteRepoFileForm struct { func (f *DeleteRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { return validate(errs, ctx.Data, f, ctx.Locale) } + +func (f *DeleteRepoFileForm) IsNewBrnach() bool { + return f.CommitChoice == "commit-to-new-branch" +} diff --git a/routers/repo/editor.go b/routers/repo/editor.go index 22e36d966..326a8c7e4 100644 --- a/routers/repo/editor.go +++ b/routers/repo/editor.go @@ -135,7 +135,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo lastCommit := form.LastCommit form.LastCommit = ctx.Repo.Commit.ID.String() - if form.CommitChoice == "commit-to-new-branch" { + if form.IsNewBrnach() { branchName = form.NewBranchName } @@ -279,7 +279,11 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo return } - ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + template.EscapePound(form.TreePath)) + if form.IsNewBrnach() { + ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + oldBranchName + "..." + form.NewBranchName) + } else { + ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + template.EscapePound(form.TreePath)) + } } func EditFilePost(ctx *context.Context, form auth.EditRepoFileForm) { @@ -336,7 +340,7 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) { oldBranchName := ctx.Repo.BranchName branchName := oldBranchName - if form.CommitChoice == "commit-to-new-branch" { + if form.IsNewBrnach() { branchName = form.NewBranchName } ctx.Data["commit_summary"] = form.CommitSummary @@ -378,8 +382,12 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) { return } - ctx.Flash.Success(ctx.Tr("repo.editor.file_delete_success", ctx.Repo.TreePath)) - ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName) + if form.IsNewBrnach() { + ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + oldBranchName + "..." + form.NewBranchName) + } else { + ctx.Flash.Success(ctx.Tr("repo.editor.file_delete_success", ctx.Repo.TreePath)) + ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName) + } } func renderUploadSettings(ctx *context.Context) { @@ -417,7 +425,7 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) { oldBranchName := ctx.Repo.BranchName branchName := oldBranchName - if form.CommitChoice == "commit-to-new-branch" { + if form.IsNewBrnach() { branchName = form.NewBranchName } @@ -495,7 +503,11 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) { return } - ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + form.TreePath) + if form.IsNewBrnach() { + ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + oldBranchName + "..." + form.NewBranchName) + } else { + ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + form.TreePath) + } } func UploadFileToServer(ctx *context.Context) { diff --git a/templates/.VERSION b/templates/.VERSION index 9d96dbb8d..69e560186 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.9.162.0220 \ No newline at end of file +0.9.163.0220 \ No newline at end of file