Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions cli/bash/commands/basectl/subcommands/gh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,9 @@ Note:
--dry-run and --yes are mutually exclusive; choose one when overriding the default.

Options:
--days <days> Minimum age for stale branch reporting. Defaults to 30.
--format <text|json>
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 <days>, --format <text|json>
prune: --dry-run, --yes, --remote
-h, --help Show this help text.
EOF
}

Expand Down Expand Up @@ -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
}

Expand Down
27 changes: 18 additions & 9 deletions cli/bash/commands/basectl/subcommands/gh_branch_worktree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 17 additions & 13 deletions cli/bash/commands/basectl/tests/gh-branch-worktree.bats
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ load ./basectl_helpers.bash
[[ "$output" == *"basectl gh branch stale [--days <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 <days>, --format <text|json>"* ]]
[[ "$output" == *"prune: --dry-run, --yes, --remote"* ]]
[[ "$output" == *"-h, --help Show this help text."* ]]
[[ "$output" != *"basectl gh issue create"* ]]
[[ "$output" != *"basectl gh worktree prune"* ]]
}
Expand All @@ -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"* ]]
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down
Loading