Skip to content

fix(remove): clear a branch's marker when wt deletes the branch - #4684

Merged
max-sixty merged 3 commits into
mainfrom
fix/issue-4683
Nov 4, 2026
Merged

max-sixty merged 3 commits into
mainfrom
fix/issue-4683

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

wt deleted branches but left worktrunk.state.<branch>.marker in git config, so a later branch with the same name came up in wt list with the old 🤖/💬. Every wt deletion path goes through delete_branch_if_safe: wt remove (foreground and the detached background child), wt merge, the picker, and branch-only removal. That function now unsets the branch's marker after a forced or integrated deletion. A branch that is kept (unmerged, checked out elsewhere, or moved by a race) keeps its marker. Unsetting is best effort: the branch is already gone by then, so a failure gets a debug log line and does not fail the removal.

deletion_clears_branch_marker covers the integrated, forced, and kept cases. It fails without the change and passes with it. I also ran the issue's repro through wt remove --yes feature (the default background path). Before the change the marker key survived; after it no worktrunk.state.* keys were left. The marker help and the FAQ's branch-deletion section now say this.

This PR does not cover:

  • vars entries: worktrunk.state.<branch>.vars.* entries also outlive the branch. They are user data rather than activity status, so whether branch deletion should drop them is a maintainer call.
  • Branches deleted outside wt: a branch deleted with plain git branch -D, as in the issue's repro, still leaves its marker. The issue suggests either having wt list ignore markers for missing branches or adding a wt config state prune; both are product decisions.

Refs #4683 — automated triage

Markers live in shared git config keyed by branch name, and nothing
removed them on branch deletion, so a later branch reusing the name
showed the stale marker. delete_branch_if_safe, which every wt deletion
path goes through, now unsets worktrunk.state.<branch>.marker after a
forced or integrated deletion. A retained branch keeps its marker.

Refs #4683
@worktrunk-bot worktrunk-bot added the automated-fix Automated CI fix label Nov 3, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting a branch named <name>.vars unsets worktrunk.state.<name>.vars.marker. That is also the key for branch <name>'s var named marker, and validate_vars_key accepts marker. So wt remove feature.vars would delete feature's marker var, which is user data. clear_all_markers in src/commands/config/state.rs already guards against this collision: it skips such a key unless the value is marker JSON. The inline suggestion applies the same guard through branch_marker, which parses marker JSON. I'll push it as a fix.

This adds a deletion of state that wt stores for the user, which running-tend's review guidance says to hold for maintainer review. I'm requesting review from @max-sixty.

Comment thread src/git/remove.rs Resolved
Deleting branch `<name>.vars` unset `worktrunk.state.<name>.vars.marker`,
which is also branch `<name>`'s var named `marker`. Clear the key only
when it holds marker JSON, as `clear_all_markers` does.
@max-sixty
max-sixty merged commit 5bdb832 into main Nov 4, 2026
36 checks passed
@max-sixty
max-sixty deleted the fix/issue-4683 branch November 4, 2026 00:07
max-sixty pushed a commit that referenced this pull request Nov 5, 2026
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 #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

Co-authored-by: worktrunk-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix Automated CI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants