Audits every function's interaction with the C1-shadowed commands (uses-shadow/bypasses-shadow) and general hazards (destructive, network, blocking-prompt) per the CLASSIFICATION schema. Delegated the initial mechanical sweep to agy, then reviewed every file by hand: fixed a systemic double-blank-comment-line formatting bug from the delegate pass, and corrected several judgment errors found on review -- three false blocking-prompt tags where a fish 'read' was consuming piped input rather than waiting on a terminal (open-url.fish, sbver.fish, play-media.fish, now untagged entirely), a blocking-prompt tag on mkrep.fish despite its documented --yes escape hatch, an untagged read in jobrunner.fish's own baseless blocking-prompt claim (removed, along with a destructive tag on cleanup of its own mktemp output -- the schema explicitly excludes that), the same own-output-cleanup false positive on _zellij_dump_log.fish's destructive tag, an interactive fzf-gated confirmation on logs.fish and replay.fish's piped read misread the same way as the first three, and a uses-shadow(mkdir) on mkcd.fish that actually belongs to the _fish_mkdir_p helper it delegates to, not to mkcd itself.
88 lines
3.1 KiB
Fish
88 lines
3.1 KiB
Fish
# Copyright (C) 2026 Rootiest
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
# CATEGORY
|
|
# 04-git-and-version-control
|
|
#
|
|
# CLASSIFICATION
|
|
# network
|
|
#
|
|
# SYNOPSIS
|
|
# git-clean [-h] [-f]
|
|
#
|
|
# DESCRIPTION
|
|
# Fetches and prunes the remote, fast-forwards the current branch, and
|
|
# deletes local branches whose tracking remote has been deleted. Switches to
|
|
# main/master automatically if the current branch is orphaned.
|
|
#
|
|
# ARGUMENTS
|
|
# -h, --help Show help message
|
|
# -f, --force Force-delete unmerged orphaned branches (git branch -D)
|
|
#
|
|
# EXIT STATUS
|
|
# 0 Cleanup complete
|
|
# 1 Argument parsing failed
|
|
#
|
|
# EXAMPLE
|
|
# git-clean --force
|
|
# git-clean
|
|
function git-clean --description 'Sync main, prune remotes, and delete orphaned branches'
|
|
set -l options h/help f/force
|
|
argparse $options -- $argv
|
|
or return
|
|
|
|
if set -q _flag_help
|
|
__fish_palette
|
|
echo "$c_head""Usage:$c_reset $c_cmd""git-clean$c_reset $c_arg""[OPTIONS]$c_reset"
|
|
echo
|
|
echo "$c_head""Steps taken:$c_reset"
|
|
echo " 1. Fetches and prunes to find deleted remote branches."
|
|
echo " 2. Switches to main if you are on an orphaned branch."
|
|
echo " 3. Pulls the latest changes from the remote."
|
|
echo " 4. Deletes local orphaned branches."
|
|
return 0
|
|
end
|
|
|
|
# 1. Fetch and prune (Quietly)
|
|
echo (set_color blue)"Fetching and pruning remote tracking..."(set_color normal)
|
|
git fetch --prune --quiet
|
|
|
|
# 2. Identify orphaned branches and current branch
|
|
# git branch -vv marks column 1 with '*' for the current worktree's
|
|
# branch or '+' for a branch checked out in another linked worktree.
|
|
# Only '*' was stripped here, so a gone branch checked out elsewhere
|
|
# left its '+' glued onto $1, producing a bogus "+" entry that later
|
|
# failed to delete ("branch '+' not found").
|
|
set -l gone_branches (git branch -vv | awk '/: gone\]/ {sub(/^[*+]/, ""); print $1}')
|
|
set -l current_branch (git branch --show-current)
|
|
|
|
if test -n "$gone_branches"
|
|
# 3. Move to safety if needed (Quietly)
|
|
if contains "$current_branch" $gone_branches
|
|
echo (set_color yellow)"Current branch '$current_branch' was deleted on remote. Moving to main..."(set_color normal)
|
|
# Redirecting output to /dev/null to hide the 'Switched to branch' message
|
|
git checkout main >/dev/null 2>&1; or git checkout master >/dev/null 2>&1
|
|
end
|
|
end
|
|
|
|
# 4. Update the current branch (Quietly)
|
|
echo (set_color blue)"Updating current branch..."(set_color normal)
|
|
git pull --quiet
|
|
|
|
# 5. Final cleanup
|
|
if test -n "$gone_branches"
|
|
set -l delete_flag -d
|
|
if set -q _flag_force
|
|
set -l delete_flag -D
|
|
end
|
|
|
|
echo (set_color red)"Deleting orphaned local branches ($delete_flag):"(set_color normal)
|
|
for branch in $gone_branches
|
|
# We keep this output so you can see confirmation of which hashes were deleted
|
|
git branch $delete_flag $branch
|
|
end
|
|
else
|
|
echo (set_color green)"Everything is tidy. No orphaned branches found."(set_color normal)
|
|
end
|
|
end
|