Skip to content

fix(git): harden worktree add in main-worktree relocate against hyphen-prefixed branches - #2738

Merged
max-sixty merged 1 commit into
mainfrom
fix/relocate-hyphen-prefixed-branch
May 13, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/relocate-hyphen-prefixed-branch

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Follow-up to #2725. The hyphen-prefixed-ref hardening sweep missed the git worktree add call in move_main_worktree. A branch literally named -foo (creatable via git update-ref refs/heads/-foo HEAD) on the main worktree would crash wt step relocate with git worktree add: unknown switch 'o'.

Adds --end-of-options before the path and branch positionals, matching the convention documented in Repository::run_command and used throughout the codebase after #2725. Also adds a regression test that fails without the fix (verified locally — without --end-of-options, wt step relocate exits non-zero with git's "unknown switch" error).

Test plan

  • cargo test --test integration test_relocate — all 23 relocate tests pass
  • Removed the fix and reran the new test — confirmed it fails with unknown switch 'o'
  • cargo clippy --all-targets -- -D warnings — clean

…hen-prefixed branches

Follow-up to #2725. The hardening sweep missed the `git worktree add` call
in `move_main_worktree` — `worktree` wasn't in the subcommand list, but
the same `-foo`-as-flag hazard applies. A branch named `-foo` (creatable
via `git update-ref refs/heads/-foo HEAD`) on the main worktree would
crash `wt step relocate` with `unknown switch 'o'`.

Adds `--end-of-options` before the path and branch positionals, matching
the convention documented in `Repository::run_command`. Also adds a
regression test that fails without the fix.
@worktrunk-bot worktrunk-bot added automated-fix Automated CI fix nightly-cleanup Issues found by nightly code quality sweep labels May 12, 2026
@max-sixty
max-sixty merged commit b9862c9 into main May 13, 2026
31 of 55 checks passed
@max-sixty
max-sixty deleted the fix/relocate-hyphen-prefixed-branch branch May 13, 2026 04:54
@worktrunk-bot worktrunk-bot mentioned this pull request May 13, 2026
max-sixty added a commit that referenced this pull request May 13, 2026
Per @worktrunk-bot review: #2738 is a follow-up to #2725 that hardens
`git worktree add` in `move_main_worktree` against hyphen-prefixed
branches. It merged to main before this release PR, so it ships in 0.50.0
— add it to the bullet's PR list and note the `wt step relocate` site.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix Automated CI fix nightly-cleanup Issues found by nightly code quality sweep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants