All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Phillip Wood <phillip.wood123@gmail.com>
Cc: Don Goodman-Wilson via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org, don@goodman-wilson.com, stolee@gmail.com,
	peff@peff.net, sandals@crustytoothpaste.net
Subject: Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories
Date: Fri, 12 Jun 2020 13:55:50 +0200 (CEST)	[thread overview]
Message-ID: <nycvar.QRO.7.76.6.2006121308030.56@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <be09ffbb-4e38-5b67-54da-0b60d5e2d8c3@gmail.com>

Hi Phillip,

On Thu, 11 Jun 2020, Phillip Wood wrote:

> On 10/06/2020 22:19, Don Goodman-Wilson via GitGitGadget wrote:
> > From: Don Goodman-Wilson <don@goodman-wilson.com>
> >
> > There is a growing number of projects trying to avoid the non-inclusive
> > name `master` in their repositories.
>
> I think it would be helpful to explain why 'master' is no-inclusive even
> if it originates from the concept of a master copy. i.e. it suggests
> master/slave even if git is not based on that concept.

Unfortunately, we do not even have that defense: the term `master` was
copied from BitKeeper, which firmly uses it in the `master/slave` context.
See e.g.
https://mail.gnome.org/archives/desktop-devel-list/2019-May/msg00066.html

I added a _brief_ extension to the context to the first commit's commit
message. However, I do not want to go into details here because _this_
patch series is only about empowering users to change their default main
branch name.

> Have you got some examples of projects that have changed and the names
> that they are using?

Yes, there are plenty examples, and I do not want to pick a tiny subset to
demonstrate that. A more useful resource is probably this post:
https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx

> I think it would be helpful if we can agree on a replacement for master
> - if every repository uses a different name for its main branch it adds
> an extra complication for new contributors to those projects.

Sure, and that's what I thought we'd discuss, too, maybe at the meeting I
proposed elsewhere (Emily started a new thread about it:
https://lore.kernel.org/git/20200610222719.GE148632@google.com/).

> >  For existing repositories, this
> > requires manual work. For new repositories, the only way to do that
> > automatically is by copying all of Git's template directory, then
> > hard-coding the desired default branch name into the `.git/HEAD` file,
> > and then configuring `init.templateDir` to point to those copied
> > template files.
> >
> > To make this process much less cumbersome, let's introduce support for
> > `core.defaultBranchName`. That way, users won't need to keep their
> > copied template files up to date, and won't interfere with default hooks
> > installed by their administrators.
> >
> > While at it, also let users set the default branch name via the
> > environment variable `GIT_TEST_DEFAULT_BRANCH_NAME`,
>
> I'm not sure we usually promote the use of GIT_TEST_... environment
> variables outside of the test suite.

True. Together with Alban's suggestion to make this purely work in the
test suite (i.e. not even adjust the C code to respect that environment
variable), you convinced me to (re-)move that part of the commit.

> > diff --git a/refs.c b/refs.c
> > index 224ff66c7bb..8499b3865cb 100644
> > --- a/refs.c
> > +++ b/refs.c
> > @@ -560,6 +560,40 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)
> >  		argv_array_pushf(prefixes, *p, len, prefix);
> >  }
> >
> > +char *git_default_branch_name(int short_name)
> > +{
> > +	const char *branch_name = getenv("GIT_TEST_DEFAULT_BRANCH_NAME");
> > +	char *from_config = NULL, *prefixed;
> > +
> > +	/*
> > +	 * If the default branch name was not specified via the environment
> > +	 * variable GIT_TEST_DEFAULT_BRANCH_NAME, retrieve it from the config
> > +	 * setting core.defaultBranchName. If neither are set, fall back to the
> > +	 * hard-coded default.
> > +	 */
> > +	if (!branch_name || !*branch_name) {
> > +		if (git_config_get_string("core.defaultbranchname",
> > +					  &from_config) < 0)
> > +			die(_("Could not retrieve `core.defaultBranchName`"));
> > +
> > +		if (from_config)
> > +			branch_name = from_config;
> > +		else
> > +			branch_name = "master";
> > +	}
> > +
> > +	if (short_name)
> > +		return from_config ? from_config : xstrdup(branch_name);
>
> If short_name is set we return without validating the name is that
> intentional?

No, unintentional. Thank you for pointing this out. It will be fixed in v2
(still working on it).

> > +
> > +	/* prepend "refs/heads/" to the branch name */
> > +	prefixed = xstrfmt("refs/heads/%s", branch_name);
> > +	if (check_refname_format(prefixed, 0))
> > +		die(_("invalid default branch name: '%s'"), branch_name);
> > +
> > +	free(from_config);
> > +	return prefixed;
> > +}
> > +
> >  /*
> >   * *string and *len will only be substituted, and *string returned (for
> >   * later free()ing) if the string passed in is a magic short-hand form
> > diff --git a/refs.h b/refs.h
> > index a92d2c74c83..e8d4f6e2f13 100644
> > --- a/refs.h
> > +++ b/refs.h
> > @@ -154,6 +154,12 @@ int repo_dwim_log(struct repository *r, const char *str, int len, struct object_
> >  int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
> >  int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
> >
> > +/*
> > + * Retrieves the name of the default branch. If `short_name` is non-zero, the
> > + * branch name will be prefixed with "refs/heads/".
>
> Isn't the other way around - the branch name is prefixed with
> "refs/heads/" if short is zero.

Absolutely. Thank you for your careful review, I read past this at least
half a dozen times.

> > + */
> > +char *git_default_branch_name(int short_name);
> > +
> >  /*
> >   * A ref_transaction represents a collection of reference updates that
> >   * should succeed or fail together.
> > diff --git a/t/t0001-init.sh b/t/t0001-init.sh
> > index 1edd5aeb8f0..b144cd8f46b 100755
> > --- a/t/t0001-init.sh
> > +++ b/t/t0001-init.sh
> > @@ -464,4 +464,24 @@ test_expect_success MINGW 'redirect std handles' '
> >  	grep "Needed a single revision" output.txt
> >  '
> >
> > +test_expect_success 'custom default branch name from config' '
> > +	git config --global core.defaultbranchname nmb &&
>
> In tests we usually use 'test_config' rather than 'git config' as the
> former automatically cleans up the config at the end of the test.

Right, and in this instance it is `test_config_global`.

> > +	GIT_TEST_DEFAULT_BRANCH_NAME= git init custom-config &&
> > +	git config --global --unset core.defaultbranchname &&
> > +	git -C custom-config symbolic-ref HEAD >actual &&
> > +	grep nmb actual
> > +'
> > +
> > +test_expect_success 'custom default branch name from env' '
> > +	GIT_TEST_DEFAULT_BRANCH_NAME=nmb git init custom-env &&
>
> It would be good to test that this overrides the config setting

Except that we'll make this a thing that is internal to the test suite
now. So this test case can go.

Thank you for helping me improve the patch series!
Dscho

  reply	other threads:[~2020-06-12 11:56 UTC|newest]

Thread overview: 180+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-10 21:19 [PATCH 0/9] Allow overriding the default name of the default branch Johannes Schindelin via GitGitGadget
2020-06-10 21:19 ` [PATCH 1/9] init: allow overriding the default branch name for new repositories Don Goodman-Wilson via GitGitGadget
2020-06-10 23:22   ` brian m. carlson
2020-06-11  0:16   ` Eric Sunshine
2020-06-11 14:09     ` Johannes Schindelin
2020-06-11 15:28       ` Junio C Hamano
2020-06-16 12:45     ` Jeff King
2020-06-16 12:47       ` Jeff King
2020-06-18 13:08         ` Johannes Schindelin
2020-06-23 20:32       ` Johannes Schindelin
2020-06-11  9:35   ` Phillip Wood
2020-06-12 11:55     ` Johannes Schindelin [this message]
2020-06-12 16:51       ` Junio C Hamano
2020-06-14 22:00         ` Johannes Schindelin
2020-06-15 10:00         ` Phillip Wood
2020-06-11 10:23   ` Alban Gruin
2020-06-11 23:14     ` Junio C Hamano
2020-06-11 23:46       ` brian m. carlson
2020-06-12 12:45         ` Johannes Schindelin
2020-06-13 18:01       ` Alban Gruin
2020-06-14  8:57         ` Johannes Schindelin
2020-06-16 12:25           ` Jeff King
2020-06-18 10:17             ` Johannes Schindelin
2020-06-10 21:19 ` [PATCH 2/9] remote: respect `core.defaultBranchName` Johannes Schindelin via GitGitGadget
2020-06-16 12:35   ` Jeff King
2020-06-18 10:21     ` Johannes Schindelin
2020-06-18 11:50       ` Jeff King
2020-06-23 21:15         ` Johannes Schindelin
2020-06-10 21:19 ` [PATCH 3/9] send-pack/transport-helper: " Johannes Schindelin via GitGitGadget
2020-06-10 21:19 ` [PATCH 4/9] testsvn: " Johannes Schindelin via GitGitGadget
2020-06-10 21:19 ` [PATCH 5/9] submodule: use the (possibly overridden) default branch name Johannes Schindelin via GitGitGadget
2020-06-15 10:46   ` Denton Liu
2020-06-10 21:19 ` [PATCH 6/9] clone: learn about the possibly-configured " Johannes Schindelin via GitGitGadget
2020-06-10 22:58   ` Junio C Hamano
2020-06-10 21:19 ` [PATCH 7/9] fmt-merge-msg: " Johannes Schindelin via GitGitGadget
2020-06-10 22:59   ` Junio C Hamano
2020-06-10 21:19 ` [PATCH 8/9] fast-export: respect the possibly-overridden " Johannes Schindelin via GitGitGadget
2020-06-10 21:54   ` Matt Rogers
2020-06-10 23:25     ` Junio C Hamano
2020-06-10 23:39     ` brian m. carlson
2020-06-11  0:20       ` Matt Rogers
2020-06-11  5:26         ` Junio C Hamano
2020-06-11 14:05           ` Johannes Schindelin
2020-06-11 15:05             ` Re* " Junio C Hamano
2020-06-11 16:44               ` Junio C Hamano
2020-06-11 18:18                 ` Junio C Hamano
2020-06-12 12:07                   ` Johannes Schindelin
2020-06-12 12:32                     ` Junio C Hamano
2020-06-12 12:03               ` Johannes Schindelin
2020-06-12 12:50                 ` Junio C Hamano
2020-06-12 12:53               ` Johannes Schindelin
2020-06-12 13:18                 ` Johannes Schindelin
2020-06-12 15:19                   ` Junio C Hamano
2020-06-12 15:22                     ` Junio C Hamano
2020-06-13  5:00                       ` Johannes Schindelin
2020-06-12 15:14                 ` Junio C Hamano
2020-06-13 11:49                   ` Johannes Sixt
2020-06-13 16:25                     ` Junio C Hamano
2020-06-13 14:47                       ` Johannes Schindelin
2020-06-13 18:49                         ` Junio C Hamano
2020-06-14  8:55                           ` Johannes Schindelin
2020-06-17 20:06                             ` Junio C Hamano
2020-06-23 21:11                               ` Johannes Schindelin
2020-06-23 21:32                                 ` Junio C Hamano
2020-06-13 14:44                   ` Johannes Schindelin
2020-06-11 13:57     ` Johannes Schindelin
2020-06-11 18:19       ` Junio C Hamano
2020-06-12 12:07         ` Johannes Schindelin
2020-06-10 21:19 ` [PATCH 9/9] Document how the default branch name can be overridden Johannes Schindelin via GitGitGadget
2020-06-11  0:18   ` Junio C Hamano
2020-06-10 23:11 ` [PATCH 0/9] Allow overriding the default name of the default branch Junio C Hamano
2020-06-11  5:42   ` Junio C Hamano
2020-06-11 13:44   ` Johannes Schindelin
2020-06-11 14:44     ` Junio C Hamano
2020-06-10 23:41 ` brian m. carlson
2020-06-11  1:07 ` Taylor Blau
2020-06-11 14:33   ` Johannes Schindelin
2020-06-15 10:03 ` Pratyush Yadav
2020-06-14 22:26   ` Johannes Schindelin
2020-06-16  0:19     ` Denton Liu
2020-06-23 20:10       ` Johannes Schindelin
2020-06-15 23:10   ` brian m. carlson
2020-06-15 12:50 ` [PATCH v2 00/12] " Johannes Schindelin via GitGitGadget
2020-06-15 12:50   ` [PATCH v2 01/12] fast-export: do anonymize the primary branch name Junio C Hamano via GitGitGadget
2020-06-16 12:58     ` Jeff King
2020-06-17 18:16       ` Junio C Hamano
2020-06-17 21:23         ` Jeff King
2020-06-18  2:06           ` Elijah Newren
2020-06-18  6:30             ` Junio C Hamano
2020-06-18  7:13               ` Elijah Newren
2020-06-18 11:45             ` Jeff King
2020-06-15 12:50   ` [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main " Johannes Schindelin via GitGitGadget
2020-06-15 15:00     ` Phillip Wood
2020-06-23 12:31       ` Johannes Schindelin
2020-06-15 17:05     ` Junio C Hamano
2020-06-23 19:19       ` Johannes Schindelin
2020-06-16  8:46     ` Ævar Arnfjörð Bjarmason
2020-06-17 18:21       ` Junio C Hamano
2020-06-16 13:04     ` Jeff King
2020-06-17 18:23       ` Junio C Hamano
2020-06-18 13:15         ` Johannes Schindelin
2020-06-17 20:56     ` Johannes Sixt
2020-06-17 21:16       ` Junio C Hamano
2020-06-23 21:12         ` Johannes Schindelin
2020-06-15 12:50   ` [PATCH v2 03/12] send-pack/transport-helper: respect `core.mainBranch` Johannes Schindelin via GitGitGadget
2020-06-15 12:50   ` [PATCH v2 04/12] git_main_branch_name(): optionally report the full ref name Johannes Schindelin via GitGitGadget
2020-06-15 15:04     ` Phillip Wood
2020-06-23 19:17       ` Johannes Schindelin
2020-06-15 12:50   ` [PATCH v2 05/12] fast-export: handle overridden main branch names correctly Johannes Schindelin via GitGitGadget
2020-06-15 15:05     ` Phillip Wood
2020-06-16 13:10       ` Jeff King
2020-06-16 15:49         ` Phillip Wood
2020-06-18 10:08         ` Johannes Schindelin
2020-06-15 17:09     ` Junio C Hamano
2020-06-23 19:22       ` Johannes Schindelin
2020-06-15 12:50   ` [PATCH v2 06/12] branch -m: adjust `core.mainBranch` if necessary Johannes Schindelin via GitGitGadget
2020-06-15 12:50   ` [PATCH v2 07/12] init: allow specifying the main branch name for the new repository Johannes Schindelin via GitGitGadget
2020-06-15 12:50   ` [PATCH v2 08/12] init: allow overriding the default main branch name via the config Don Goodman-Wilson via GitGitGadget
2020-06-15 12:50   ` [PATCH v2 09/12] clone: handle overridden main branch names Johannes Schindelin via GitGitGadget
2020-06-16 13:22     ` Jeff King
2020-06-23 20:58       ` Johannes Schindelin
2020-06-15 12:50   ` [PATCH v2 10/12] remote: learn about the possibly-overridden default main branch name Johannes Schindelin via GitGitGadget
2020-06-15 12:50   ` [PATCH v2 11/12] submodule: use the correct default for the " Johannes Schindelin via GitGitGadget
2020-06-16 13:46     ` Jeff King
2020-06-23 21:03       ` Johannes Schindelin
2020-06-23 21:14         ` Jeff King
2020-06-15 12:50   ` [PATCH v2 12/12] testsvn: respect `init.defaultBranch` Johannes Schindelin via GitGitGadget
2020-06-16 13:51     ` Jeff King
2020-06-23 21:07       ` Johannes Schindelin
2020-06-23 22:33   ` [PATCH v3 0/8] Allow overriding the default name of the default branch Johannes Schindelin via GitGitGadget
2020-06-23 22:33     ` [PATCH v3 1/8] fmt-merge-msg: stop treating `master` specially Johannes Schindelin via GitGitGadget
2020-06-24 16:16       ` Junio C Hamano
2020-06-25 13:07         ` Johannes Schindelin
2020-06-23 22:33     ` [PATCH v3 2/8] send-pack/transport-helper: avoid mentioning a particular branch Johannes Schindelin via GitGitGadget
2020-06-24  0:36       ` Junio C Hamano
2020-06-24 12:44         ` Johannes Schindelin
2020-06-24 15:44           ` Junio C Hamano
2020-06-25 13:05             ` Johannes Schindelin
2020-06-23 22:33     ` [PATCH v3 3/8] submodule: use a better fall-back for missing remote.<name>.branch Johannes Schindelin via GitGitGadget
2020-06-24  2:18       ` Philippe Blain
2020-06-24 12:51         ` Johannes Schindelin
2020-06-23 22:33     ` [PATCH v3 4/8] init: allow specifying the initial branch name for the new repository Johannes Schindelin via GitGitGadget
2020-06-24  0:58       ` Junio C Hamano
2020-06-24 12:55         ` Johannes Schindelin
2020-06-23 22:33     ` [PATCH v3 5/8] init: allow setting the default for the initial branch name via the config Don Goodman-Wilson via GitGitGadget
2020-06-24  1:05       ` Junio C Hamano
2020-06-24 12:56         ` Johannes Schindelin
2020-06-24 16:25           ` Junio C Hamano
2020-06-23 22:33     ` [PATCH v3 6/8] clone: use configured default branch name when appropriate Johannes Schindelin via GitGitGadget
2020-06-23 22:33     ` [PATCH v3 7/8] remote: use the " Johannes Schindelin via GitGitGadget
2020-06-24  1:10       ` Junio C Hamano
2020-06-24 13:00         ` Johannes Schindelin
2020-06-23 22:33     ` [PATCH v3 8/8] testsvn: respect `init.defaultBranch` Johannes Schindelin via GitGitGadget
2020-06-24 14:46     ` [PATCH v4 0/9] Allow overriding the default name of the default branch Johannes Schindelin via GitGitGadget
2020-06-24 14:46       ` [PATCH v4 1/9] fmt-merge-msg: stop treating `master` specially Johannes Schindelin via GitGitGadget
2020-06-29 16:20         ` Đoàn Trần Công Danh
2020-06-29 13:27           ` Johannes Schindelin
2020-06-30 15:05             ` Đoàn Trần Công Danh
2020-07-01 10:39               ` Johannes Schindelin
2020-07-01 19:54                 ` Junio C Hamano
2020-06-24 14:46       ` [PATCH v4 2/9] send-pack/transport-helper: avoid mentioning a particular branch Johannes Schindelin via GitGitGadget
2020-06-24 14:46       ` [PATCH v4 3/9] submodule: fall back to remote's HEAD for missing remote.<name>.branch Johannes Schindelin via GitGitGadget
2020-06-24 16:17         ` Junio C Hamano
2020-06-24 14:46       ` [PATCH v4 4/9] docs: add missing diamond brackets Johannes Schindelin via GitGitGadget
2020-06-24 14:46       ` [PATCH v4 5/9] init: allow specifying the initial branch name for the new repository Johannes Schindelin via GitGitGadget
2020-06-24 14:46       ` [PATCH v4 6/9] init: allow setting the default for the initial branch name via the config Don Goodman-Wilson via GitGitGadget
2020-06-24 14:46       ` [PATCH v4 7/9] clone: use configured default branch name when appropriate Johannes Schindelin via GitGitGadget
2020-06-24 14:46       ` [PATCH v4 8/9] remote: use the " Johannes Schindelin via GitGitGadget
2020-06-24 14:46       ` [PATCH v4 9/9] testsvn: respect `init.defaultBranch` Johannes Schindelin via GitGitGadget
2020-06-24 16:26       ` [PATCH v4 0/9] Allow overriding the default name of the default branch Junio C Hamano
2020-06-25 13:03         ` Johannes Schindelin
2020-06-29 22:41       ` brian m. carlson
2020-07-12 13:03         ` Edward Thomson
2020-07-12  8:19           ` Johannes Schindelin
     [not found]             ` <CA+WKDT1GMNTY5N862-7ui70D6-b1u6fuUkvctEYo+57aJGbjmw@mail.gmail.com>
2020-07-14 14:55               ` Johannes Schindelin
2020-06-16  9:47 ` [PATCH " Ævar Arnfjörð Bjarmason
2020-06-16 14:09   ` Jeff King
2020-06-16 14:24     ` Jeff King
2020-06-23 20:28       ` Johannes Schindelin
2020-06-17 20:28   ` Junio C Hamano

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.2006121308030.56@tvgsbejvaqbjf.bet \
    --to=johannes.schindelin@gmx.de \
    --cc=don@goodman-wilson.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=peff@peff.net \
    --cc=phillip.wood123@gmail.com \
    --cc=sandals@crustytoothpaste.net \
    --cc=stolee@gmail.com \
    /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.