All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: "Thomas Weißschuh" <thomas@t-8ch.de>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] builtin: add git-default-branch command
Date: Tue, 2 Nov 2021 14:39:27 +0100 (CET)	[thread overview]
Message-ID: <nycvar.QRO.7.76.6.2111021433010.56@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <20211030140112.834650-1-thomas@t-8ch.de>

[-- Attachment #1: Type: text/plain, Size: 1967 bytes --]

Hi Thomas,

On Sat, 30 Oct 2021, Thomas Weißschuh wrote:

> Introduce command `default-branch` which allows to retrieve the branch
> that will be used by git-init.
>
> Currently this command 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`.

I am very sympathetic to the motivation for your patch, I have had to
resort to an ugly hack in Git for Windows' script that generates the
installer: the script creates a throw-away repository _just_ to determine
said branch name.

>
> By providing this command ahead of time users of git can make their
> code forward-compatible.

It is probably overkill to introduce a whole new command for just this
single purpose.

But we do have prior art in Git how to display similar information: `git
var -l` will list e.g. `GIT_PAGER`, even if it is not configured
explicitly.

Something like this should be a good start along those lines:

-- snip --
diff --git a/builtin/var.c b/builtin/var.c
index 6c6f46b4aea..937c63939d9 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,16 @@ 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)
+		BUG("could not determine the default branch name");
+
+	return name;
+}
+
 struct git_var {
 	const char *name;
 	const char *(*read)(int);
@@ -36,6 +47,7 @@ static struct git_var git_vars[] = {
 	{ "GIT_AUTHOR_IDENT",   git_author_info },
 	{ "GIT_EDITOR", editor },
 	{ "GIT_PAGER", pager },
+	{ "GIT_DEFAULT_BRANCH", default_branch },
 	{ "", NULL },
 };

-- snap --

Thanks,
Johannes

  parent reply	other threads:[~2021-11-02 13:39 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 [this message]
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
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=nycvar.QRO.7.76.6.2111021433010.56@tvgsbejvaqbjf.bet \
    --to=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.