Repository navigation
fix(remove): clear a branch's marker when wt deletes the branch - #4684
Merged
Merged
Conversation
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
commented
Nov 3, 2026
worktrunk-bot
left a comment
Collaborator
Author
There was a problem hiding this comment.
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.
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.
This was referenced Nov 4, 2026
This was referenced Nov 4, 2026
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]>
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
wtdeleted branches but leftworktrunk.state.<branch>.markerin git config, so a later branch with the same name came up inwt listwith the old 🤖/💬. Everywtdeletion path goes throughdelete_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_markercovers the integrated, forced, and kept cases. It fails without the change and passes with it. I also ran the issue's repro throughwt remove --yes feature(the default background path). Before the change the marker key survived; after it noworktrunk.state.*keys were left. The marker help and the FAQ's branch-deletion section now say this.This PR does not cover:
varsentries: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.wt: a branch deleted with plaingit branch -D, as in the issue's repro, still leaves its marker. The issue suggests either havingwt listignore markers for missing branches or adding awt config state prune; both are product decisions.Refs #4683 — automated triage