feat: add branch delete command for local + remote cleanup#36
Merged
Conversation
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>
|
✅ All checks passed (Go 1.26) Coverage: 69.4% |
There was a problem hiding this comment.
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 deletecommand wiring, flags (--all,--repo,--force,--no-remote), and execution logic across repos in parallel. - Adds a new git helper
DeleteLocalBranchand 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). |
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>
|
✅ All checks passed (Go 1.26) Coverage: 69.4% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gitm branch delete <branch-name>subcommand that removes a branch from both local and origin across selected repositories in one stepgit branch -d(refuses unmerged branches);--forceflag escalates to-D--all/--repo) requirey/Nconfirmation before deleting; interactive mode uses the existing multi-select as confirmation--no-remoteflag for local-only deletion, consistent withbranch renameTest plan
TestDeleteLocalBranch— safe delete of merged branch, refusal of unmerged branch, force deleteTestBranchCmdHasSubcommands— updated to includedeleteTestBranchDeleteCmdExists/TestBranchDeleteCmdFlags— command registration and flag parsingTestBranchDelete_RepoFlag_LocalAndRemote— deletes local + remote via--repoTestBranchDelete_NoRemote— deletes local only, remote survivesTestBranchDelete_Interactive— multi-select pathTestBranchDelete_ConfirmationDeclined— branch untouched when user says noTestBranchDelete_DefaultBranchProtected— main/master never deletedTestBranchDelete_CurrentBranchSkipped— checked-out branch skippedTestBranchDelete_UnmergedWithoutForceSkipped/WithForce— safe vs force unmergedTestBranchDelete_NoReposWithBranch/UnknownAliasErrors— error paths-racemake lintclean🤖 Generated with Claude Code