Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion skills/using-git-worktrees/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,25 @@ Honor any existing declared preference without asking. If the user declines cons

### 1a. Native Worktree Tools (preferred)

The user has asked for an isolated workspace (Step 0 consent). Do you already have a way to create a worktree? It might be a tool with a name like `EnterWorktree`, `WorktreeCreate`, a `/worktree` command, or a `--worktree` flag. If you do, use it and skip to Step 2.
The user has asked for an isolated workspace (Step 0 consent). Do you already have a way to create a worktree? It might be a tool with a name like `EnterWorktree`, `WorktreeCreate`, a `/worktree` command, or a `--worktree` flag. If you do, use it, run any post-native sanity check below, and skip to Step 2.

Native tools handle directory placement, branch creation, and cleanup automatically. Using `git worktree add` when you have a native tool creates phantom state your harness can't see or manage.

**Known issue (Claude Code):** `EnterWorktree` can trigger an upstream Claude Code bug that writes `core.bare=true` into the parent checkout's shared git config. This is not a Superpowers bug, and the native preference still applies. Record the parent checkout before calling the native tool:

```bash
PARENT_REPO_ROOT=$(git rev-parse --show-toplevel)
```

After the native tool returns, verify the parent checkout. If `core.bare` flipped to `true`, repair it immediately and tell the user what happened:

```bash
if [ "$(git -C "$PARENT_REPO_ROOT" config --get core.bare 2>/dev/null)" = "true" ]; then
git -C "$PARENT_REPO_ROOT" config --unset core.bare
echo "Repaired parent checkout: unset unexpected core.bare=true after native worktree creation."
fi
```

Only proceed to Step 1b if you have no native worktree tool available.

### 1b. Git Worktree Fallback
Expand Down
7 changes: 7 additions & 0 deletions tests/claude-code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ RED-GREEN-REFACTOR validation for the using-git-worktrees skill (~5 minutes):
- PRESSURE: same as GREEN under urgency framing with pre-existing `.worktrees/`
- Drill scenario `worktree-creation-under-pressure.yaml` covers the PRESSURE phase only

#### test-enterworktree-core-bare-guard.sh
Static regression test for the using-git-worktrees Step 1a Claude Code guard:
- Records the parent checkout before native tool use
- Checks the parent checkout's `core.bare` after native tool use
- Repairs unexpected `core.bare=true` with `git -C "$PARENT_REPO_ROOT" config --unset core.bare`
- Preserves native worktree preference and does not tell agents to avoid `EnterWorktree`

## Adding New Tests

1. Create new test file: `test-<skill-name>.sh`
Expand Down
2 changes: 2 additions & 0 deletions tests/claude-code/run-skill-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ while [[ $# -gt 0 ]]; do
echo " --help, -h Show this help"
echo ""
echo "Tests:"
echo " test-enterworktree-core-bare-guard.sh Test EnterWorktree parent core.bare guard"
echo " test-subagent-driven-development.sh Test skill loading and requirements"
echo ""
echo "Integration Tests (use --integration):"
Expand All @@ -73,6 +74,7 @@ done

# List of skill tests to run (fast unit tests)
tests=(
"test-enterworktree-core-bare-guard.sh"
"test-worktree-path-policy.sh"
"test-subagent-driven-development.sh"
)
Expand Down
64 changes: 64 additions & 0 deletions tests/claude-code/test-enterworktree-core-bare-guard.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
# Regression check: using-git-worktrees should guard against the known Claude
# Code EnterWorktree parent-checkout core.bare failure mode.

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"

USING_SKILL="$REPO_ROOT/skills/using-git-worktrees/SKILL.md"

failures=0

assert_contains() {
local file="$1"
local pattern="$2"
local label="$3"

if grep -Fq "$pattern" "$file"; then
echo " [PASS] $label"
else
echo " [FAIL] $label"
echo " Expected to find: $pattern"
echo " In file: $file"
failures=$((failures + 1))
fi
}

assert_not_contains() {
local file="$1"
local pattern="$2"
local label="$3"

if grep -Fq "$pattern" "$file"; then
echo " [FAIL] $label"
echo " Did not expect to find: $pattern"
echo " In file: $file"
failures=$((failures + 1))
else
echo " [PASS] $label"
fi
}

echo "=== EnterWorktree core.bare Guard Test ==="
echo ""

assert_contains "$USING_SKILL" "Known issue (Claude Code)" "Step 1a names the known Claude Code issue"
assert_contains "$USING_SKILL" "EnterWorktree" "Step 1a names EnterWorktree"
assert_contains "$USING_SKILL" "core.bare" "Step 1a names core.bare"
assert_contains "$USING_SKILL" 'PARENT_REPO_ROOT=$(git rev-parse --show-toplevel)' "Step 1a records the parent checkout root"
assert_contains "$USING_SKILL" 'git -C "$PARENT_REPO_ROOT" config --get core.bare' "Step 1a checks parent checkout core.bare"
assert_contains "$USING_SKILL" 'git -C "$PARENT_REPO_ROOT" config --unset core.bare' "Step 1a repairs parent checkout core.bare"
assert_contains "$USING_SKILL" "Native tools handle directory placement, branch creation, and cleanup automatically." "Step 1a still preserves native tool preference"
assert_not_contains "$USING_SKILL" "avoid native tools" "Step 1a does not tell agents to avoid native tools"
assert_not_contains "$USING_SKILL" "skip EnterWorktree" "Step 1a does not tell agents to skip EnterWorktree"

echo ""

if [ "$failures" -gt 0 ]; then
echo "STATUS: FAILED ($failures failures)"
exit 1
fi

echo "STATUS: PASSED"