From 1734aab9fb3c9af98d71e4d466cbc82474009af5 Mon Sep 17 00:00:00 2001 From: J Chris Anderson Date: Wed, 17 Jun 2026 09:23:34 +0300 Subject: [PATCH] fix(using-git-worktrees): verify the chosen worktree directory is ignored MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "Safety Verification (project-local directories only)" step ran: git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null This passes if *either* candidate is ignored, but the directory-selection steps above may have chosen `worktrees/` for this run while only `.worktrees/` is in `.gitignore` (a common setup). The guard succeeds on the unchosen candidate, the skill skips adding the ignore rule, and `git worktree add` then creates untracked, non-ignored worktree contents in the chosen directory — the exact "don't commit worktree contents" hazard the step exists to prevent. Fix: bind the chosen directory to `LOCATION` in the selection steps and have the safety check verify only `"$LOCATION"`. The variable was already referenced downstream in the "Create the Worktree" snippet (`path="$LOCATION/$BRANCH_NAME"`) but was never explicitly assigned; this change makes the contract explicit and uses it for the ignore check too. Surfaced while vendoring superpowers v5.1.0 into another repo; the bug is independent of vendoring and reproduces on current `dev`. --- skills/using-git-worktrees/SKILL.md | 36 ++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/skills/using-git-worktrees/SKILL.md b/skills/using-git-worktrees/SKILL.md index 212c56926e..8c8931c5b6 100644 --- a/skills/using-git-worktrees/SKILL.md +++ b/skills/using-git-worktrees/SKILL.md @@ -62,30 +62,44 @@ Only proceed to Step 1b if you have no native worktree tool available. #### Directory Selection -Follow this priority order. Explicit user preference always beats observed filesystem state. +Follow this priority order. Explicit user preference always beats observed filesystem state. Bind the chosen directory to `LOCATION` so later steps verify and create against the same path. -1. **Check your instructions for a declared worktree directory preference.** If the user has already specified one, use it without asking. +1. **Check your instructions for a declared worktree directory preference.** If the user has already specified one, use it without asking: + ```bash + LOCATION="" + ``` -2. **Check for an existing project-local worktree directory:** +2. **Otherwise, check for an existing project-local worktree directory:** ```bash - ls -d .worktrees 2>/dev/null # Preferred (hidden) - ls -d worktrees 2>/dev/null # Alternative + if [ -d .worktrees ]; then # Preferred (hidden) + LOCATION=".worktrees" + elif [ -d worktrees ]; then # Alternative + LOCATION="worktrees" + fi ``` - If found, use it. If both exist, `.worktrees` wins. + If both exist, `.worktrees` wins. -3. **If there is no other guidance available**, default to `.worktrees/` at the project root. +3. **If there is no other guidance available**, default to `.worktrees/` at the project root: + ```bash + LOCATION=".worktrees" + ``` #### Safety Verification (project-local directories only) -**MUST verify directory is ignored before creating worktree:** +**MUST verify the chosen directory is ignored before creating worktree:** ```bash -git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null +git check-ignore -q "$LOCATION" ``` -**If NOT ignored:** Add to .gitignore, commit the change, then proceed. +**If NOT ignored:** Add `$LOCATION/` to .gitignore, commit the change, then proceed: + +```bash +echo "$LOCATION/" >> .gitignore +git add .gitignore && git commit -m "chore: ignore worktree directory" +``` -**Why critical:** Prevents accidentally committing worktree contents to repository. +**Why critical:** Prevents accidentally committing worktree contents to repository. Verifying the specific chosen location matters: a repo may ignore `.worktrees/` but not `worktrees/` (or vice versa). An `||` across both candidates can pass on the unchosen one and silently skip adding the ignore rule for the directory actually about to be created. #### Create the Worktree