From c8ba77179716c95dbe995d1296f31fbf0cce53e2 Mon Sep 17 00:00:00 2001 From: hugocasa Date: Thu, 6 Aug 2026 10:13:16 +0200 Subject: [PATCH] chore: track origin EE branch in worktree setup when absent locally (#9504) * chore: track origin EE branch in worktree setup when absent locally * chore: pass --track to worktree add so upstream is set regardless of git config Co-Authored-By: Claude Fable 5 * chore: guard first worktree arm on local branch to avoid remote-only DWIM Co-Authored-By: Claude Fable 5 --------- Co-authored-by: Claude Fable 5 --- scripts/worktree-common.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/worktree-common.sh b/scripts/worktree-common.sh index 4ca78338bf..65c396d458 100755 --- a/scripts/worktree-common.sh +++ b/scripts/worktree-common.sh @@ -181,8 +181,14 @@ wm_setup_ee_worktree() { mkdir -p "$(dirname "$ee_worktree_dir")" git -C "$ee_repo" fetch --quiet 2>/dev/null || true - if git -C "$ee_repo" worktree add "$ee_worktree_dir" "$branch" 2>/dev/null; then - echo "Created EE worktree at $ee_worktree_dir (branch: $branch)" + # Guard on refs/heads: without it, `worktree add` DWIMs a remote-only branch + # into a new local branch here, skipping the explicit --track arm below. + if git -C "$ee_repo" show-ref --verify --quiet "refs/heads/$branch" \ + && git -C "$ee_repo" worktree add "$ee_worktree_dir" "$branch" 2>/dev/null; then + echo "Created EE worktree at $ee_worktree_dir (existing local branch: $branch)" + elif git -C "$ee_repo" show-ref --verify --quiet "refs/remotes/origin/$branch" \ + && git -C "$ee_repo" worktree add --track -b "$branch" "$ee_worktree_dir" "origin/$branch" 2>/dev/null; then + echo "Created EE worktree at $ee_worktree_dir (tracking origin/$branch)" elif git -C "$ee_repo" worktree add -b "$branch" "$ee_worktree_dir" main 2>/dev/null; then echo "Created EE worktree at $ee_worktree_dir (new branch: $branch from main)" else