From: Phillip Wood Date: Mon, 13 Jul 2026 15:27:29 GMT Subject: Re: [PATCH v18 7/7] branch: add --dry-run for --delete-merged Message-ID: <278df7ad-caf1-40fa-b5f9-34d78f435fd0@gmail.com> In-Reply-To: <8d0323f4b30cdfed134ff2840cc8a9ab32f9db53.1782338106.git.gitgitgadget@gmail.com> Hi Harald On 24/06/2026 22:55, Harald Nordgren via GitGitGadget wrote: > From: Harald Nordgren > > With --dry-run, --delete-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. The same filtering as what? I think something like "git branch --dry-run --delete-merged ..." prints one line per ref that would be deleted without modifing any refs. would be sufficient > --dry-run is only meaningful together with --delete-merged and is > rejected otherwise. Good > @@ -346,13 +348,20 @@ static int delete_branches(int argc, const char **argv, int kinds, > free(target); > } > > - if (refs_delete_refs(get_main_ref_store(the_repository), NULL, &refs_to_delete, REF_NO_DEREF)) > + if (!dry_run && > + refs_delete_refs(get_main_ref_store(the_repository), NULL, &refs_to_delete, REF_NO_DEREF)) > ret = 1; > > for_each_string_list_item(item, &refs_to_delete) { > char *describe_ref = item->util; > char *name = item->string; > - if (!refs_ref_exists(get_main_ref_store(the_repository), name)) { > + if (dry_run) { > + if (!quiet) This matches what we do without '--dry-run' but what use is '--dry-run --quiet' if it does not print anything? > + printf(remote_branch > + ? _("Would delete remote-tracking branch %s (was %s).\n") > + : _("Would delete branch %s (was %s).\n"), > + name + branch_name_pos, describe_ref); > + } else if (!refs_ref_exists(get_main_ref_store(the_repository), name)) { > diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh > index b7595610d9..cddcde341d 100755 > --- a/t/t3200-branch.sh > +++ b/t/t3200-branch.sh > @@ -1892,8 +1892,12 @@ test_expect_success '--delete-merged deletes merged branches and spares the rest > ) && > sha=$(git -C repo rev-parse --short merged) && > > - git -C repo branch --delete-merged origin/next >actual 2>&1 && > + git -C repo branch --dry-run --delete-merged origin/next >actual 2>&1 && > + echo "Would delete branch merged (was $sha)." >expect && > + test_cmp expect actual && > + git -C repo rev-parse --verify refs/heads/merged && > > + git -C repo branch --delete-merged origin/next >actual 2>&1 && I was wondering why the diff shows the line above being deleted and then added, it is because previously there was a blank line after it. The test for --dry-run looks good. > echo "Deleted branch merged (was $sha)." >expect && > test_cmp expect actual && > git -C repo for-each-ref --format="%(refname:short)" refs/heads/ >actual && > @@ -2050,4 +2054,9 @@ test_expect_success "branch -d still deletes a deleteMerged=false branch" ' > test_must_fail git -C repo rev-parse --verify refs/heads/kept > ' > > +test_expect_success '--dry-run without --delete-merged is rejected' ' > + test_must_fail git -C forked branch --dry-run 2>err && > + test_grep "requires --delete-merged" err Nice Thanks Phillip