Re: [PATCH v9 1/4] branch: move the deleteMerged opt-out check into a helper
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 20, 2026, 18:57 UTC
- Message-ID
- <xmqqy0anpbzb.fsf@gitster.g>
- In-Reply-To
- <37ef7636e069ce528728c43cd79f678293e0d035.1795184664.git.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 24 quoted lines
> From: Harald Nordgren <haraldnordgren@gmail.com> > > A later commit adds "git branch --delete-integrated", which deletes > branches whose tips are not reachable from their upstream. Those must > honor branch.<name>.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 <haraldnordgren@gmail.com> > --- > builtin/branch.c | 32 +++++++++++++++++++------------- > 1 file changed, 19 insertions(+), 13 deletions(-) > > diff --git a/builtin/branch.c b/builtin/branch.c > index b536b619bb..2c1a8b8395 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)
I am afraid that this is a somewhat selfish choice of a name that we would regret later, as it assumes that "delete once it is merged elsewhere" will continue to be the only destructive operation that people may want to exempt some branches from. The configuration key is named very specifically for that destructive operation (i.e., setting branch.<name>.deleteMerged to false is a way to say "no, even if it is merged, do not delete it"), so there is an impedance mismatch.
Either
(1) naming this function to make it clear that this is about
opting out of the deleteMerged operation, or (2) naming this function to make it clear that this is about opting
out of ANY destructive operation, and renaming the
configuration key to something less specific than deleteMerged
so that the user will be saved from any new destructive
operation we may add in the future, e.g., "force update to what
upstream says", by setting the same configuration variable to
opt out of it (e.g., branch.<name>.noClobber=true)would work better, perhaps?
Show 8 quoted lines
> +{
> + 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;The lack of a key, or the key explicitly set to true, will cause this function to say "no, this branch is not opted out", which smells like a risky default to me.
Putting the devil's advocate hat on (because I understand why the inventor of a feature wants it to apply as widely as possible), shouldn't this be the other way around? If the user does not explicitly say "I am fine losing this once we are done", shouldn't we be treating it as precious?