diff --git a/cli/bash/commands/basectl/subcommands/gh.sh b/cli/bash/commands/basectl/subcommands/gh.sh index a4b40aaf..a3f15e31 100644 --- a/cli/bash/commands/basectl/subcommands/gh.sh +++ b/cli/bash/commands/basectl/subcommands/gh.sh @@ -546,12 +546,9 @@ Note: --dry-run and --yes are mutually exclusive; choose one when overriding the default. Options: - --days Minimum age for stale branch reporting. Defaults to 30. - --format - Select human text or stable inspection JSON for stale reporting. - --dry-run Preview branches that would be deleted (default). - --yes Delete merged branches after preview. - --remote Also prune merged GitHub remote branches and stale origin/* refs. + stale: --days , --format + prune: --dry-run, --yes, --remote + -h, --help Show this help text. EOF } @@ -609,6 +606,7 @@ Note: Options: --dry-run Preview worktrees that would be removed (default). --yes Remove safe merged worktrees after preview. + -h, --help Show this help text. EOF } diff --git a/cli/bash/commands/basectl/subcommands/gh_branch_worktree.sh b/cli/bash/commands/basectl/subcommands/gh_branch_worktree.sh index 018bacda..ac55e05f 100644 --- a/cli/bash/commands/basectl/subcommands/gh_branch_worktree.sh +++ b/cli/bash/commands/basectl/subcommands/gh_branch_worktree.sh @@ -247,14 +247,19 @@ base_gh_branch_prune_local() { local dry_run="$1" local default_branch="$2" local branch current_branch merge_source merge_status worktree_path upstream - local deleted=0 skipped_worktree=0 skipped_upstream=0 failed=0 candidates=0 + local deleted=0 skipped_current=0 skipped_worktree=0 skipped_upstream=0 failed=0 candidates=0 current_branch="$(git branch --show-current)" printf 'Local branches\n' while read -r branch; do branch="${branch#\* }" branch="${branch## }" - [[ -z "$branch" || "$branch" == "$default_branch" || "$branch" == "$current_branch" ]] && continue + [[ -n "$branch" ]] || continue + if [[ "$branch" == "$default_branch" || "$branch" == "$current_branch" ]]; then + printf 'SKIP %s current/default branch protected\n' "$branch" + skipped_current=$((skipped_current + 1)) + continue + fi merge_source="" if base_gh_branch_cleanup_merged "$branch" "$default_branch" merge_source; then @@ -310,9 +315,9 @@ base_gh_branch_prune_local() { if ((skipped_worktree > 0)); then printf 'Hint: run `basectl gh worktree prune` to preview these worktrees, then `basectl gh worktree prune --yes` and rerun this command.\n' fi - printf 'Summary: %s %s, %s skipped worktree, %s skipped upstream, %s failed.\n' \ + printf 'Summary: %s %s, %s skipped current/default, %s skipped worktree, %s skipped upstream, %s failed.\n' \ "$deleted" "$([[ "$dry_run" -eq 1 ]] && printf 'would delete' || printf 'deleted')" \ - "$skipped_worktree" "$skipped_upstream" "$failed" + "$skipped_current" "$skipped_worktree" "$skipped_upstream" "$failed" if ((failed > 0)); then return 1 fi @@ -323,13 +328,13 @@ base_gh_branch_prune_github_branches() { local dry_run="$1" local default_branch="$2" local branch current_branch merge_status worktree_path remote_branches - local deleted=0 skipped_worktree=0 skipped_unmerged=0 failed=0 candidates=0 found=0 + local deleted=0 skipped_current=0 skipped_worktree=0 skipped_unmerged=0 failed=0 candidates=0 found=0 printf 'GitHub branches\n' if ! base_gh_prune_github_ready; then base_gh_error "GitHub merge verification requires the GitHub CLI 'gh' on PATH." printf 'SKIP GitHub merge verification unavailable; remote branches retained\n' - printf 'Summary: 0 %s, 0 skipped worktree, 0 skipped unmerged, 1 failed.\n' \ + printf 'Summary: 0 %s, 0 skipped current/default, 0 skipped worktree, 0 skipped unmerged, 1 failed.\n' \ "$([[ "$dry_run" -eq 1 ]] && printf 'would delete remotely' || printf 'deleted remotely')" return 1 fi @@ -342,7 +347,11 @@ base_gh_branch_prune_github_branches() { while read -r branch; do [[ -n "$branch" ]] || continue found=1 - [[ "$branch" == "$default_branch" || "$branch" == "$current_branch" ]] && continue + if [[ "$branch" == "$default_branch" || "$branch" == "$current_branch" ]]; then + printf 'SKIP origin/%s current/default branch protected\n' "$branch" + skipped_current=$((skipped_current + 1)) + continue + fi if base_gh_branch_github_merged "$branch"; then merge_status=0 @@ -386,9 +395,9 @@ base_gh_branch_prune_github_branches() { elif ((candidates == 0 && failed == 0)); then printf 'No merged GitHub remote branches found.\n' fi - printf 'Summary: %s %s, %s skipped worktree, %s skipped unmerged, %s failed.\n' \ + printf 'Summary: %s %s, %s skipped current/default, %s skipped worktree, %s skipped unmerged, %s failed.\n' \ "$deleted" "$([[ "$dry_run" -eq 1 ]] && printf 'would delete remotely' || printf 'deleted remotely')" \ - "$skipped_worktree" "$skipped_unmerged" "$failed" + "$skipped_current" "$skipped_worktree" "$skipped_unmerged" "$failed" if ((failed > 0)); then return 1 fi diff --git a/cli/bash/commands/basectl/tests/gh-branch-worktree.bats b/cli/bash/commands/basectl/tests/gh-branch-worktree.bats index a43711ca..2a014108 100644 --- a/cli/bash/commands/basectl/tests/gh-branch-worktree.bats +++ b/cli/bash/commands/basectl/tests/gh-branch-worktree.bats @@ -48,7 +48,9 @@ load ./basectl_helpers.bash [[ "$output" == *"basectl gh branch stale [--days ]"* ]] [[ "$output" == *"basectl gh branch prune [--dry-run] [--yes] [--remote]"* ]] [[ "$output" == *"Runs in dry-run mode by default. Pass --yes to apply changes."* ]] - [[ "$output" == *"--dry-run Preview branches that would be deleted (default)."* ]] + [[ "$output" == *"stale: --days , --format "* ]] + [[ "$output" == *"prune: --dry-run, --yes, --remote"* ]] + [[ "$output" == *"-h, --help Show this help text."* ]] [[ "$output" != *"basectl gh issue create"* ]] [[ "$output" != *"basectl gh worktree prune"* ]] } @@ -61,6 +63,7 @@ load ./basectl_helpers.bash [[ "$output" == *"Prune safe, merged Git worktrees and their local branches."* ]] [[ "$output" == *"Runs in dry-run mode by default. Pass --yes to apply changes."* ]] [[ "$output" == *"--dry-run Preview worktrees that would be removed (default)."* ]] + [[ "$output" == *"-h, --help Show this help text."* ]] [[ "$output" != *"basectl gh branch prune"* ]] [[ "$output" != *"basectl gh issue create"* ]] } @@ -190,7 +193,8 @@ load ./basectl_helpers.bash [[ "$output" == *"[DRY-RUN] Branch prune preview for default branch master."* ]] [[ "$output" == *"Local branches"* ]] [[ "$output" == *"[DRY-RUN] DELETE merged-work"* ]] - [[ "$output" == *"Summary: 1 would delete, 0 skipped worktree, 0 skipped upstream, 0 failed."* ]] + [[ "$output" == *"SKIP master current/default branch protected"* ]] + [[ "$output" == *"Summary: 1 would delete, 1 skipped current/default, 0 skipped worktree, 0 skipped upstream, 0 failed."* ]] [[ "$output" == *"Run with --yes to apply these changes."* ]] git -C "$repo" show-ref --verify --quiet refs/heads/merged-work } @@ -216,7 +220,7 @@ load ./basectl_helpers.bash [ "$status" -eq 0 ] [[ "$output" == *"DELETE merged-work"* ]] - [[ "$output" == *"Summary: 1 deleted, 0 skipped worktree, 0 skipped upstream, 0 failed."* ]] + [[ "$output" == *"Summary: 1 deleted, 1 skipped current/default, 0 skipped worktree, 0 skipped upstream, 0 failed."* ]] ! git -C "$repo" show-ref --verify --quiet refs/heads/merged-work } @@ -244,7 +248,7 @@ load ./basectl_helpers.bash [ "$status" -eq 0 ] [[ "$output" == *"SKIP merged-work attached to worktree "*"/merged-worktree"* ]] [[ "$output" == *'Hint: run `basectl gh worktree prune` to preview these worktrees, then `basectl gh worktree prune --yes` and rerun this command.'* ]] - [[ "$output" == *"Summary: 0 deleted, 1 skipped worktree, 0 skipped upstream, 0 failed."* ]] + [[ "$output" == *"Summary: 0 deleted, 1 skipped current/default, 1 skipped worktree, 0 skipped upstream, 0 failed."* ]] git -C "$repo" show-ref --verify --quiet refs/heads/merged-work } @@ -273,7 +277,7 @@ load ./basectl_helpers.bash [ "$status" -eq 0 ] [[ "$output" == *"SKIP merged-work not fully merged to upstream origin/merged-work"* ]] - [[ "$output" == *"Summary: 0 deleted, 0 skipped worktree, 1 skipped upstream, 0 failed."* ]] + [[ "$output" == *"Summary: 0 deleted, 1 skipped current/default, 0 skipped worktree, 1 skipped upstream, 0 failed."* ]] git -C "$repo" show-ref --verify --quiet refs/heads/merged-work } @@ -317,7 +321,7 @@ EOF [ "$status" -eq 0 ] [[ "$output" == *"SKIP unmerged-work not confirmed merged into master or through a merged GitHub PR; local branch retained"* ]] [[ "$output" == *"SKIP origin/unmerged-work no merged GitHub PR found for this branch; remote branch retained"* ]] - [[ "$output" == *"Summary: 0 deleted remotely, 0 skipped worktree, 1 skipped unmerged, 0 failed."* ]] + [[ "$output" == *"Summary: 0 deleted remotely, 1 skipped current/default, 0 skipped worktree, 1 skipped unmerged, 0 failed."* ]] git -C "$repo" show-ref --verify --quiet refs/heads/unmerged-work git -C "$repo" ls-remote --exit-code --heads origin unmerged-work >/dev/null } @@ -461,7 +465,7 @@ EOF [[ "$output" == *"[DRY-RUN] Branch prune preview for default branch master."* ]] [[ "$output" == *"GitHub branches"* ]] [[ "$output" == *"[DRY-RUN] DELETE-REMOTE origin/squash-remote merged GitHub PR"* ]] - [[ "$output" == *"Summary: 1 would delete remotely, 0 skipped worktree, 0 skipped unmerged, 0 failed."* ]] + [[ "$output" == *"Summary: 1 would delete remotely, 1 skipped current/default, 0 skipped worktree, 0 skipped unmerged, 0 failed."* ]] [[ "$output" == *"Run with --yes to apply these changes."* ]] git -C "$repo" ls-remote --exit-code --heads origin squash-remote >/dev/null } @@ -507,7 +511,7 @@ EOF [ "$status" -eq 0 ] [[ "$output" == *"GitHub branches"* ]] [[ "$output" == *"DELETE-REMOTE origin/squash-remote"* ]] - [[ "$output" == *"Summary: 1 deleted remotely, 0 skipped worktree, 0 skipped unmerged, 0 failed."* ]] + [[ "$output" == *"Summary: 1 deleted remotely, 1 skipped current/default, 0 skipped worktree, 0 skipped unmerged, 0 failed."* ]] ! git -C "$repo" ls-remote --exit-code --heads origin squash-remote >/dev/null } @@ -552,7 +556,7 @@ EOF [ "$status" -eq 1 ] [[ "$output" == *"failed to connect to api.github.com"* ]] [[ "$output" == *"SKIP origin/lookup-failure GitHub merge verification unavailable; remote branch retained"* ]] - [[ "$output" == *"Summary: 0 would delete remotely, 0 skipped worktree, 0 skipped unmerged, 1 failed."* ]] + [[ "$output" == *"Summary: 0 would delete remotely, 1 skipped current/default, 0 skipped worktree, 0 skipped unmerged, 1 failed."* ]] [[ "$output" == *"Resolve the reported failures and rerun before using --yes."* ]] git -C "$repo" ls-remote --exit-code --heads origin lookup-failure >/dev/null } @@ -585,7 +589,7 @@ EOF [ "$status" -eq 1 ] [[ "$output" == *"ERROR: GitHub merge verification requires the GitHub CLI 'gh' on PATH."* ]] [[ "$output" == *"SKIP GitHub merge verification unavailable; remote branches retained"* ]] - [[ "$output" == *"Summary: 0 would delete remotely, 0 skipped worktree, 0 skipped unmerged, 1 failed."* ]] + [[ "$output" == *"Summary: 0 would delete remotely, 0 skipped current/default, 0 skipped worktree, 0 skipped unmerged, 1 failed."* ]] [[ "$output" == *"Resolve the reported failures and rerun before using --yes."* ]] git -C "$repo" ls-remote --exit-code --heads origin unverified-remote >/dev/null } @@ -632,7 +636,7 @@ EOF [ "$status" -eq 0 ] [[ "$output" == *"SKIP squash-work attached to worktree "*"/squash-worktree"* ]] [[ "$output" == *"SKIP origin/squash-work attached to worktree "*"/squash-worktree"* ]] - [[ "$output" == *"Summary: 0 deleted remotely, 1 skipped worktree, 0 skipped unmerged, 0 failed."* ]] + [[ "$output" == *"Summary: 0 deleted remotely, 1 skipped current/default, 1 skipped worktree, 0 skipped unmerged, 0 failed."* ]] git -C "$repo" ls-remote --exit-code --heads origin squash-work >/dev/null } @@ -675,7 +679,7 @@ EOF [ "$status" -eq 0 ] [[ "$output" == *"DELETE squash-work"* ]] - [[ "$output" == *"Summary: 1 deleted, 0 skipped worktree, 0 skipped upstream, 0 failed."* ]] + [[ "$output" == *"Summary: 1 deleted, 1 skipped current/default, 0 skipped worktree, 0 skipped upstream, 0 failed."* ]] ! git -C "$repo" show-ref --verify --quiet refs/heads/squash-work } @@ -719,7 +723,7 @@ EOF [ "$status" -eq 1 ] [[ "$output" == *"failed to connect to api.github.com"* ]] [[ "$output" == *"SKIP lookup-failure GitHub merge verification unavailable; local branch retained"* ]] - [[ "$output" == *"Summary: 0 would delete, 0 skipped worktree, 0 skipped upstream, 1 failed."* ]] + [[ "$output" == *"Summary: 0 would delete, 1 skipped current/default, 0 skipped worktree, 0 skipped upstream, 1 failed."* ]] [[ "$output" == *"Resolve the reported failures and rerun before using --yes."* ]] git -C "$repo" show-ref --verify --quiet refs/heads/lookup-failure }