From bf325d44120c4a6fc7f67ff1dc25db770247c9a7 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Thu, 15 Sep 2022 15:25:16 +0200 Subject: [PATCH] Keep path when creating a new branch (#21153) If you are create a new new branch while viewing file or directory, you get redirected to the root of the repo. With this PR, you keep your current path instead of getting redirected to the repo root. --- routers/web/repo/branch.go | 2 +- services/forms/repo_branch_form.go | 1 + templates/repo/branch_dropdown.tmpl | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index d14ba6cbe9..d1f1255db4 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -427,5 +427,5 @@ func CreateBranch(ctx *context.Context) { } ctx.Flash.Success(ctx.Tr("repo.branch.create_success", form.NewBranchName)) - ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(form.NewBranchName)) + ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(form.NewBranchName) + "/" + util.PathEscapeSegments(form.CurrentPath)) } diff --git a/services/forms/repo_branch_form.go b/services/forms/repo_branch_form.go index f9262aaede..011926092f 100644 --- a/services/forms/repo_branch_form.go +++ b/services/forms/repo_branch_form.go @@ -16,6 +16,7 @@ import ( // NewBranchForm form for creating a new branch type NewBranchForm struct { NewBranchName string `binding:"Required;MaxSize(100);GitRefName"` + CurrentPath string CreateTag bool } diff --git a/templates/repo/branch_dropdown.tmpl b/templates/repo/branch_dropdown.tmpl index 9d1ec10d3c..2010fe261e 100644 --- a/templates/repo/branch_dropdown.tmpl +++ b/templates/repo/branch_dropdown.tmpl @@ -94,6 +94,9 @@ {{.root.CsrfTokenHtml}} + {{if $.root.TreePath}} + + {{end}}