git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: "Thomas Weißschuh" <thomas@t-8ch.de>
Cc: git@vger.kernel.org, Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH v2] var: add GIT_DEFAULT_BRANCH variable
Date: Tue, 02 Nov 2021 17:53:46 +0100	[thread overview]
Message-ID: <211102.86czni1o72.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <20211102164434.1005707-1-thomas@t-8ch.de>


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@gmx.de>
> Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
> ---
>
> Changes from v1 ( https://lore.kernel.org/git/20211030140112.834650-1-thomas@t-8ch.de/ ):
> * 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(+)
>
> diff --git a/Documentation/git-var.txt b/Documentation/git-var.txt
> index 6072f936ab..387cc1b914 100644
> --- a/Documentation/git-var.txt
> +++ b/Documentation/git-var.txt
> @@ -59,6 +59,9 @@ ifdef::git-default-pager[]
>      The build you are using chose '{git-default-pager}' as the default.
>  endif::git-default-pager[]
>  
> +GIT_DEFAULT_BRANCH::
> +    The name of the first branch created in newly initialized repositories.
> +
>  SEE ALSO
>  --------
>  linkgit:git-commit-tree[1]
> diff --git a/builtin/var.c b/builtin/var.c
> index 6c6f46b4ae..d1d82b6c93 100644
> --- a/builtin/var.c
> +++ b/builtin/var.c
> @@ -5,6 +5,7 @@
>   */
>  #include "builtin.h"
>  #include "config.h"
> +#include "refs.h"
>  
>  static const char var_usage[] = "git var (-l | <variable>)";
>  
> @@ -27,6 +28,17 @@ static const char *pager(int flag)
>  	return pgm;
>  }
>  
> +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(...)?

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@evledraar.gmail.com/

  reply	other threads:[~2021-11-02 17:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-30 14:01 [PATCH] builtin: add git-default-branch command Thomas Weißschuh
2021-10-30 17:18 ` Ævar Arnfjörð Bjarmason
2021-11-02 13:39 ` Johannes Schindelin
2021-11-02 16:44   ` [PATCH v2] var: add GIT_DEFAULT_BRANCH variable Thomas Weißschuh
2021-11-02 16:53     ` Ævar Arnfjörð Bjarmason [this message]
2021-11-02 17:35       ` Thomas Weißschuh
2021-11-02 19:14         ` Ævar Arnfjörð Bjarmason
2021-11-02 20:08           ` Thomas Weißschuh
2021-11-03 11:37       ` Jeff King
2021-11-03 16:48         ` Eric Sunshine
2021-11-03 18:21     ` Junio C Hamano
2021-11-03 18:53       ` [PATCH v3] " Thomas Weißschuh
2021-11-03 19:57         ` Eric Sunshine
2021-11-03 20:04           ` Junio C Hamano
2021-11-03 20:17           ` [PATCH v4] " Thomas Weißschuh
2021-11-03 20:23             ` Junio C Hamano
2021-11-03 17:22   ` [PATCH] builtin: add git-default-branch command Junio C Hamano
2021-11-03 23:44     ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=211102.86czni1o72.gmgdl@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=thomas@t-8ch.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).