Re: [PATCH v2] var: add GIT_DEFAULT_BRANCH variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2021-11-02 17:53+0100, Ævar Arnfjörð Bjarmason wrote:
> On Tue, Nov 02 2021, Thomas Weißschuh wrote:
> 
> > Introduce the builtin variable GIT_DEFAULT_BRANCH which represents the
> > the default branch name that will be used by git-init.
> >
> > Currently this variable is equivalent to
> >     git config init.defaultbranch || 'master'
> >
> > This however will break if at one point the default branch is changed as
> > indicated by `default_branch_name_advice` in `refs.c`.
> >
> > By providing this command ahead of time users of git can make their
> > code forward-compatible.
> >
> > Co-developed-by: Johannes Schindelin <Johannes.Schindelin@xxxxxx>
> > Signed-off-by: Thomas Weißschuh <thomas@xxxxxxxx>
> > ---
> >
> > Changes from v1 ( https://lore.kernel.org/git/20211030140112.834650-1-thomas@xxxxxxxx/ ):
> > * Replaced the custom subcommand with an internal variable
> > * Cleaned up the tests
> >
> > @Johannes: I replaced BUG() with die() from your example because that seems to be
> > nicer for user facing messages.
> >
> >  Documentation/git-var.txt |  3 +++
> >  builtin/var.c             | 13 +++++++++++++
> >  t/t0007-git-var.sh        | 19 +++++++++++++++++++
> >  3 files changed, 35 insertions(+)
> >
> >  
> > +static const char *default_branch(int flag)
> > +{
> > +	const char *name = repo_default_branch_name(the_repository, 1);
> > +
> > +	if (!name)
> > +		die("could not determine the default branch name");
> 
> Isn't this die() unrechable given the similar logic in
> repo_default_branch_name()? Hence the previous BUG(...)?

Ok. Good point.

> I really don't see how it makes sense to add this to "git var", we have
> that to correspond to environment variables we use.
> 
> *Maybe* if we renamed GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME to
> GIT_INITIAL_BRANCH_NAME and made it a non-test thing like
> GIT_TEMPLATE_DIR, but even then shouldn't we be adding
> "GIT_TEMPLATE_DIR" and any number of other things to this as well?
> 
> I'm not saying that your patch needs to do that, but we really should
> think about the interface & future implications if we're going in this
> direction.
> 
> The reason I suggested extending "git config" in [1] is because it seems
> like a natural thing for "git config" to learn to spew out our idea of
> default hardcoded config values to the user.
> 
> But creating a variable form of that existing config just so we can have
> "git var" spew it out just seems weird.
> 
> We don't have or need such a variable now for anything else, so why go
> through that indirection, instead of something that closes the feature
> gap of asking what a config variable default is?
> 
> In any case whatever we do here this really should be updating the
> documentation of init.defaultbranch & the relevant bits in the "git
> init" manpage to add cross-references, similar to how we discuss
> GIT_TEMPLATE_DIR now.
>
> 1. https://lore.kernel.org/git/211030.86ilxe4edm.gmgdl@xxxxxxxxxxxxxxxxxxx/

I'll then wait for a consensus of the git devs. The actual implementation
shouldn't be the issue afterwards.

Thanks for looking into this!

Thomas



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux