Skip to content

feat: add branch delete command for local + remote cleanup#36

Merged
alexandreafj merged 2 commits into
masterfrom
feat/add-branch-delete-command
May 20, 2026
Merged

feat: add branch delete command for local + remote cleanup#36
alexandreafj merged 2 commits into
masterfrom
feat/add-branch-delete-command

Conversation

@alexandreafj
Copy link
Copy Markdown
Owner

Summary

  • Adds gitm branch delete <branch-name> subcommand that removes a branch from both local and origin across selected repositories in one step
  • Safe by default: uses git branch -d (refuses unmerged branches); --force flag escalates to -D
  • Non-interactive runs (--all/--repo) require y/N confirmation before deleting; interactive mode uses the existing multi-select as confirmation
  • Protects the default branch and currently checked-out branches (skipped with a clear message)
  • Includes --no-remote flag for local-only deletion, consistent with branch rename

Test plan

  • TestDeleteLocalBranch — safe delete of merged branch, refusal of unmerged branch, force delete
  • TestBranchCmdHasSubcommands — updated to include delete
  • TestBranchDeleteCmdExists / TestBranchDeleteCmdFlags — command registration and flag parsing
  • TestBranchDelete_RepoFlag_LocalAndRemote — deletes local + remote via --repo
  • TestBranchDelete_NoRemote — deletes local only, remote survives
  • TestBranchDelete_Interactive — multi-select path
  • TestBranchDelete_ConfirmationDeclined — branch untouched when user says no
  • TestBranchDelete_DefaultBranchProtected — main/master never deleted
  • TestBranchDelete_CurrentBranchSkipped — checked-out branch skipped
  • TestBranchDelete_UnmergedWithoutForceSkipped / WithForce — safe vs force unmerged
  • TestBranchDelete_NoReposWithBranch / UnknownAliasErrors — error paths
  • All 431 tests pass with -race
  • make lint clean

🤖 Generated with Claude Code

Manually running `git branch -d` and `git push origin --delete` across
multiple repos is tedious and error-prone. The new `gitm branch delete`
subcommand handles both in one step, with safety checks for the default
branch, currently checked-out branches, and unmerged commits.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 20, 2026 07:52
@github-actions
Copy link
Copy Markdown

✅ All checks passed (Go 1.26)

Coverage: 69.4%

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new gitm branch delete <branch-name> subcommand to delete a branch across selected repositories (local + optional remote), with safety checks and confirmation behavior consistent with existing branch workflows.

Changes:

  • Introduces gitm branch delete command wiring, flags (--all, --repo, --force, --no-remote), and execution logic across repos in parallel.
  • Adds a new git helper DeleteLocalBranch and comprehensive test coverage for local/remote delete scenarios and safety cases.
  • Updates README command reference and project structure notes to document the new subcommand.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
README.md Documents the new gitm branch delete command, flags, behavior, and examples.
internal/git/git.go Adds DeleteLocalBranch helper used by the new command.
internal/git/git_more_test.go Adds unit test coverage for DeleteLocalBranch behavior (safe vs force).
internal/cli/ui.go Extends UI abstraction with a Confirm prompt for non-interactive deletes.
internal/cli/test_helpers_test.go Updates fakeUI to support Confirm in CLI tests.
internal/cli/branch.go Registers the new branch delete subcommand and flags/help text.
internal/cli/branch_test.go Verifies branch delete is registered and its flags exist.
internal/cli/branch_run.go Implements multi-repo branch delete logic (local + optional remote).
internal/cli/branch_run_test.go Adds end-to-end tests for delete flows (repo/all, interactive, safety, errors).

Comment thread internal/cli/branch_run.go
Comment thread internal/cli/branch_run.go Outdated
Comment thread internal/git/git.go
When `git branch -d` refuses an unmerged branch without --force, show it
as ⚠ SKIPPED (a safe guard) rather than ✗ ERROR (a system failure).
Matches the default-branch and current-branch skip reasons in the same
function and avoids a "broken" runner summary for expected behaviour.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

✅ All checks passed (Go 1.26)

Coverage: 69.4%

@alexandreafj alexandreafj merged commit f777325 into master May 20, 2026
1 check passed
@alexandreafj alexandreafj deleted the feat/add-branch-delete-command branch May 20, 2026 10:04
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