Skip to content

fix(switch): clear a stale marker when --create makes the branch - #4704

Merged
max-sixty merged 1 commit into
mainfrom
fix/switch-create-clears-marker
Nov 5, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/switch-create-clears-marker

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

A branch deleted outside wt (for example with git branch -D) leaves its worktrunk.state.<branch>.marker key in git config. A later wt switch --create with the same name then showed the old 🤖/💬. Now wt switch --create clears that branch's marker once git worktree add -b succeeds. #4684 already clears the marker on every wt deletion path. This is the follow-up the maintainer asked for when closing #4685.

  • The deletion helper from fix(remove): clear a branch's marker when wt deletes the branch #4684 moves to Repository::clear_branch_marker, and both call sites use it. It is still best effort: a failed unset is logged at debug level, and only marker JSON is removed, so a vars entry named marker that shares the key is left alone.
  • Only --create clears the marker. Switching to an existing branch keeps its marker, and so does a DWIM checkout from a remote branch or a PR/MR ref.
  • A branch deleted and recreated with plain git still keeps its marker until wt config state marker clear. The marker help, its generated docs, and the help snapshot now say so.

test_switch_create_clears_stale_marker sets a marker on a branch name that has no branch and on an existing branch. It then runs wt switch --create for the first and plain wt switch for the second. It fails without the change, because the stale marker survives, and passes with it. The existing deletion_* unit tests pass on the moved helper.

Refs #4683

A branch deleted outside wt (git branch -D) leaves
worktrunk.state.<branch>.marker behind, and a later `wt switch --create`
with the same name showed the old marker. Clear it when --create
succeeds, reusing #4684's deletion helper, now
Repository::clear_branch_marker. A branch deleted and recreated with
plain git still keeps its marker until `wt config state marker clear`.

Refs #4683
@max-sixty
max-sixty merged commit ea0dbee into main Nov 5, 2026
36 checks passed
@max-sixty
max-sixty deleted the fix/switch-create-clears-marker branch November 5, 2026 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants