From: Harald Nordgren via GitGitGadget Date: Sun, 01 Nov 2026 08:22:08 GMT Subject: [PATCH v6 1/4] branch: move the deleteMerged opt-out check into a helper Message-ID: In-Reply-To: From: Harald Nordgren A later commit adds "git branch --delete-integrated", which deletes branches whose tips are not reachable from their upstream. Those must honor branch..deleteMerged=false as well. Move the check into a helper so it can be used in both places. No change in behavior. Signed-off-by: Harald Nordgren --- builtin/branch.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index a613148fc7..171b13b081 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -824,6 +824,23 @@ static int branch_pushes_to_upstream(struct branch *branch, return ret; } +static bool branch_opted_out(struct strbuf *key, const char *branch_name, + unsigned int flags) +{ + int opt_out; + + strbuf_reset(key); + strbuf_addf(key, "branch.%s.deletemerged", branch_name); + if (repo_config_get_bool(the_repository, key->buf, &opt_out) || + opt_out) + return false; + if (!(flags & DELETE_BRANCH_QUIET)) + fprintf(stderr, + _("Skipping '%s' (branch.%s.deleteMerged is false)\n"), + branch_name, branch_name); + return true; +} + static int delete_merged_branches(const struct strvec *upstreams, const char **argv, unsigned int flags) { @@ -852,7 +869,6 @@ static int delete_merged_branches(const struct strvec *upstreams, const char *branch_name; struct branch *branch; const char *upstream_refname; - int opt_out; if (!skip_prefix(branch_refname, "refs/heads/", &branch_name)) BUG("filter returned non-branch ref '%s'", branch_refname); @@ -870,18 +886,8 @@ static int delete_merged_branches(const struct strvec *upstreams, FILTER_REFS_BRANCHES, DELETE_BRANCH_SKIP_UNMERGED)) continue; - strbuf_reset(&key); - strbuf_addf(&key, "branch.%s.deletemerged", branch_name); - if (!repo_config_get_bool(the_repository, key.buf, &opt_out) && - !opt_out) { - if (!(flags & DELETE_BRANCH_QUIET)) - fprintf(stderr, - _("Skipping '%s' (branch.%s.deleteMerged is false)\n"), - branch_name, branch_name); - continue; - } - - strset_add(&deletable_branch_names, branch_name); + if (!branch_opted_out(&key, branch_name, flags)) + strset_add(&deletable_branch_names, branch_name); } protect_stacked_branch_bases(refs, &deletable_branch_names, -- gitgitgadget