fix: harden git workflow skills with better state handling (#406)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,7 @@ bash scripts/clean-gone
|
||||
|
||||
[scripts/clean-gone](./scripts/clean-gone)
|
||||
|
||||
The script runs `git fetch --prune` first, then parses `git branch -vv` for branches marked `: gone]`. It uses `command git` to bypass shell aliases and RTK proxies.
|
||||
The script runs `git fetch --prune` first, then parses `git branch -vv` for branches marked `: gone]`.
|
||||
|
||||
If the script outputs `__NONE__`, report that no stale branches were found and stop.
|
||||
|
||||
@@ -45,9 +45,9 @@ This is a yes-or-no decision on the entire list -- do not offer multi-selection
|
||||
|
||||
If the user confirms, delete each branch. For each branch:
|
||||
|
||||
1. Check if it has an associated worktree (`command git worktree list | grep "\\[$branch\\]"`)
|
||||
2. If a worktree exists and is not the main repo root, remove it first: `command git worktree remove --force "$worktree_path"`
|
||||
3. Delete the branch: `command git branch -D "$branch"`
|
||||
1. Check if it has an associated worktree (`git worktree list | grep "\\[$branch\\]"`)
|
||||
2. If a worktree exists and is not the main repo root, remove it first: `git worktree remove --force "$worktree_path"`
|
||||
3. Delete the branch: `git branch -D "$branch"`
|
||||
|
||||
Report results as you go:
|
||||
|
||||
@@ -61,7 +61,3 @@ Cleaned up 3 branches.
|
||||
```
|
||||
|
||||
If the user declines, acknowledge and stop without deleting anything.
|
||||
|
||||
## Important: Use `command git`
|
||||
|
||||
Always invoke git as `command git` in shell commands. This bypasses shell aliases and tools like RTK (Rust Token Killer) that proxy git commands, ensuring consistent behavior and output parsing.
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
# clean-gone: List local branches whose remote tracking branch is gone.
|
||||
# Outputs one branch name per line, or nothing if none found.
|
||||
# Uses `command git` to bypass aliases and RTK proxies.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Ensure we have current remote state
|
||||
command git fetch --prune 2>/dev/null
|
||||
git fetch --prune 2>/dev/null
|
||||
|
||||
# Find branches marked [gone] in tracking info.
|
||||
# `git branch -vv` output format:
|
||||
@@ -37,7 +36,7 @@ while IFS= read -r line; do
|
||||
fi
|
||||
|
||||
gone_branches+=("$branch_name")
|
||||
done < <(command git branch -vv 2>/dev/null | grep ': gone]')
|
||||
done < <(git branch -vv 2>/dev/null | grep ': gone]')
|
||||
|
||||
if [[ ${#gone_branches[@]} -eq 0 ]]; then
|
||||
echo "__NONE__"
|
||||
|
||||
Reference in New Issue
Block a user