From 9f1f4f04dd71dbe754d7e601dfa93979f72875d5 Mon Sep 17 00:00:00 2001 From: Harivansh Rathi Date: Mon, 30 Mar 2026 17:26:46 +0000 Subject: [PATCH] Fix worktree path resolution inside linked worktrees Resolve the path anchor from the repository common git dir so running wtc from inside an existing worktree still names sibling worktrees from the main checkout root. Co-authored-by: Codex --- scripts/wt-path.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/wt-path.sh b/scripts/wt-path.sh index 46e4b62..9d8abb9 100644 --- a/scripts/wt-path.sh +++ b/scripts/wt-path.sh @@ -7,11 +7,16 @@ if [[ $# -ne 1 ]]; then exit 1 fi -repo_root=$(git rev-parse --show-toplevel 2>/dev/null) || { +common_git_dir=$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null) || { printf 'wt-path: not inside a git repository\n' >&2 exit 1 } +repo_root=$(cd "${common_git_dir}/.." && pwd -P) || { + printf 'wt-path: failed to resolve repository root\n' >&2 + exit 1 +} + worktree_name=$1 clean_name=$(printf '%s' "$worktree_name" | sed -E 's#[^[:alnum:]._-]+#-#g; s#-+#-#g; s#(^[.-]+|[.-]+$)##g')