Bug
When creating a new worktree via the Supacode UI or supacode repo worktree-new, the operation always fails with "Git command failed" for repositories where no worktrees have been previously created under ~/.supacode/repos/<repo>/.
Root Cause
Before calling the bundled wt sw script to create a worktree, Supacode's Swift code runs a pre-cleanup step:
git -C <repo> worktree remove --force ~/.supacode/repos/<repo>/<branch>/
This fails with exit code 128 when the target path doesn't exist (which is always the case for a brand-new worktree):
fatal: '~/.supacode/repos/<repo>/<branch>/' is not a working tree
Supacode treats this as a fatal error and aborts — the wt sw command is never invoked.
How I diagnosed this
I enabled [trace2] eventTarget in ~/.gitconfig to capture all git commands Supacode executes. The sequence for every worktree creation attempt is:
git check-ref-format --branch <name> → exit 0 ✓
git rev-parse --is-bare-repository → exit 0 ✓
git worktree remove --force <target-path>/ → exit 128 ✗
- Supacode aborts.
wt sw is never called.
Running the wt sw command directly from a terminal works perfectly:
wt --base-dir ~/.supacode/repos/<repo>/ sw --from origin/main <branch>
Expected behavior
git worktree remove --force should be allowed to fail silently when the target path doesn't exist or isn't a registered worktree. It's a cleanup step — if there's nothing to clean up, that's fine.
Suggested fix
Either:
- Skip the
worktree remove call if the target path doesn't exist
- Ignore exit code 128 from
worktree remove when the error message contains "is not a working tree"
Reproduction
- Add https://github.com/elastic/elasticsearch as a repository in Supacode (large repo, ~41,500 files, open source)
- Try creating a new worktree from the UI with any branch name based on
origin/main
- Observe "Git command failed" error — the
wt sw command is never executed
Environment
- Supacode v0.8.5 (build 136000)
- macOS 26.4 (25E246), Apple Silicon
- Git: Apple Git 2.50.1 (
/Applications/Xcode.app/Contents/Developer/usr/bin/git)
Bug
When creating a new worktree via the Supacode UI or
supacode repo worktree-new, the operation always fails with "Git command failed" for repositories where no worktrees have been previously created under~/.supacode/repos/<repo>/.Root Cause
Before calling the bundled
wt swscript to create a worktree, Supacode's Swift code runs a pre-cleanup step:This fails with exit code 128 when the target path doesn't exist (which is always the case for a brand-new worktree):
Supacode treats this as a fatal error and aborts — the
wt swcommand is never invoked.How I diagnosed this
I enabled
[trace2] eventTargetin~/.gitconfigto capture all git commands Supacode executes. The sequence for every worktree creation attempt is:git check-ref-format --branch <name>→ exit 0 ✓git rev-parse --is-bare-repository→ exit 0 ✓git worktree remove --force <target-path>/→ exit 128 ✗wt swis never called.Running the
wt swcommand directly from a terminal works perfectly:Expected behavior
git worktree remove --forceshould be allowed to fail silently when the target path doesn't exist or isn't a registered worktree. It's a cleanup step — if there's nothing to clean up, that's fine.Suggested fix
Either:
worktree removecall if the target path doesn't existworktree removewhen the error message contains "is not a working tree"Reproduction
origin/mainwt swcommand is never executedEnvironment
/Applications/Xcode.app/Contents/Developer/usr/bin/git)