Merge pull request #3526 from gsd-build/fix/3521-workflows-quick-md-two-bugs-in-post-merg

fix(quick): pin cleanup-loop CWD to project root before bare git commands (#3521)
This commit is contained in:
Tom Boucher
2026-05-14 19:57:45 -04:00
committed by GitHub
3 changed files with 216 additions and 0 deletions

View File

@@ -799,6 +799,19 @@ After executor returns:
node -e 'const fs=require("fs");const p=process.env.QUICK_WORKTREE_MANIFEST||process.env.WAVE_WORKTREE_MANIFEST;try{if(!p)throw new Error("QUICK_WORKTREE_MANIFEST is unset");if(!fs.existsSync(p))throw new Error("manifest does not exist");const s=fs.readFileSync(p,"utf8");if(!s.trim())throw new Error("manifest is empty");const j=JSON.parse(s);for(const w of j.worktrees||[])if(w.worktree_path)console.log(w.worktree_path)}catch(e){console.error(`ERROR: cannot read worktree manifest ${p||"(unset)"}: ${e.message}`);process.exit(1)}' > "$WT_PATHS_FILE" || { echo "BLOCKED: cannot read QUICK_WORKTREE_MANIFEST; refusing cleanup (#3384)." >&2; exit 1; }
while IFS= read -r WT; do
[ -z "$WT" ] && continue
# Pin CWD to project root before any bare git command (#3521).
# An LLM orchestrator may leak CWD into a worktree across tool calls; without
# this pin the merge command resolves against the worktree branch itself and
# silently no-ops the main-branch merge.
PROJECT_ROOT=$(git -C "$WT" rev-parse --git-common-dir 2>/dev/null)
# git rev-parse --git-common-dir returns the .git dir, not the working tree root.
# Strip the trailing /.git (or bare .git) to get the working tree root.
PROJECT_ROOT=$(echo "$PROJECT_ROOT" | sed 's|/\.git$||; s|/\.git/.*||')
if [ -z "$PROJECT_ROOT" ] || [ ! -d "$PROJECT_ROOT" ]; then
echo "WARN: cannot resolve project root from worktree $WT — skipping cleanup for this entry (#3521)" >&2
continue
fi
cd "$PROJECT_ROOT" || { echo "WARN: cannot cd to project root $PROJECT_ROOT — skipping cleanup for worktree $WT (#3521)" >&2; continue; }
WT_BRANCH=$(git -C "$WT" rev-parse --abbrev-ref HEAD 2>/dev/null)
if [ -n "$WT_BRANCH" ] && [ "$WT_BRANCH" != "HEAD" ]; then
# --- Orchestrator file protection (#1756) ---