From 2426025ece27b5b0b56cc8a4fbaa4f10b56fdbcd Mon Sep 17 00:00:00 2001 From: nolte Date: Tue, 14 Jul 2026 13:51:13 +0200 Subject: [PATCH] fix(worktree): make add's base-ref fetch non-interactive and resilient MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `worktree:add` task fetched the base ref with a plain `git fetch`, which — when the task runs from a non-interactive context and SSH_AUTH_SOCK is stale — can fall into a credential/passphrase prompt. Without a terminal that surfaces as an intermittent "no terminal" style failure, and because of `set -euo pipefail` the task aborts before `git worktree add`, leaving no worktree. Force the fetch to be strictly non-interactive (GIT_TERMINAL_PROMPT=0, SSH BatchMode, ConnectTimeout) so git can never prompt, and fall back to the last-known local base ref with a warning instead of aborting when the remote is unreachable. Only error out when no local base ref exists. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/taskfile-include-worktree.yaml | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/taskfile-include-worktree.yaml b/src/taskfile-include-worktree.yaml index 55b0588..39c09ec 100644 --- a/src/taskfile-include-worktree.yaml +++ b/src/taskfile-include-worktree.yaml @@ -117,8 +117,28 @@ tasks: echo "→ Branch : $branch" echo "→ Destination : $dest" - git fetch "$fetch_remote" "$fetch_branch" --quiet - git worktree add -b "$branch" "$dest" "$base_ref" + # Fetch the base ref strictly non-interactively. GIT_TERMINAL_PROMPT=0 + # plus SSH BatchMode guarantees git can never fall into a credential or + # passphrase prompt when the task runs from a non-interactive context + # (a stale SSH_AUTH_SOCK between sessions was the cause of the + # intermittent "no terminal" failure). If the remote is unreachable we + # fall back to the last-known local base ref instead of aborting before + # the worktree is even created. + if ! GIT_TERMINAL_PROMPT=0 \ + GIT_SSH_COMMAND="${GIT_SSH_COMMAND:-ssh} -o BatchMode=yes -o ConnectTimeout=10" \ + git fetch "$fetch_remote" "$fetch_branch" --quiet < /dev/null; then + if git rev-parse --verify --quiet "$base_ref^{commit}" >/dev/null; then + echo "⚠ Could not reach ${fetch_remote} (offline, or no non-interactive" >&2 + echo " credentials — check that ssh-agent is reachable via SSH_AUTH_SOCK)." >&2 + echo " Falling back to the local ${base_ref}, which may be behind the remote." >&2 + else + echo "✖ Could not fetch ${fetch_remote}/${fetch_branch} and no local" >&2 + echo " ${base_ref} exists to fall back to. Make ssh-agent reachable" >&2 + echo " (SSH_AUTH_SOCK) or ensure credentials work non-interactively, then retry." >&2 + exit 1 + fi + fi + git worktree add -b "$branch" "$dest" "$base_ref" < /dev/null # Plan-before-work gate: seed a foundational implementation-plan stub # inside the new worktree so a fresh resumable session can pick the