From 3841a32216867915995ae594bb2bfb743a6aeb33 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 30 Sep 2026 12:26:08 +0000 Subject: [PATCH] fix(branch): pass HEAD to --merged when deleting merged branches `git branch --merged --format=...` fails with "malformed object name --format=%(refname:short)" because --merged takes an optional commit and git consumes the next argument as it. Deleting merged branches from `gitb branch delete` therefore did nothing. Pass HEAD explicitly. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01N7bXuSKAQZEE7BsHZdjQ21 --- scripts/branch.sh | 2 +- tests/test_branch_operations.bats | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/branch.sh b/scripts/branch.sh index 6352c3b..61dd5c4 100644 --- a/scripts/branch.sh +++ b/scripts/branch.sh @@ -448,7 +448,7 @@ function branch_script { "$main_branch"|"$current_branch"|master|main|develop) continue ;; esac merged_to_delete+=("$_mb") - done < <(git branch --merged --format='%(refname:short)') + done < <(git branch --merged HEAD --format='%(refname:short)') for branch_to_delete in "${merged_to_delete[@]}"; do delete_output=$(git branch -d "$branch_to_delete" 2>&1) diff --git a/tests/test_branch_operations.bats b/tests/test_branch_operations.bats index 351c769..033966d 100644 --- a/tests/test_branch_operations.bats +++ b/tests/test_branch_operations.bats @@ -99,6 +99,24 @@ teardown() { [ "$status" -ne 0 ] } +@test "branch deletion: merged-branch listing used by gitb branch delete works" { + create_test_branch "feature/merged" + make_test_commit "feature.txt" "Feature work" + git checkout main + git merge feature/merged --no-edit + + run git branch --merged HEAD --format='%(refname:short)' + [ "$status" -eq 0 ] + [[ "$output" == *"feature/merged"* ]] +} + +@test "branch deletion: --merged is never followed directly by another flag" { + # `--merged`/`--no-merged` take an optional commit, so git parses a + # following `--format=...` as that commit: "malformed object name". + run grep -rnE -- '--(no-)?merged +-' "${GITBASHER_ROOT}/scripts" + [ "$status" -ne 0 ] +} + # ===== Remote branch tests ===== @test "remote branches: can fetch from remote" {