Skip to content

Commit bf325d4

Browse files
authored
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.
1 parent ef40324 commit bf325d4

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

routers/web/repo/branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,5 +427,5 @@ func CreateBranch(ctx *context.Context) {
427427
}
428428

429429
ctx.Flash.Success(ctx.Tr("repo.branch.create_success", form.NewBranchName))
430-
ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(form.NewBranchName))
430+
ctx.Redirect(ctx.Repo.RepoLink + "/src/branch/" + util.PathEscapeSegments(form.NewBranchName) + "/" + util.PathEscapeSegments(form.CurrentPath))
431431
}

services/forms/repo_branch_form.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
// NewBranchForm form for creating a new branch
1717
type NewBranchForm struct {
1818
NewBranchName string `binding:"Required;MaxSize(100);GitRefName"`
19+
CurrentPath string
1920
CreateTag bool
2021
}
2122

templates/repo/branch_dropdown.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@
9494
{{.root.CsrfTokenHtml}}
9595
<input type="hidden" name="new_branch_name" v-model="searchTerm">
9696
<input type="hidden" name="create_tag" v-model="createTag">
97+
{{if $.root.TreePath}}
98+
<input type="hidden" name="current_path" value="{{.root.TreePath}}">
99+
{{end}}
97100
</form>
98101
</div>
99102
</div>

0 commit comments

Comments
 (0)