Skip to content

fix(commit-commands): detect [gone] branches with git branch -vv in clean_gone#70173

Open
AndrewDongminYoo wants to merge 1 commit into
anthropics:mainfrom
AndrewDongminYoo:fix/clean-gone-detect-gone-marker
Open

fix(commit-commands): detect [gone] branches with git branch -vv in clean_gone#70173
AndrewDongminYoo wants to merge 1 commit into
anthropics:mainfrom
AndrewDongminYoo:fix/clean-gone-detect-gone-marker

Conversation

@AndrewDongminYoo

Copy link
Copy Markdown

Summary

/clean_gone never deletes anything because its [gone] detection is broken.

Root cause

The command lists branches with git branch -v and filters with grep '\[gone\]':

git branch -v | grep '\[gone\]' | sed 's/^[+* ]//' | awk '{print $1}'

Two problems:

  1. git branch -v does not print the [gone] marker. The upstream-tracking
    state (including gone) is only emitted by git branch -vv (double v).
    With single -v the pipeline matches nothing.
  2. The marker is never the literal [gone]. Git formats it as
    [origin/<branch>: gone], so grep '\[gone\]' would not match even with
    -vv.

Net effect: the loop body never runs and no stale branches are removed.

Fix

  • List with git branch -vv (both in step 1 and the deletion pipeline).
  • Match the real marker with grep ': gone]'.
  • Minor hardening: sed 's/^[+* ]*//' (strip all leading */+/space markers)
    and clarifying comments.
git branch -vv | grep ': gone]' | sed 's/^[+* ]*//' | awk '{print $1}' | while read branch; do
  ...
done

Verification

Against git branch -vv style input:

  feat-a   1234567 [origin/feat-a: gone] msg
* main     89abcde [origin/main] msg
+ wt-br    abc1234 [origin/wt-br: gone] msg
  active   def5678 [origin/active: behind 2] msg
  • Old logic (git branch -v | grep '\[gone\]'): 0 matches.
  • New logic: outputs feat-a and wt-br only (correctly excludes main and the
    behind branch, and keeps the + worktree branch).

… clean_gone

`git branch -v` does not emit the `[gone]` upstream-tracking marker, so the
detection pipeline matched nothing and the command silently deleted no
branches. Switch to `git branch -vv` and match the real marker format
`[origin/<branch>: gone]` via `grep ': gone]'` instead of the literal
`[gone]`, which never appears.
@RossMora

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

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