From d3893609b791af8254098d7e72f4046e31644575 Mon Sep 17 00:00:00 2001 From: weichen Date: Wed, 30 Sep 2026 15:28:14 +0000 Subject: [PATCH] Fix task worktree path derivation to anchor on the main checkout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Why: cmd_start derived the worktree location from $PWD, so running task.sh start from a repository subdirectory (or inside a task worktree) placed the new worktree at the wrong spot — e.g. scripts-wt- nested inside the repo. Evidence: bash -n clean; functional smoke of the patched script from both the main checkout scripts/ subdir and the repo root created ../Agent-System-Dev-wt- as a sibling of the main checkout (paths asserted; pre-fix subdir run would nest inside the repo); git rev-parse --git-common-dir resolves to the main checkout from both locations (relative ../.git vs absolute). Impact: scripts/task.sh cmd_start only; from the main checkout root the derived path is identical to before; new worktrees now always land as siblings of the main checkout regardless of invocation directory. Refs: .task/feature-task-start-rootfix.md --- scripts/task.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/task.sh b/scripts/task.sh index 587074dd..f9eadd84 100755 --- a/scripts/task.sh +++ b/scripts/task.sh @@ -63,10 +63,13 @@ cmd_start() { [ "$(git status --porcelain | { grep -v '^.. \.zcode/' || true; } | wc -l)" -eq 0 ] || die "dirty tree — resolve first (precheck verdict BUSY)" [ "$(git submodule status --recursive 2>/dev/null | { grep -cE '^\+|^U' || true; })" -eq 0 ] || die "submodule drift/conflict — resolve first (precheck verdict BUSY)" git merge-base --is-ancestor "origin/${TARGET_BRANCH}" HEAD || die "local ${TARGET_BRANCH} behind origin — pull --ff-only first" - local rmain slug wt + local rmain slug wt mainroot rmain=$(git rev-parse "origin/${TARGET_BRANCH}") slug=$(echo "$name" | tr '/' '-') - wt="$(dirname "$(pwd)")/$(basename "$(pwd)")-wt-${slug}" + # 落点须为主检出的平级目录:$PWD 推算在子目录(或任务 worktree 内)运行时会算错, + # 改用 git-common-dir 的父目录定位主检出(与 cmd_finish 同款惯用法)。 + mainroot=$(dirname "$(cd "$(git rev-parse --git-common-dir)" && pwd)") + wt="$(dirname "$mainroot")/$(basename "$mainroot")-wt-${slug}" [ -e "$wt" ] && die "worktree path exists: $wt" git worktree add -q "$wt" -b "$name" "$rmain" (cd "$wt" && git submodule update --init --recursive >/dev/null 2>&1 || echo "[warn] submodule init incomplete in worktree")