Re: [PATCH v14 5/6] branch: add branch.<name>.pruneMerged opt-out
From: Phillip Wood <hidden>
Date: 2026-06-16 09:57:48
Hi Harald On 09/06/2026 11:11, Harald Nordgren via GitGitGadget wrote:
From: Harald Nordgren <redacted> Setting branch.<name>.pruneMerged=false exempts that branch from "git branch --prune-merged", which is useful for a topic you want to keep developing after an early round of it has been merged upstream. Unless --quiet is given, each skip is reported so the user knows why their topic was kept.
Sounds good
quoted hunk ↗ jump to hunk
@@ -755,6 +757,18 @@ static int prune_merged_branches(int argc, const char **argv, if (!push || !strcmp(push, upstream)) continue; + strbuf_addf(&key, "branch.%s.prunemerged", short_name); + if (!repo_config_get_bool(the_repository, key.buf, &opt_out) && + !opt_out) { + if (!quiet) + fprintf(stderr, + _("Skipping '%s' (branch.%s.pruneMerged is false)\n"), + short_name, short_name); + strbuf_release(&key); + continue; + } + strbuf_release(&key);
As this is in a loop we don't want to free the buffer on each iteration, only at the end. You should call strbuf_reset() just before strbuf_addf() above and then move this call to strbuf_release() out of the loop.
+test_expect_success '--prune-merged honours branch.<name>.pruneMerged=false' ' + test_when_finished "rm -rf pm-optout" && + git clone pm-upstream pm-optout && + git -C pm-optout remote add fork ../pm-fork && + test_config -C pm-optout remote.pushDefault fork && + test_config -C pm-optout push.default current && + git -C pm-optout branch one one-commit && + git -C pm-optout branch --set-upstream-to=origin/next one && + git -C pm-optout branch two two-commit && + git -C pm-optout branch --set-upstream-to=origin/next two && + test_config -C pm-optout branch.one.pruneMerged false && + + git -C pm-optout branch --prune-merged "origin/*" 2>err && + + git -C pm-optout rev-parse --verify refs/heads/one && + test_must_fail git -C pm-optout rev-parse --verify refs/heads/two && + test_grep "Skipping .one." err
Do we really need a whole new setup to test this - can't we just add a protected branch to an existing test? Thanks Phillip
+ +test_expect_success 'branch -d still deletes a pruneMerged=false branch' ' + test_when_finished "rm -rf pm-optout-d" && + git clone pm-upstream pm-optout-d && + git -C pm-optout-d branch one one-commit && + git -C pm-optout-d branch --set-upstream-to=origin/next one && + test_config -C pm-optout-d branch.one.pruneMerged false && + + git -C pm-optout-d branch -d one && + test_must_fail git -C pm-optout-d rev-parse --verify refs/heads/one +' + test_done