From 29e8c79ff59a3cc30e44e9e6397d4f96f9ee2241 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 13 Oct 2026 09:01:40 +0200 Subject: [PATCH] Extract a helper for trimming the slashes around a worktree path The next commit compares worktree paths with their slashes trimmed. Co-Authored-By: Claude Opus 5.5 (1M context) --- pkg/commands/git_commands/worktree_loader.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/commands/git_commands/worktree_loader.go b/pkg/commands/git_commands/worktree_loader.go index 4760841c7..418ca5c06 100644 --- a/pkg/commands/git_commands/worktree_loader.go +++ b/pkg/commands/git_commands/worktree_loader.go @@ -249,11 +249,8 @@ func getUniqueNamesFromPathsAux(paths []pathWithIndexT, depth int) []nameWithInd // if the path is /a/b/c/d, and the depth is 0, the value is 'd'. If the depth is 1, the value is 'c', etc func valueAtDepth(path string, depth int) string { - path = strings.TrimPrefix(path, "/") - path = strings.TrimSuffix(path, "/") - // Split the path into segments - segments := strings.Split(path, "/") + segments := strings.Split(trimSlashes(path), "/") // Get the length of segments length := len(segments) @@ -269,11 +266,8 @@ func valueAtDepth(path string, depth int) string { // if the path is /a/b/c/d, and the depth is 0, the value is 'd'. If the depth is 1, the value is 'b/c', etc func sliceAtDepth(path string, depth int) string { - path = strings.TrimPrefix(path, "/") - path = strings.TrimSuffix(path, "/") - // Split the path into segments - segments := strings.Split(path, "/") + segments := strings.Split(trimSlashes(path), "/") // Get the length of segments length := len(segments) @@ -286,3 +280,8 @@ func sliceAtDepth(path string, depth int) string { // Join the segments from the specified depth till end of the path return strings.Join(segments[length-1-depth:], "/") } + +func trimSlashes(path string) string { + path = strings.TrimPrefix(path, "/") + return strings.TrimSuffix(path, "/") +}