From ed7d986fa70345fada0ecdf85d0522363b6efea3 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 13 Sep 2022 10:55:34 +0200 Subject: [PATCH 1/3] Keep path when creating a new branch --- 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 d14ba6cbe9a4..0a9f15667e29 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) + "/" + form.CurrentPath) } diff --git a/services/forms/repo_branch_form.go b/services/forms/repo_branch_form.go index f9262aaede77..011926092fd7 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 9d1ec10d3cec..62c49d235a51 100644 --- a/templates/repo/branch_dropdown.tmpl +++ b/templates/repo/branch_dropdown.tmpl @@ -94,6 +94,9 @@ {{.root.CsrfTokenHtml}} + {{if $.root.TreePath}} + + {{end}} From aff21fc78014be62d3c247b0691a8727124c756d Mon Sep 17 00:00:00 2001 From: JakobDev Date: Thu, 15 Sep 2022 14:02:28 +0200 Subject: [PATCH 2/3] Move PathEscapeSegments --- routers/web/repo/branch.go | 2 +- templates/repo/branch_dropdown.tmpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index 0a9f15667e29..2779b6bb1582 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) + "/" + form.CurrentPath) + ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(form.NewBranchName) + "/" + util.PathEscapeSegments(form.CurrentPath)) } diff --git a/templates/repo/branch_dropdown.tmpl b/templates/repo/branch_dropdown.tmpl index 62c49d235a51..2010fe261e15 100644 --- a/templates/repo/branch_dropdown.tmpl +++ b/templates/repo/branch_dropdown.tmpl @@ -95,7 +95,7 @@ {{if $.root.TreePath}} - + {{end}} From adc8210a30a6271847eed5a3b11186432991a890 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 15 Sep 2022 20:05:58 +0800 Subject: [PATCH 3/3] fix lint --- routers/web/repo/branch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index 2779b6bb1582..d1f1255db465 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) + "/" + util.PathEscapeSegments(form.CurrentPath)) + ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(form.NewBranchName) + "/" + util.PathEscapeSegments(form.CurrentPath)) }