From: Phillip Wood Date: Tue, 16 Jun 2026 09:57:08 GMT Subject: Re: [PATCH v14 6/6] branch: add --dry-run for --prune-merged Message-ID: <7b43a0f1-32a0-40f0-8c82-d2ee78809cc2@gmail.com> In-Reply-To: Hi Harald On 09/06/2026 11:11, Harald Nordgren via GitGitGadget wrote: > From: Harald Nordgren > > With --dry-run, --prune-merged prints the local branches it would > delete, one "Would delete branch " line each, and exits > without touching any ref. The same filtering applies, so the output > is exactly the set that the real run would delete. I can see this being very useful. > diff --git a/builtin/branch.c b/builtin/branch.c > index 52a0371292..7c52a88af2 100644 > --- a/builtin/branch.c > +++ b/builtin/branch.c > @@ -717,7 +717,7 @@ static int parse_opt_forked(const struct option *opt, const char *arg, int unset > } > > static int prune_merged_branches(int argc, const char **argv, > - int quiet) > + int quiet, int dry_run) Let's not start adding multiple boolean augments - use a flags argument like we do for delete_branches() - if you get feedback on one patch you should think about whether it applies later in the series as well. The rest of the implementation looks good. > diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh > index 3f7b1fc3d6..305c0141fc 100755 > --- a/t/t3200-branch.sh > +++ b/t/t3200-branch.sh > @@ -2040,4 +2040,48 @@ test_expect_success 'branch -d still deletes a pruneMerged=false branch' ' > test_must_fail git -C pm-optout-d rev-parse --verify refs/heads/one > ' > > +test_expect_success '--prune-merged --dry-run lists but does not delete' ' A good way to test --dry-run would be to add it to an existing test before calling --prune-merged without --dry-run. Thanks Phillip > + test_when_finished "rm -rf pm-dry" && > + git clone pm-upstream pm-dry && > + git -C pm-dry remote add fork ../pm-fork && > + test_config -C pm-dry remote.pushDefault fork && > + test_config -C pm-dry push.default current && > + git -C pm-dry branch one one-commit && > + git -C pm-dry branch --set-upstream-to=origin/next one && > + git -C pm-dry branch two two-commit && > + git -C pm-dry branch --set-upstream-to=origin/next two && > + > + git -C pm-dry branch --dry-run --prune-merged "origin/*" >actual && > + test_grep "Would delete branch one " actual && > + test_grep "Would delete branch two " actual && > + > + git -C pm-dry rev-parse --verify refs/heads/one && > + git -C pm-dry rev-parse --verify refs/heads/two > +' > + > +test_expect_success '--prune-merged --dry-run only lists branches the live run would delete' ' > + test_when_finished "rm -rf pm-dry-mixed" && > + git clone pm-upstream pm-dry-mixed && > + git -C pm-dry-mixed remote add fork ../pm-fork && > + test_config -C pm-dry-mixed remote.pushDefault fork && > + test_config -C pm-dry-mixed push.default current && > + git -C pm-dry-mixed checkout -b wip origin/next && > + git -C pm-dry-mixed branch --set-upstream-to=origin/next wip && > + test_commit -C pm-dry-mixed local-only && > + git -C pm-dry-mixed checkout - && > + git -C pm-dry-mixed branch merged one-commit && > + git -C pm-dry-mixed branch --set-upstream-to=origin/next merged && > + > + git -C pm-dry-mixed branch --dry-run --prune-merged "origin/*" >out && > + test_grep "Would delete branch merged" out && > + test_grep ! "Would delete branch wip" out && > + git -C pm-dry-mixed rev-parse --verify refs/heads/wip && > + git -C pm-dry-mixed rev-parse --verify refs/heads/merged > +' > + > +test_expect_success '--dry-run without --prune-merged is rejected' ' > + test_must_fail git -C forked branch --dry-run 2>err && > + test_grep "requires --prune-merged" err > +' > + > test_done