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 <noreply@openai.com>
This commit is contained in:
Harivansh Rathi 2026-03-30 17:26:46 +00:00
parent 8ad1784a82
commit 9f1f4f04dd

View file

@ -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')