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) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-10-15 08:35:00 +02:00
co-authored by Claude Opus 5.5
parent 1c79c830f8
commit 29e8c79ff5
+7 -8
View File
@@ -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, "/")
}