{"thread":{"id":"54691","subject":"[PATCH 2/3] get_default_branch_name(): prepare for showing some advice","startedAt":"2020-11-22T23:23:51Z","lastAt":"2021-02-03T05:22:17Z","messageCount":57,"participants":["Johannes Schindelin via GitGitGadget","Junio C Hamano","Johannes Schindelin","Philip Oakley","Felipe Contreras","SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"410505","messageId":"pull.921.git.git.1606087406.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":null,"subject":"[PATCH 0/3] Add helpful advice about init.defaultBranch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-22T23:23:23Z","receivedAt":"2020-11-22T23:23:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"It is our designated intention\n[https://sfconservancy.org/news/2020/jun/23/gitbranchname/] to \"to explore\nchanging the name of the first branch created automatically for new\nrepositories away from ‘master’\". Further, we promised that we \"will\nminimize disruption for Git's users and will include appropriate deprecation\nperiods\".\n\nTo that end, introduce a message giving advice to users running git init \nthat the fall-back for init.defaultBranch is subject to change, and how to\nconfigure it.\n\nThe beauty of this patch series, if I may say so, is that it does not commit\nus to any concrete plan, but opens the door for all options regarding the\ndefault branch name.\n\nJohannes Schindelin (3):\n  init: document `init.defaultBranch` better\n  get_default_branch_name(): prepare for showing some advice\n  init: provide useful advice about init.defaultBranch\n\n Documentation/git-init.txt    | 11 +++++++----\n builtin/clone.c               |  2 +-\n builtin/init-db.c             |  8 +++++---\n refs.c                        | 19 +++++++++++++++----\n refs.h                        |  4 ++--\n remote.c                      |  5 +++--\n t/t0001-init.sh               |  9 ++++++++-\n t/t1510-repo-setup.sh         |  2 +-\n t/t7414-submodule-mistakes.sh |  2 +-\n t/test-lib-functions.sh       |  3 ++-\n 10 files changed, 45 insertions(+), 20 deletions(-)\n\n\nbase-commit: faefdd61ec7c7f6f3c8c9907891465ac9a2a1475\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-921%2Fdscho%2Finit.defaultBranch-advice-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-921/dscho/init.defaultBranch-advice-v1\nPull-Request: https://github.com/git/git/pull/921\n-- \ngitgitgadget\n"},{"id":"410504","messageId":"42f694004322361b5495f2ce1a2eba638644f754.1606087406.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.git.git.1606087406.gitgitgadget@gmail.com","subject":"[PATCH 2/3] get_default_branch_name(): prepare for showing some advice","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-22T23:23:25Z","receivedAt":"2020-11-22T23:23:52Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nWe are about to introduce a message giving users running `git init` some\nadvice about `init.defaultBranch`. This will necessarily be done in\n`repo_default_branch_name()`.\n\nNot all code paths want to show that advice, though. In particular, the\n`git clone` codepath _specifically_ asks for `init_db()` to be quiet,\nvia the `INIT_DB_QUIET` flag.\n\nIn preparation for showing users above-mentioned advice, let's change\nthe function signature of `get_default_branch_name()` to accept the\nparameter `quiet`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/clone.c   | 2 +-\n builtin/init-db.c | 8 +++++---\n refs.c            | 6 +++---\n refs.h            | 4 ++--\n remote.c          | 5 +++--\n 5 files changed, 14 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex a0841923cf..64b1784011 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -1323,7 +1323,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\tremote_head = NULL;\n \t\toption_no_checkout = 1;\n \t\tif (!option_bare) {\n-\t\t\tconst char *branch = git_default_branch_name();\n+\t\t\tconst char *branch = git_default_branch_name(0);\n \t\t\tchar *ref = xstrfmt(\"refs/heads/%s\", branch);\n \n \t\t\tinstall_branch_config(0, branch, remote_name, ref);\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 01bc648d41..dcc45bef51 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -202,7 +202,8 @@ void initialize_repository_version(int hash_algo, int reinit)\n static int create_default_files(const char *template_path,\n \t\t\t\tconst char *original_git_dir,\n \t\t\t\tconst char *initial_branch,\n-\t\t\t\tconst struct repository_format *fmt)\n+\t\t\t\tconst struct repository_format *fmt,\n+\t\t\t\tint quiet)\n {\n \tstruct stat st1;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -267,7 +268,7 @@ static int create_default_files(const char *template_path,\n \t\tchar *ref;\n \n \t\tif (!initial_branch)\n-\t\t\tinitial_branch = git_default_branch_name();\n+\t\t\tinitial_branch = git_default_branch_name(quiet);\n \n \t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n \t\tif (check_refname_format(ref, 0) < 0)\n@@ -438,7 +439,8 @@ int init_db(const char *git_dir, const char *real_git_dir,\n \tvalidate_hash_algorithm(&repo_fmt, hash);\n \n \treinit = create_default_files(template_dir, original_git_dir,\n-\t\t\t\t      initial_branch, &repo_fmt);\n+\t\t\t\t      initial_branch, &repo_fmt,\n+\t\t\t\t      flags & INIT_DB_QUIET);\n \tif (reinit && initial_branch)\n \t\twarning(_(\"re-init: ignored --initial-branch=%s\"),\n \t\t\tinitial_branch);\ndiff --git a/refs.c b/refs.c\nindex 392f0bbf68..8df03122d6 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -562,7 +562,7 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n \t\tstrvec_pushf(prefixes, *p, len, prefix);\n }\n \n-char *repo_default_branch_name(struct repository *r)\n+char *repo_default_branch_name(struct repository *r, int quiet)\n {\n \tconst char *config_key = \"init.defaultbranch\";\n \tconst char *config_display_key = \"init.defaultBranch\";\n@@ -585,12 +585,12 @@ char *repo_default_branch_name(struct repository *r)\n \treturn ret;\n }\n \n-const char *git_default_branch_name(void)\n+const char *git_default_branch_name(int quiet)\n {\n \tstatic char *ret;\n \n \tif (!ret)\n-\t\tret = repo_default_branch_name(the_repository);\n+\t\tret = repo_default_branch_name(the_repository, quiet);\n \n \treturn ret;\n }\ndiff --git a/refs.h b/refs.h\nindex 6695518156..ff05d2e9fe 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -170,8 +170,8 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n  * The return value of `repo_default_branch_name()` is an allocated string. The\n  * return value of `git_default_branch_name()` is a singleton.\n  */\n-const char *git_default_branch_name(void);\n-char *repo_default_branch_name(struct repository *r);\n+const char *git_default_branch_name(int quiet);\n+char *repo_default_branch_name(struct repository *r, int quiet);\n \n /*\n  * A ref_transaction represents a collection of reference updates that\ndiff --git a/remote.c b/remote.c\nindex 8a6dbbb903..bdb88d4b7d 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -284,7 +284,7 @@ static void read_branches_file(struct remote *remote)\n \tif (frag)\n \t\t*(frag++) = '\\0';\n \telse\n-\t\tfrag = (char *)git_default_branch_name();\n+\t\tfrag = (char *)git_default_branch_name(0);\n \n \tadd_url_alias(remote, strbuf_detach(&buf, NULL));\n \trefspec_appendf(&remote->fetch, \"refs/heads/%s:refs/heads/%s\",\n@@ -2206,7 +2206,8 @@ struct ref *guess_remote_head(const struct ref *head,\n \n \t/* If a remote branch exists with the default branch name, let's use it. */\n \tif (!all) {\n-\t\tchar *ref = xstrfmt(\"refs/heads/%s\", git_default_branch_name());\n+\t\tchar *ref = xstrfmt(\"refs/heads/%s\",\n+\t\t\t\t    git_default_branch_name(0));\n \n \t\tr = find_ref_by_name(refs, ref);\n \t\tfree(ref);\n-- \ngitgitgadget\n\n"},{"id":"410506","messageId":"1518387eaa95098707878459bc74bd5ef2179386.1606087406.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.git.git.1606087406.gitgitgadget@gmail.com","subject":"[PATCH 1/3] init: document `init.defaultBranch` better","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-22T23:23:24Z","receivedAt":"2020-11-22T23:23:52Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nOur documentation does not mention any future plan to change 'master' to\nother value. It is a good idea to document this, though.\n\nInitial-patch-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/git-init.txt | 11 +++++++----\n 1 file changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\nindex 59ecda6c17..19f9f16e6b 100644\n--- a/Documentation/git-init.txt\n+++ b/Documentation/git-init.txt\n@@ -20,8 +20,9 @@ DESCRIPTION\n \n This command creates an empty Git repository - basically a `.git`\n directory with subdirectories for `objects`, `refs/heads`,\n-`refs/tags`, and template files.  An initial `HEAD` file that\n-references the HEAD of the master branch is also created.\n+`refs/tags`, and template files.  An initial branch without any\n+commits will be created (see the `--initial-branch` option below\n+for its name).\n \n If the `$GIT_DIR` environment variable is set then it specifies a path\n to use instead of `./.git` for the base of the repository.\n@@ -73,8 +74,10 @@ If this is reinitialization, the repository will be moved to the specified path.\n -b <branch-name>::\n --initial-branch=<branch-name>::\n \n-Use the specified name for the initial branch in the newly created repository.\n-If not specified, fall back to the default name: `master`.\n+Use the specified name for the initial branch in the newly created\n+repository.  If not specified, fall back to the default name (currently\n+`master`, but that will be changed in the future; The name can be customized\n+via the `init.defaultBranch` configuration variable).\n \n --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::\n \n-- \ngitgitgadget\n\n"},{"id":"410507","messageId":"253d6706e6ab97e71ec012f6de33c75f3e980701.1606087406.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.git.git.1606087406.gitgitgadget@gmail.com","subject":"[PATCH 3/3] init: provide useful advice about init.defaultBranch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-22T23:23:26Z","receivedAt":"2020-11-22T23:23:52Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nTo give ample warning in case we decide to change the fall-back for an\nunconfigured `init.defaultBranch`, let's introduce some advice that is\nshown upon `git init` when that value is not set.\n\nNote: three test cases in Git's test suite want to verify that the\n`stderr` output of `git init` is empty. With this patch, that is only\ntrue if `init.defaultBranch` is configured, so let's do exactly that in\nthose test cases. The same reasoning applies to `test_create_repo()`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n refs.c                        | 13 ++++++++++++-\n t/t0001-init.sh               |  9 ++++++++-\n t/t1510-repo-setup.sh         |  2 +-\n t/t7414-submodule-mistakes.sh |  2 +-\n t/test-lib-functions.sh       |  3 ++-\n 5 files changed, 24 insertions(+), 5 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 8df03122d6..61d712ca05 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -562,6 +562,14 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n \t\tstrvec_pushf(prefixes, *p, len, prefix);\n }\n \n+static const char default_branch_name_advice[] = N_(\n+\"Using '%s' as the name for the initial branch. This name is subject\\n\"\n+\"to change. To configure the name to use as the initial branch name in\\n\"\n+\"new repositories, or to silence this warning, run:\\n\"\n+\"\\n\"\n+\"\\tgit config --global init.defaultBranch <name>\\n\"\n+);\n+\n char *repo_default_branch_name(struct repository *r, int quiet)\n {\n \tconst char *config_key = \"init.defaultbranch\";\n@@ -574,8 +582,11 @@ char *repo_default_branch_name(struct repository *r, int quiet)\n \telse if (repo_config_get_string(r, config_key, &ret) < 0)\n \t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n \n-\tif (!ret)\n+\tif (!ret) {\n \t\tret = xstrdup(\"master\");\n+\t\tif (!quiet)\n+\t\t\tadvise(_(default_branch_name_advice), ret);\n+\t}\n \n \tfull_ref = xstrfmt(\"refs/heads/%s\", ret);\n \tif (check_refname_format(full_ref, 0))\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 69a320489f..754dab3bab 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -163,7 +163,7 @@ test_expect_success 'reinit' '\n \t(\n \t\tmkdir again &&\n \t\tcd again &&\n-\t\tgit init >out1 2>err1 &&\n+\t\tgit -c init.defaultBranch=initial init >out1 2>err1 &&\n \t\tgit init >out2 2>err2\n \t) &&\n \ttest_i18ngrep \"Initialized empty\" again/out1 &&\n@@ -558,6 +558,13 @@ test_expect_success 'overridden default initial branch name (config)' '\n \tgrep nmb actual\n '\n \n+test_expect_success 'advice on unconfigured init.defaultBranch' '\n+\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git -c color.advice=always \\\n+\t\tinit unconfigured-default-branch-name 2>err &&\n+\ttest_decode_color <err >decoded &&\n+\ttest_i18ngrep \"<YELLOW>hint: \" decoded\n+'\n+\n test_expect_success 'overridden default main branch name (env)' '\n \ttest_config_global init.defaultBranch nmb &&\n \tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&\ndiff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh\nindex 9974457f56..5189a520a2 100755\n--- a/t/t1510-repo-setup.sh\n+++ b/t/t1510-repo-setup.sh\n@@ -79,7 +79,7 @@ setup_repo () {\n \tname=$1 worktreecfg=$2 gitfile=$3 barecfg=$4 &&\n \tsane_unset GIT_DIR GIT_WORK_TREE &&\n \n-\tgit init \"$name\" &&\n+\tgit -c init.defaultBranch=repo init \"$name\" &&\n \tmaybe_config \"$name/.git/config\" core.worktree \"$worktreecfg\" &&\n \tmaybe_config \"$name/.git/config\" core.bare \"$barecfg\" &&\n \tmkdir -p \"$name/sub/sub\" &&\ndiff --git a/t/t7414-submodule-mistakes.sh b/t/t7414-submodule-mistakes.sh\nindex f2e7df59cf..0ed02938f9 100755\n--- a/t/t7414-submodule-mistakes.sh\n+++ b/t/t7414-submodule-mistakes.sh\n@@ -30,7 +30,7 @@ test_expect_success 'no warning when updating entry' '\n \n test_expect_success 'submodule add does not warn' '\n \ttest_when_finished \"git rm -rf submodule .gitmodules\" &&\n-\tgit submodule add ./embed submodule 2>stderr &&\n+\tgit -c init.defaultBranch=x submodule add ./embed submodule 2>stderr &&\n \ttest_i18ngrep ! warning stderr\n '\n \ndiff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\nindex 59bbf75e83..772152320a 100644\n--- a/t/test-lib-functions.sh\n+++ b/t/test-lib-functions.sh\n@@ -1202,7 +1202,8 @@ test_create_repo () {\n \tmkdir -p \"$repo\"\n \t(\n \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n-\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n+\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" \\\n+\t\t\t-c init.defaultBranch=master init \\\n \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n \t\terror \"cannot run git init -- have you built things yet?\"\n \t\tmv .git/hooks .git/hooks-disabled\n-- \ngitgitgadget\n"},{"id":"410508","messageId":"xmqqk0udot9p.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"1518387eaa95098707878459bc74bd5ef2179386.1606087406.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 1/3] init: document `init.defaultBranch` better","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-22T23:40:02Z","receivedAt":"2020-11-22T23:40:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\nwrites:\n\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n>\n> Our documentation does not mention any future plan to change 'master' to\n> other value. It is a good idea to document this, though.\n>\n> Initial-patch-by: Junio C Hamano <gitster@pobox.com>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n\nIt would have been nicer to have a reference to the original patch\n<xmqqd00a36wc.fsf@gitster.c.googlers.com> here after the three-dash\nlines, which would have made it easier for me to say that the\nupdated phrasing is much better.\n\nI do not think I deserve credit for this step in the series.  Please\ndrop \"initial-patch-by\" when you do a v2.\n\n>  Documentation/git-init.txt | 11 +++++++----\n>  1 file changed, 7 insertions(+), 4 deletions(-)\n>\n> diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\n> index 59ecda6c17..19f9f16e6b 100644\n> --- a/Documentation/git-init.txt\n> +++ b/Documentation/git-init.txt\n> @@ -20,8 +20,9 @@ DESCRIPTION\n>  \n>  This command creates an empty Git repository - basically a `.git`\n>  directory with subdirectories for `objects`, `refs/heads`,\n> -`refs/tags`, and template files.  An initial `HEAD` file that\n> -references the HEAD of the master branch is also created.\n> +`refs/tags`, and template files.  An initial branch without any\n> +commits will be created (see the `--initial-branch` option below\n> +for its name).\n\n\"branch without any commits\" is certainly easier to understand than\n\"unborn branch\", which was in my weatherballoon patch.  \n\nStepping back a bit more, I wonder if we want to make reference to\nimplementation details even less, e.g.\n\n    ... an empty Git repository---a `.git` directory to store\n    objects, branches and tags, hooks, and template files.\n\nwhich would be in the same spirit as not mentioning 'HEAD file'.\n\n> @@ -73,8 +74,10 @@ If this is reinitialization, the repository will be moved to the specified path.\n>  -b <branch-name>::\n>  --initial-branch=<branch-name>::\n>  \n> -Use the specified name for the initial branch in the newly created repository.\n> -If not specified, fall back to the default name: `master`.\n> +Use the specified name for the initial branch in the newly created\n> +repository.  If not specified, fall back to the default name (currently\n> +`master`, but that will be changed in the future; The name can be customized\n> +via the `init.defaultBranch` configuration variable).\n\ns/The/the/ after semicolon that ends a half-sentence.  Or\nalternatively, s/in the future;/in the future./\n\n\n>  \n>  --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::\n"},{"id":"410509","messageId":"xmqqft51osnu.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"253d6706e6ab97e71ec012f6de33c75f3e980701.1606087406.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 3/3] init: provide useful advice about init.defaultBranch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-22T23:53:09Z","receivedAt":"2020-11-22T23:53:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\nwrites:\n\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n>\n> To give ample warning in case we decide to change the fall-back for an\n> unconfigured `init.defaultBranch`, let's introduce some advice that is\n> shown upon `git init` when that value is not set.\n\nI know this means well.  \n\nI however doubt \"ample warning\" before we announce an actual\ndecision makes user's life any easier in practice, though.  Until\nthey know what it will be changed to (if we decide not to change\nanything, treat it as changing it to 'master'), they would not be\nable to decide if the name is more suitable for their use case.\n\nI further suspect that their choice will be influenced the most by\nthe choice made by the projects they most often interact with, and\nnot by our plan.\n\n> +static const char default_branch_name_advice[] = N_(\n> +\"Using '%s' as the name for the initial branch. This name is subject\\n\"\n> +\"to change. To configure the name to use as the initial branch name in\\n\"\n> +\"new repositories, or to silence this warning, run:\\n\"\n\ns/new repositories/all of your new repositories/ as that is the\nwhole point of using --global option below.\n\n> +\"\\n\"\n> +\"\\tgit config --global init.defaultBranch <name>\\n\"\n> +);\n> +\n\n> +test_expect_success 'advice on unconfigured init.defaultBranch' '\n> +\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git -c color.advice=always \\\n> +\t\tinit unconfigured-default-branch-name 2>err &&\n> +\ttest_decode_color <err >decoded &&\n> +\ttest_i18ngrep \"<YELLOW>hint: \" decoded\n> +'\n> +\n\n> diff --git a/t/t7414-submodule-mistakes.sh b/t/t7414-submodule-mistakes.sh\n> index f2e7df59cf..0ed02938f9 100755\n> --- a/t/t7414-submodule-mistakes.sh\n> +++ b/t/t7414-submodule-mistakes.sh\n> @@ -30,7 +30,7 @@ test_expect_success 'no warning when updating entry' '\n>  \n>  test_expect_success 'submodule add does not warn' '\n>  \ttest_when_finished \"git rm -rf submodule .gitmodules\" &&\n> -\tgit submodule add ./embed submodule 2>stderr &&\n> +\tgit -c init.defaultBranch=x submodule add ./embed submodule 2>stderr &&\n>  \ttest_i18ngrep ! warning stderr\n>  '\n\nIt is a bit subtle that this not only tests whatever \"git submodule\"\ntest it originally wanted to do but also serves as a test that the\nnew advice message is squelched by the presence of the configuration.\n\n> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n> index 59bbf75e83..772152320a 100644\n> --- a/t/test-lib-functions.sh\n> +++ b/t/test-lib-functions.sh\n> @@ -1202,7 +1202,8 @@ test_create_repo () {\n>  \tmkdir -p \"$repo\"\n>  \t(\n>  \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n> -\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n> +\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" \\\n> +\t\t\t-c init.defaultBranch=master init \\\n\nI wonder if this should be more like\n\n\t-c init.defaultBranch=${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}\n\nso that tests that want a particular branch name would get what they\nwant?\n\nEventually we would need to do the s/master/X/ if/when the actual\ndefault change happens.\n\n>  \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n>  \t\terror \"cannot run git init -- have you built things yet?\"\n>  \t\tmv .git/hooks .git/hooks-disabled\n"},{"id":"410511","messageId":"xmqq4klgq10d.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"xmqqft51osnu.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 3/3] init: provide useful advice about init.defaultBranch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-23T02:07:30Z","receivedAt":"2020-11-23T02:07:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n>> +static const char default_branch_name_advice[] = N_(\n>> +\"Using '%s' as the name for the initial branch. This name is subject\\n\"\n>> +\"to change. To configure the name to use as the initial branch name in\\n\"\n>> +\"new repositories, or to silence this warning, run:\\n\"\n>\n> s/new repositories/all of your new repositories/ as that is the\n> whole point of using --global option below.\n>\n>> +\"\\n\"\n>> +\"\\tgit config --global init.defaultBranch <name>\\n\"\n>> +);\n>> +\n\nThe above may give a valuable lesson to those who want to use one\nbranch name across new repositories, but it does not tell those who\nwanted 'trunk' (to match the project, perhaps github.com/cli/cli,\nwith which they intend to interact) how to recover from having\nalready created the 'master' branch.  We may want to add some text\nto suggest \"branch -M\" after giving the advice for the permanent\noption.\n\nAlso, it is unclear to those who do not have a good <name> in mind\n(or, those who do not care to choose a <name> for themselves), what\n<name> they should give to take the \"or to silence this warning\"\npart of the advice.  It probably is a good idea to rephrase and say\neither:\n\n    ... To configure ... in all your new repositories and squelch\n    this message, run:\n\n\tgit config --global init.defaultBranch <name>\n\nor\n\n    ... To configure ... in all your new repositories, run:\n\n\tgit config --global init.defaultBranch <name>\n\n    Note that this message won't appear after doing so.\n\nI am offhand not sure which one is better.\n\nThanks.\n"},{"id":"410522","messageId":"nycvar.QRO.7.76.6.2011231209470.56@tvgsbejvaqbjf.bet","threadId":"54691","inReplyTo":"xmqqk0udot9p.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 1/3] init: document `init.defaultBranch` better","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-11-23T12:07:55Z","receivedAt":"2020-11-23T12:08:03Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Sun, 22 Nov 2020, Junio C Hamano wrote:\n\n> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> > From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> >\n> > Our documentation does not mention any future plan to change 'master' to\n> > other value. It is a good idea to document this, though.\n> >\n> > Initial-patch-by: Junio C Hamano <gitster@pobox.com>\n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> > ---\n>\n> It would have been nicer to have a reference to the original patch\n> <xmqqd00a36wc.fsf@gitster.c.googlers.com> here after the three-dash\n> lines, which would have made it easier for me to say that the\n> updated phrasing is much better.\n\nThis is unfortunately not possible with GitGitGadget, which I use because\nit takes away so much of my burden when contributing patches.\n\n> I do not think I deserve credit for this step in the series.  Please\n> drop \"initial-patch-by\" when you do a v2.\n\nThis is not about \"deserving\". More than half of the patch is still\nidentical to what you wrote, I only pasted it. This is yours, not mine.\n\n> > diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\n> > index 59ecda6c17..19f9f16e6b 100644\n> > --- a/Documentation/git-init.txt\n> > +++ b/Documentation/git-init.txt\n> > @@ -20,8 +20,9 @@ DESCRIPTION\n> >\n> >  This command creates an empty Git repository - basically a `.git`\n> >  directory with subdirectories for `objects`, `refs/heads`,\n> > -`refs/tags`, and template files.  An initial `HEAD` file that\n> > -references the HEAD of the master branch is also created.\n> > +`refs/tags`, and template files.  An initial branch without any\n> > +commits will be created (see the `--initial-branch` option below\n> > +for its name).\n>\n> \"branch without any commits\" is certainly easier to understand than\n> \"unborn branch\", which was in my weatherballoon patch.\n>\n> Stepping back a bit more, I wonder if we want to make reference to\n> implementation details even less, e.g.\n>\n>     ... an empty Git repository---a `.git` directory to store\n>     objects, branches and tags, hooks, and template files.\n>\n> which would be in the same spirit as not mentioning 'HEAD file'.\n\nHmm. I'm of two minds there. On the one hand, it is nice to have a\nconciser description. On the other hand, it is nice to have a little bit\ndepth in the description.\n\nFor the time being, I'll leave it as-is.\n\n> > @@ -73,8 +74,10 @@ If this is reinitialization, the repository will be moved to the specified path.\n> >  -b <branch-name>::\n> >  --initial-branch=<branch-name>::\n> >\n> > -Use the specified name for the initial branch in the newly created repository.\n> > -If not specified, fall back to the default name: `master`.\n> > +Use the specified name for the initial branch in the newly created\n> > +repository.  If not specified, fall back to the default name (currently\n> > +`master`, but that will be changed in the future; The name can be customized\n> > +via the `init.defaultBranch` configuration variable).\n>\n> s/The/the/ after semicolon that ends a half-sentence.  Or\n> alternatively, s/in the future;/in the future./\n\nOkay.\n\n> >  --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::\n\nThanks for the thorough review,\nDscho\n"},{"id":"410523","messageId":"nycvar.QRO.7.76.6.2011231308140.56@tvgsbejvaqbjf.bet","threadId":"54691","inReplyTo":"xmqqft51osnu.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 3/3] init: provide useful advice about init.defaultBranch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-11-23T12:26:09Z","receivedAt":"2020-11-23T12:26:29Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Sun, 22 Nov 2020, Junio C Hamano wrote:\n\n> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> > From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> >\n> > To give ample warning in case we decide to change the fall-back for an\n> > unconfigured `init.defaultBranch`, let's introduce some advice that is\n> > shown upon `git init` when that value is not set.\n>\n> I know this means well.\n>\n> I however doubt \"ample warning\" before we announce an actual\n> decision makes user's life any easier in practice, though.\n\nI reworded the commit message to make the rationale more obvious: the\nample warning is to give users a chance to override whatever is Git's\ndefault branch name by configuring `init.defaultBranch`. If they care at\nall.\n\n> Until they know what it will be changed to (if we decide not to change\n> anything, treat it as changing it to 'master'), they would not be able\n> to decide if the name is more suitable for their use case.\n>\n> I further suspect that their choice will be influenced the most by\n> the choice made by the projects they most often interact with, and\n> not by our plan.\n>\n> > +static const char default_branch_name_advice[] = N_(\n> > +\"Using '%s' as the name for the initial branch. This name is subject\\n\"\n> > +\"to change. To configure the name to use as the initial branch name in\\n\"\n> > +\"new repositories, or to silence this warning, run:\\n\"\n>\n> s/new repositories/all of your new repositories/ as that is the\n> whole point of using --global option below.\n\nMakes sense.\n\n> > +\"\\n\"\n> > +\"\\tgit config --global init.defaultBranch <name>\\n\"\n> > +);\n> > +\n>\n> > +test_expect_success 'advice on unconfigured init.defaultBranch' '\n> > +\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git -c color.advice=always \\\n> > +\t\tinit unconfigured-default-branch-name 2>err &&\n> > +\ttest_decode_color <err >decoded &&\n> > +\ttest_i18ngrep \"<YELLOW>hint: \" decoded\n> > +'\n> > +\n>\n> > diff --git a/t/t7414-submodule-mistakes.sh b/t/t7414-submodule-mistakes.sh\n> > index f2e7df59cf..0ed02938f9 100755\n> > --- a/t/t7414-submodule-mistakes.sh\n> > +++ b/t/t7414-submodule-mistakes.sh\n> > @@ -30,7 +30,7 @@ test_expect_success 'no warning when updating entry' '\n> >\n> >  test_expect_success 'submodule add does not warn' '\n> >  \ttest_when_finished \"git rm -rf submodule .gitmodules\" &&\n> > -\tgit submodule add ./embed submodule 2>stderr &&\n> > +\tgit -c init.defaultBranch=x submodule add ./embed submodule 2>stderr &&\n> >  \ttest_i18ngrep ! warning stderr\n> >  '\n>\n> It is a bit subtle that this not only tests whatever \"git submodule\"\n> test it originally wanted to do but also serves as a test that the\n> new advice message is squelched by the presence of the configuration.\n\nThank you for catching this. It is a debugging left-over.\n\nThe real fix for the underlying issue is in the previous commit, which\nsilences the warning when `init_db()` is called via `clone`, as is the\ncase here.\n\nI removed it from v2.\n\n> > diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n> > index 59bbf75e83..772152320a 100644\n> > --- a/t/test-lib-functions.sh\n> > +++ b/t/test-lib-functions.sh\n> > @@ -1202,7 +1202,8 @@ test_create_repo () {\n> >  \tmkdir -p \"$repo\"\n> >  \t(\n> >  \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n> > -\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n> > +\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" \\\n> > +\t\t\t-c init.defaultBranch=master init \\\n>\n> I wonder if this should be more like\n>\n> \t-c init.defaultBranch=${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}\n>\n> so that tests that want a particular branch name would get what they\n> want?\n\nAs is custom with our `GIT_TEST_*` variables,\n`GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME` overrides `init.defaultBranch`.\n\nTherefore, _technically_ what you suggested is not even necessary here.\n\n> Eventually we would need to do the s/master/X/ if/when the actual\n> default change happens.\n\nHowever, _practically_, what you suggested is very helpful, as it will\nmake it easy to find when (if?) we finish the transition to a new\nfall-back.\n\nThank you for your thorough feedback,\nDscho\n\n> >  \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n> >  \t\terror \"cannot run git init -- have you built things yet?\"\n> >  \t\tmv .git/hooks .git/hooks-disabled\n>\n"},{"id":"410524","messageId":"b7df1e27-9ffc-5ca5-3c9a-77dbcff48d19@iee.email","threadId":"54691","inReplyTo":"253d6706e6ab97e71ec012f6de33c75f3e980701.1606087406.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 3/3] init: provide useful advice about init.defaultBranch","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2020-11-23T12:49:38Z","receivedAt":"2020-11-23T13:06:31Z","isPatch":true,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"hi dscho,\n\nOn 22/11/2020 23:23, Johannes Schindelin via GitGitGadget wrote:\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n>\n> To give ample warning in case we decide to change the fall-back for an\n> unconfigured `init.defaultBranch`, let's introduce some advice that is\n> shown upon `git init` when that value is not set.\n>\n> Note: three test cases in Git's test suite want to verify that the\n> `stderr` output of `git init` is empty. With this patch, that is only\n> true if `init.defaultBranch` is configured, so let's do exactly that in\n> those test cases. The same reasoning applies to `test_create_repo()`.\n>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>  refs.c                        | 13 ++++++++++++-\n>  t/t0001-init.sh               |  9 ++++++++-\n>  t/t1510-repo-setup.sh         |  2 +-\n>  t/t7414-submodule-mistakes.sh |  2 +-\n>  t/test-lib-functions.sh       |  3 ++-\n>  5 files changed, 24 insertions(+), 5 deletions(-)\n>\n> diff --git a/refs.c b/refs.c\n> index 8df03122d6..61d712ca05 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -562,6 +562,14 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n>  \t\tstrvec_pushf(prefixes, *p, len, prefix);\n>  }\n>  \n> +static const char default_branch_name_advice[] = N_(\n> +\"Using '%s' as the name for the initial branch. This name is subject\\n\"\n> +\"to change. \nThis sounds like Git will change the branch name within the user's repo,\nrather than \"The default\" being subject to change.  So maybe\ns/This/The default/   ?\n\nPhilip\n\n> To configure the name to use as the initial branch name in\\n\"\n> +\"new repositories, or to silence this warning, run:\\n\"\n> +\"\\n\"\n> +\"\\tgit config --global init.defaultBranch <name>\\n\"\n> +);\n> +\n>  char *repo_default_branch_name(struct repository *r, int quiet)\n>  {\n>  \tconst char *config_key = \"init.defaultbranch\";\n> @@ -574,8 +582,11 @@ char *repo_default_branch_name(struct repository *r, int quiet)\n>  \telse if (repo_config_get_string(r, config_key, &ret) < 0)\n>  \t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n>  \n> -\tif (!ret)\n> +\tif (!ret) {\n>  \t\tret = xstrdup(\"master\");\n> +\t\tif (!quiet)\n> +\t\t\tadvise(_(default_branch_name_advice), ret);\n> +\t}\n>  \n>  \tfull_ref = xstrfmt(\"refs/heads/%s\", ret);\n>  \tif (check_refname_format(full_ref, 0))\n> diff --git a/t/t0001-init.sh b/t/t0001-init.sh\n> index 69a320489f..754dab3bab 100755\n> --- a/t/t0001-init.sh\n> +++ b/t/t0001-init.sh\n> @@ -163,7 +163,7 @@ test_expect_success 'reinit' '\n>  \t(\n>  \t\tmkdir again &&\n>  \t\tcd again &&\n> -\t\tgit init >out1 2>err1 &&\n> +\t\tgit -c init.defaultBranch=initial init >out1 2>err1 &&\n>  \t\tgit init >out2 2>err2\n>  \t) &&\n>  \ttest_i18ngrep \"Initialized empty\" again/out1 &&\n> @@ -558,6 +558,13 @@ test_expect_success 'overridden default initial branch name (config)' '\n>  \tgrep nmb actual\n>  '\n>  \n> +test_expect_success 'advice on unconfigured init.defaultBranch' '\n> +\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git -c color.advice=always \\\n> +\t\tinit unconfigured-default-branch-name 2>err &&\n> +\ttest_decode_color <err >decoded &&\n> +\ttest_i18ngrep \"<YELLOW>hint: \" decoded\n> +'\n> +\n>  test_expect_success 'overridden default main branch name (env)' '\n>  \ttest_config_global init.defaultBranch nmb &&\n>  \tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&\n> diff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh\n> index 9974457f56..5189a520a2 100755\n> --- a/t/t1510-repo-setup.sh\n> +++ b/t/t1510-repo-setup.sh\n> @@ -79,7 +79,7 @@ setup_repo () {\n>  \tname=$1 worktreecfg=$2 gitfile=$3 barecfg=$4 &&\n>  \tsane_unset GIT_DIR GIT_WORK_TREE &&\n>  \n> -\tgit init \"$name\" &&\n> +\tgit -c init.defaultBranch=repo init \"$name\" &&\n>  \tmaybe_config \"$name/.git/config\" core.worktree \"$worktreecfg\" &&\n>  \tmaybe_config \"$name/.git/config\" core.bare \"$barecfg\" &&\n>  \tmkdir -p \"$name/sub/sub\" &&\n> diff --git a/t/t7414-submodule-mistakes.sh b/t/t7414-submodule-mistakes.sh\n> index f2e7df59cf..0ed02938f9 100755\n> --- a/t/t7414-submodule-mistakes.sh\n> +++ b/t/t7414-submodule-mistakes.sh\n> @@ -30,7 +30,7 @@ test_expect_success 'no warning when updating entry' '\n>  \n>  test_expect_success 'submodule add does not warn' '\n>  \ttest_when_finished \"git rm -rf submodule .gitmodules\" &&\n> -\tgit submodule add ./embed submodule 2>stderr &&\n> +\tgit -c init.defaultBranch=x submodule add ./embed submodule 2>stderr &&\n>  \ttest_i18ngrep ! warning stderr\n>  '\n>  \n> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n> index 59bbf75e83..772152320a 100644\n> --- a/t/test-lib-functions.sh\n> +++ b/t/test-lib-functions.sh\n> @@ -1202,7 +1202,8 @@ test_create_repo () {\n>  \tmkdir -p \"$repo\"\n>  \t(\n>  \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n> -\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n> +\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" \\\n> +\t\t\t-c init.defaultBranch=master init \\\n>  \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n>  \t\terror \"cannot run git init -- have you built things yet?\"\n>  \t\tmv .git/hooks .git/hooks-disabled\n\n"},{"id":"410527","messageId":"nycvar.QRO.7.76.6.2011231326150.56@tvgsbejvaqbjf.bet","threadId":"54691","inReplyTo":"xmqq4klgq10d.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 3/3] init: provide useful advice about init.defaultBranch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-11-23T12:28:20Z","receivedAt":"2020-11-23T13:30:15Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Sun, 22 Nov 2020, Junio C Hamano wrote:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n> >> +static const char default_branch_name_advice[] = N_(\n> >> +\"Using '%s' as the name for the initial branch. This name is subject\\n\"\n> >> +\"to change. To configure the name to use as the initial branch name in\\n\"\n> >> +\"new repositories, or to silence this warning, run:\\n\"\n> >\n> > s/new repositories/all of your new repositories/ as that is the\n> > whole point of using --global option below.\n> >\n> >> +\"\\n\"\n> >> +\"\\tgit config --global init.defaultBranch <name>\\n\"\n> >> +);\n> >> +\n>\n> The above may give a valuable lesson to those who want to use one\n> branch name across new repositories, but it does not tell those who\n> wanted 'trunk' (to match the project, perhaps github.com/cli/cli,\n> with which they intend to interact) how to recover from having\n> already created the 'master' branch.  We may want to add some text\n> to suggest \"branch -M\" after giving the advice for the permanent\n> option.\n\nGood point.\n\n> Also, it is unclear to those who do not have a good <name> in mind\n> (or, those who do not care to choose a <name> for themselves), what\n> <name> they should give to take the \"or to silence this warning\"\n> part of the advice.\n\nAlso a good point.\n\n> It probably is a good idea to rephrase and say\n> either:\n>\n>     ... To configure ... in all your new repositories and squelch\n>     this message, run:\n>\n> \tgit config --global init.defaultBranch <name>\n>\n> or\n>\n>     ... To configure ... in all your new repositories, run:\n>\n> \tgit config --global init.defaultBranch <name>\n>\n>     Note that this message won't appear after doing so.\n\nI came up with this, which I intend to submit with v2:\n\nstatic const char default_branch_name_advice[] = N_(\n\"Using '%s' as the name for the initial branch. This name is subject\\n\"\n\"to change. To configure the initial branch name to use in all of your\\n\"\n\"new repositories (or to suppress this warning), run:\\n\"\n\"\\n\"\n\"\\tgit config --global init.defaultBranch <name>\\n\"\n\"\\n\"\n\"Common names are 'main', 'trunk' and 'development'. The initial branch\\n\"\n\"can be renamed via this command:\\n\"\n\"\\n\"\n\"\\tgit branch -m <name>\\n\"\n);\n\nCiao,\nDscho\n"},{"id":"410544","messageId":"xmqqv9dvor27.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"nycvar.QRO.7.76.6.2011231326150.56@tvgsbejvaqbjf.bet","subject":"Re: [PATCH 3/3] init: provide useful advice about init.defaultBranch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-23T18:40:00Z","receivedAt":"2020-11-23T18:40:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n>> The above may give a valuable lesson to those who want to use one\n>> branch name across new repositories, but it does not tell those who\n>> wanted 'trunk' (to match the project, perhaps github.com/cli/cli,\n>> with which they intend to interact) how to recover from having\n>> already created the 'master' branch.  We may want to add some text\n>> to suggest \"branch -M\" after giving the advice for the permanent\n>> option.\n>\n> Good point.\n>\n>> Also, it is unclear to those who do not have a good <name> in mind\n>> (or, those who do not care to choose a <name> for themselves), what\n>> <name> they should give to take the \"or to silence this warning\"\n>> part of the advice.\n>\n> Also a good point.\n\n> I came up with this, which I intend to submit with v2:\n>\n> static const char default_branch_name_advice[] = N_(\n> \"Using '%s' as the name for the initial branch. This name is subject\\n\"\n> \"to change. To configure the initial branch name to use in all of your\\n\"\n> \"new repositories (or to suppress this warning), run:\\n\"\n\nThe same issue around \"to suppress\" is here, though.\n\n> \"\\n\"\n> \"\\tgit config --global init.defaultBranch <name>\\n\"\n> \"\\n\"\n> \"Common names are 'main', 'trunk' and 'development'. The initial branch\\n\"\n> \"can be renamed via this command:\\n\"\n> \"\\n\"\n> \"\\tgit branch -m <name>\\n\"\n\nIt is very likely that the users are on an unborn branch when they\nsee this message and \"git branch -m/-M <name>\" does not work.  We'd\nprobably want to update \"git branch\" to allow renaming the current\nbranch that is unborn.\n\nIn the meantime, you could do \"git checkout --orphan <name>\" here,\nbut once <name> exists as a branch that would not work, so...\n\n\n> );\n>\n> Ciao,\n> Dscho\n"},{"id":"410567","messageId":"nycvar.QRO.7.76.6.2011232136191.56@tvgsbejvaqbjf.bet","threadId":"54691","inReplyTo":"xmqqv9dvor27.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 3/3] init: provide useful advice about init.defaultBranch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-11-23T20:46:09Z","receivedAt":"2020-11-23T20:46:18Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Mon, 23 Nov 2020, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n>\n> >> The above may give a valuable lesson to those who want to use one\n> >> branch name across new repositories, but it does not tell those who\n> >> wanted 'trunk' (to match the project, perhaps github.com/cli/cli,\n> >> with which they intend to interact) how to recover from having\n> >> already created the 'master' branch.  We may want to add some text\n> >> to suggest \"branch -M\" after giving the advice for the permanent\n> >> option.\n> >\n> > Good point.\n> >\n> >> Also, it is unclear to those who do not have a good <name> in mind\n> >> (or, those who do not care to choose a <name> for themselves), what\n> >> <name> they should give to take the \"or to silence this warning\"\n> >> part of the advice.\n> >\n> > Also a good point.\n>\n> > I came up with this, which I intend to submit with v2:\n> >\n> > static const char default_branch_name_advice[] = N_(\n> > \"Using '%s' as the name for the initial branch. This name is subject\\n\"\n> > \"to change. To configure the initial branch name to use in all of your\\n\"\n> > \"new repositories (or to suppress this warning), run:\\n\"\n>\n> The same issue around \"to suppress\" is here, though.\n\nHmm. I would like to believe that readers understand that setting it to\n_any_ name would suppress this warning.\n\n> > \"\\n\"\n> > \"\\tgit config --global init.defaultBranch <name>\\n\"\n> > \"\\n\"\n> > \"Common names are 'main', 'trunk' and 'development'. The initial branch\\n\"\n> > \"can be renamed via this command:\\n\"\n> > \"\\n\"\n> > \"\\tgit branch -m <name>\\n\"\n>\n> It is very likely that the users are on an unborn branch when they\n> see this message and \"git branch -m/-M <name>\" does not work.  We'd\n> probably want to update \"git branch\" to allow renaming the current\n> branch that is unborn.\n\nOuch, good point, I had not even realized that that does not work. In v2,\nI will include a patch that lets it work.\n\n> In the meantime, you could do \"git checkout --orphan <name>\" here,\n> but once <name> exists as a branch that would not work, so...\n\nCareful. We should start thinking about phasing out either `checkout` or\n`switch`. The latter was intended to supersede the former with respect to\nworking on branches, so I would think of phasing out `checkout` and favor\n`switch` instead.\n\nThat issue aside, `git switch --orphan <name>` is not necessarily a good\nUI here. Its documentation talks about creating a new branch, deleting all\ntracked files. While it is technically still correct that this command,\nwhen run on an unborn branch, does the same as renaming said branch, it is\nhighly unintuitive to think about it that way. (\"I don't want to create a\nnew branch, I want to rename the current one! And whoa, delete tracked\nfiles? I don't want to delete _any_ files! What do you mean: there aren't\nany tracked files, so none are deleted? Why do you talk about deleting\nfiles, then?\")\n\nSo in the interest of _reducing_ confusion, I would really, really,\n_really_ like to avoid mentioning that command in this advice.\n\nIt really is much better to make `git branch -m <name>` work in this\nscenario.\n\nCiao,\nDscho\n\n>\n>\n> > );\n> >\n> > Ciao,\n> > Dscho\n>\n"},{"id":"410568","messageId":"nycvar.QRO.7.76.6.2011232146530.56@tvgsbejvaqbjf.bet","threadId":"54691","inReplyTo":"b7df1e27-9ffc-5ca5-3c9a-77dbcff48d19@iee.email","subject":"Re: [PATCH 3/3] init: provide useful advice about init.defaultBranch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-11-23T20:47:23Z","receivedAt":"2020-11-23T20:47:28Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Philip,\n\nOn Mon, 23 Nov 2020, Philip Oakley wrote:\n\n> On 22/11/2020 23:23, Johannes Schindelin via GitGitGadget wrote:\n> > From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> >\n> > To give ample warning in case we decide to change the fall-back for an\n> > unconfigured `init.defaultBranch`, let's introduce some advice that is\n> > shown upon `git init` when that value is not set.\n> >\n> > Note: three test cases in Git's test suite want to verify that the\n> > `stderr` output of `git init` is empty. With this patch, that is only\n> > true if `init.defaultBranch` is configured, so let's do exactly that in\n> > those test cases. The same reasoning applies to `test_create_repo()`.\n> >\n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> > ---\n> >  refs.c                        | 13 ++++++++++++-\n> >  t/t0001-init.sh               |  9 ++++++++-\n> >  t/t1510-repo-setup.sh         |  2 +-\n> >  t/t7414-submodule-mistakes.sh |  2 +-\n> >  t/test-lib-functions.sh       |  3 ++-\n> >  5 files changed, 24 insertions(+), 5 deletions(-)\n> >\n> > diff --git a/refs.c b/refs.c\n> > index 8df03122d6..61d712ca05 100644\n> > --- a/refs.c\n> > +++ b/refs.c\n> > @@ -562,6 +562,14 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n> >  \t\tstrvec_pushf(prefixes, *p, len, prefix);\n> >  }\n> >\n> > +static const char default_branch_name_advice[] = N_(\n> > +\"Using '%s' as the name for the initial branch. This name is subject\\n\"\n> > +\"to change.\n> This sounds like Git will change the branch name within the user's repo,\n> rather than \"The default\" being subject to change.  So maybe\n> s/This/The default/   ?\n\nYes, that sounds clearer to me. Thank you,\nDscho\n\n>\n> Philip\n>\n> > To configure the name to use as the initial branch name in\\n\"\n> > +\"new repositories, or to silence this warning, run:\\n\"\n> > +\"\\n\"\n> > +\"\\tgit config --global init.defaultBranch <name>\\n\"\n> > +);\n> > +\n> >  char *repo_default_branch_name(struct repository *r, int quiet)\n> >  {\n> >  \tconst char *config_key = \"init.defaultbranch\";\n> > @@ -574,8 +582,11 @@ char *repo_default_branch_name(struct repository *r, int quiet)\n> >  \telse if (repo_config_get_string(r, config_key, &ret) < 0)\n> >  \t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n> >\n> > -\tif (!ret)\n> > +\tif (!ret) {\n> >  \t\tret = xstrdup(\"master\");\n> > +\t\tif (!quiet)\n> > +\t\t\tadvise(_(default_branch_name_advice), ret);\n> > +\t}\n> >\n> >  \tfull_ref = xstrfmt(\"refs/heads/%s\", ret);\n> >  \tif (check_refname_format(full_ref, 0))\n> > diff --git a/t/t0001-init.sh b/t/t0001-init.sh\n> > index 69a320489f..754dab3bab 100755\n> > --- a/t/t0001-init.sh\n> > +++ b/t/t0001-init.sh\n> > @@ -163,7 +163,7 @@ test_expect_success 'reinit' '\n> >  \t(\n> >  \t\tmkdir again &&\n> >  \t\tcd again &&\n> > -\t\tgit init >out1 2>err1 &&\n> > +\t\tgit -c init.defaultBranch=initial init >out1 2>err1 &&\n> >  \t\tgit init >out2 2>err2\n> >  \t) &&\n> >  \ttest_i18ngrep \"Initialized empty\" again/out1 &&\n> > @@ -558,6 +558,13 @@ test_expect_success 'overridden default initial branch name (config)' '\n> >  \tgrep nmb actual\n> >  '\n> >\n> > +test_expect_success 'advice on unconfigured init.defaultBranch' '\n> > +\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git -c color.advice=always \\\n> > +\t\tinit unconfigured-default-branch-name 2>err &&\n> > +\ttest_decode_color <err >decoded &&\n> > +\ttest_i18ngrep \"<YELLOW>hint: \" decoded\n> > +'\n> > +\n> >  test_expect_success 'overridden default main branch name (env)' '\n> >  \ttest_config_global init.defaultBranch nmb &&\n> >  \tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&\n> > diff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh\n> > index 9974457f56..5189a520a2 100755\n> > --- a/t/t1510-repo-setup.sh\n> > +++ b/t/t1510-repo-setup.sh\n> > @@ -79,7 +79,7 @@ setup_repo () {\n> >  \tname=$1 worktreecfg=$2 gitfile=$3 barecfg=$4 &&\n> >  \tsane_unset GIT_DIR GIT_WORK_TREE &&\n> >\n> > -\tgit init \"$name\" &&\n> > +\tgit -c init.defaultBranch=repo init \"$name\" &&\n> >  \tmaybe_config \"$name/.git/config\" core.worktree \"$worktreecfg\" &&\n> >  \tmaybe_config \"$name/.git/config\" core.bare \"$barecfg\" &&\n> >  \tmkdir -p \"$name/sub/sub\" &&\n> > diff --git a/t/t7414-submodule-mistakes.sh b/t/t7414-submodule-mistakes.sh\n> > index f2e7df59cf..0ed02938f9 100755\n> > --- a/t/t7414-submodule-mistakes.sh\n> > +++ b/t/t7414-submodule-mistakes.sh\n> > @@ -30,7 +30,7 @@ test_expect_success 'no warning when updating entry' '\n> >\n> >  test_expect_success 'submodule add does not warn' '\n> >  \ttest_when_finished \"git rm -rf submodule .gitmodules\" &&\n> > -\tgit submodule add ./embed submodule 2>stderr &&\n> > +\tgit -c init.defaultBranch=x submodule add ./embed submodule 2>stderr &&\n> >  \ttest_i18ngrep ! warning stderr\n> >  '\n> >\n> > diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n> > index 59bbf75e83..772152320a 100644\n> > --- a/t/test-lib-functions.sh\n> > +++ b/t/test-lib-functions.sh\n> > @@ -1202,7 +1202,8 @@ test_create_repo () {\n> >  \tmkdir -p \"$repo\"\n> >  \t(\n> >  \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n> > -\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n> > +\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" \\\n> > +\t\t\t-c init.defaultBranch=master init \\\n> >  \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n> >  \t\terror \"cannot run git init -- have you built things yet?\"\n> >  \t\tmv .git/hooks .git/hooks-disabled\n>\n>\n"},{"id":"410570","messageId":"xmqqsg8zn4or.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"nycvar.QRO.7.76.6.2011232136191.56@tvgsbejvaqbjf.bet","subject":"Re: [PATCH 3/3] init: provide useful advice about init.defaultBranch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-23T21:28:36Z","receivedAt":"2020-11-23T21:28:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> Hmm. I would like to believe that readers understand that setting it to\n> _any_ name would suppress this warning.\n\nYes, and the point raised in an earlier messages was that it is not\nclear that there is no recourse for those who do NOT want to choose\nbut still want to suppress.\n\n> It really is much better to make `git branch -m <name>` work in this\n> scenario.\n\nYes, if we can make it work, that is much more preferred.\n"},{"id":"410593","messageId":"483e490349165223a80a0bdf7716c5189560c977.1606173607.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v2.git.git.1606173607.gitgitgadget@gmail.com","subject":"[PATCH v2 1/4] init: document `init.defaultBranch` better","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-23T23:20:04Z","receivedAt":"2020-11-23T23:20:34Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nOur documentation does not mention any future plan to change 'master' to\nother value. It is a good idea to document this, though.\n\nInitial-patch-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/git-init.txt | 11 +++++++----\n 1 file changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\nindex 59ecda6c17..2b399cb73d 100644\n--- a/Documentation/git-init.txt\n+++ b/Documentation/git-init.txt\n@@ -20,8 +20,9 @@ DESCRIPTION\n \n This command creates an empty Git repository - basically a `.git`\n directory with subdirectories for `objects`, `refs/heads`,\n-`refs/tags`, and template files.  An initial `HEAD` file that\n-references the HEAD of the master branch is also created.\n+`refs/tags`, and template files.  An initial branch without any\n+commits will be created (see the `--initial-branch` option below\n+for its name).\n \n If the `$GIT_DIR` environment variable is set then it specifies a path\n to use instead of `./.git` for the base of the repository.\n@@ -73,8 +74,10 @@ If this is reinitialization, the repository will be moved to the specified path.\n -b <branch-name>::\n --initial-branch=<branch-name>::\n \n-Use the specified name for the initial branch in the newly created repository.\n-If not specified, fall back to the default name: `master`.\n+Use the specified name for the initial branch in the newly created\n+repository.  If not specified, fall back to the default name (currently\n+`master`, but that will be changed in the future; the name can be customized\n+via the `init.defaultBranch` configuration variable).\n \n --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::\n \n-- \ngitgitgadget\n\n"},{"id":"410594","messageId":"pull.921.v2.git.git.1606173607.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.git.git.1606087406.gitgitgadget@gmail.com","subject":"[PATCH v2 0/4] Add helpful advice about init.defaultBranch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-23T23:20:03Z","receivedAt":"2020-11-23T23:20:34Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"It is our designated intention\n[https://sfconservancy.org/news/2020/jun/23/gitbranchname/] to \"to explore\nchanging the name of the first branch created automatically for new\nrepositories away from ‘master’\". Further, we promised that we \"will\nminimize disruption for Git's users and will include appropriate deprecation\nperiods\".\n\nTo that end, we first clarify git init's documentation (a lightly edited\nversion of Junio's patch\n[https://lore.kernel.org/git/xmqqd00a36wc.fsf@gitster.c.googlers.com]), and\nthen introduce a message giving advice to users running git init that the\nfall-back for init.defaultBranch is subject to change, and how to override\nGit's fall-back manually.\n\nThe beauty of this patch series, if I may say so, is that it does not commit\nus to any concrete plan, but opens the door for all options regarding the\ndefault branch name.\n\nChanges since v1:\n\n * Grammar fix\n * Reworded advice and commit messages\n * test_create_repo already respected GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME,\n   but now does so more obviously\n * Allowed git branch -m <name> to rename unborn branches, so that the\n   advice actually works\n\nJohannes Schindelin (4):\n  init: document `init.defaultBranch` better\n  branch -m: allow renaming a yet-unborn branch\n  get_default_branch_name(): prepare for showing some advice\n  init: provide useful advice about init.defaultBranch\n\n Documentation/git-init.txt | 11 +++++++----\n builtin/branch.c           |  3 ++-\n builtin/clone.c            |  2 +-\n builtin/init-db.c          |  8 +++++---\n refs.c                     | 25 +++++++++++++++++++++----\n refs.h                     |  4 ++--\n remote.c                   |  5 +++--\n t/t0001-init.sh            | 15 ++++++++++++++-\n t/t1510-repo-setup.sh      |  2 +-\n t/test-lib-functions.sh    |  3 ++-\n 10 files changed, 58 insertions(+), 20 deletions(-)\n\n\nbase-commit: faefdd61ec7c7f6f3c8c9907891465ac9a2a1475\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-921%2Fdscho%2Finit.defaultBranch-advice-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-921/dscho/init.defaultBranch-advice-v2\nPull-Request: https://github.com/git/git/pull/921\n\nRange-diff vs v1:\n\n 1:  1518387eaa ! 1:  483e490349 init: document `init.defaultBranch` better\n     @@ Documentation/git-init.txt: If this is reinitialization, the repository will be\n      -If not specified, fall back to the default name: `master`.\n      +Use the specified name for the initial branch in the newly created\n      +repository.  If not specified, fall back to the default name (currently\n     -+`master`, but that will be changed in the future; The name can be customized\n     ++`master`, but that will be changed in the future; the name can be customized\n      +via the `init.defaultBranch` configuration variable).\n       \n       --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::\n -:  ---------- > 2:  8de0c0eb22 branch -m: allow renaming a yet-unborn branch\n 2:  42f6940043 = 3:  03314f7ac6 get_default_branch_name(): prepare for showing some advice\n 3:  253d6706e6 ! 4:  bccef95391 init: provide useful advice about init.defaultBranch\n     @@ Metadata\n       ## Commit message ##\n          init: provide useful advice about init.defaultBranch\n      \n     -    To give ample warning in case we decide to change the fall-back for an\n     -    unconfigured `init.defaultBranch`, let's introduce some advice that is\n     -    shown upon `git init` when that value is not set.\n     +    To give ample warning for users wishing to override Git's the fall-back\n     +    for an unconfigured `init.defaultBranch` (in case we decide to change it\n     +    in a future Git version), let's introduce some advice that is shown upon\n     +    `git init` when that value is not set.\n      \n     -    Note: three test cases in Git's test suite want to verify that the\n     +    Note: two test cases in Git's test suite want to verify that the\n          `stderr` output of `git init` is empty. With this patch, that is only\n          true if `init.defaultBranch` is configured, so let's do exactly that in\n          those test cases. The same reasoning applies to `test_create_repo()`.\n     @@ refs.c: void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n       }\n       \n      +static const char default_branch_name_advice[] = N_(\n     -+\"Using '%s' as the name for the initial branch. This name is subject\\n\"\n     -+\"to change. To configure the name to use as the initial branch name in\\n\"\n     -+\"new repositories, or to silence this warning, run:\\n\"\n     ++\"Using '%s' as the name for the initial branch. This default branch name\\n\"\n     ++\"is subject to change. To configure the initial branch name to use in all\\n\"\n     ++\"of your new repositories, run:\\n\"\n      +\"\\n\"\n      +\"\\tgit config --global init.defaultBranch <name>\\n\"\n     ++\"\\n\"\n     ++\"Common names are 'main', 'trunk' and 'development'. If you merely wish\\n\"\n     ++\"to suppress this warning, you can also use the current default branch\\n\"\n     ++\"name. The current branch can be renamed via this command:\\n\"\n     ++\"\\n\"\n     ++\"\\tgit branch -m <name>\\n\"\n      +);\n      +\n       char *repo_default_branch_name(struct repository *r, int quiet)\n     @@ t/t1510-repo-setup.sh: setup_repo () {\n       \tmaybe_config \"$name/.git/config\" core.bare \"$barecfg\" &&\n       \tmkdir -p \"$name/sub/sub\" &&\n      \n     - ## t/t7414-submodule-mistakes.sh ##\n     -@@ t/t7414-submodule-mistakes.sh: test_expect_success 'no warning when updating entry' '\n     - \n     - test_expect_success 'submodule add does not warn' '\n     - \ttest_when_finished \"git rm -rf submodule .gitmodules\" &&\n     --\tgit submodule add ./embed submodule 2>stderr &&\n     -+\tgit -c init.defaultBranch=x submodule add ./embed submodule 2>stderr &&\n     - \ttest_i18ngrep ! warning stderr\n     - '\n     - \n     -\n       ## t/test-lib-functions.sh ##\n      @@ t/test-lib-functions.sh: test_create_repo () {\n       \tmkdir -p \"$repo\"\n     @@ t/test-lib-functions.sh: test_create_repo () {\n       \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n      -\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n      +\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" \\\n     -+\t\t\t-c init.defaultBranch=master init \\\n     ++\t\t\t-c init.defaultBranch=${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master} init \\\n       \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n       \t\terror \"cannot run git init -- have you built things yet?\"\n       \t\tmv .git/hooks .git/hooks-disabled\n\n-- \ngitgitgadget\n"},{"id":"410595","messageId":"03314f7ac6ae093d5a685bcbf0ca3d4403d6c5bb.1606173607.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v2.git.git.1606173607.gitgitgadget@gmail.com","subject":"[PATCH v2 3/4] get_default_branch_name(): prepare for showing some advice","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-23T23:20:06Z","receivedAt":"2020-11-23T23:20:34Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nWe are about to introduce a message giving users running `git init` some\nadvice about `init.defaultBranch`. This will necessarily be done in\n`repo_default_branch_name()`.\n\nNot all code paths want to show that advice, though. In particular, the\n`git clone` codepath _specifically_ asks for `init_db()` to be quiet,\nvia the `INIT_DB_QUIET` flag.\n\nIn preparation for showing users above-mentioned advice, let's change\nthe function signature of `get_default_branch_name()` to accept the\nparameter `quiet`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/clone.c   | 2 +-\n builtin/init-db.c | 8 +++++---\n refs.c            | 6 +++---\n refs.h            | 4 ++--\n remote.c          | 5 +++--\n 5 files changed, 14 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex a0841923cf..64b1784011 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -1323,7 +1323,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\tremote_head = NULL;\n \t\toption_no_checkout = 1;\n \t\tif (!option_bare) {\n-\t\t\tconst char *branch = git_default_branch_name();\n+\t\t\tconst char *branch = git_default_branch_name(0);\n \t\t\tchar *ref = xstrfmt(\"refs/heads/%s\", branch);\n \n \t\t\tinstall_branch_config(0, branch, remote_name, ref);\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 01bc648d41..dcc45bef51 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -202,7 +202,8 @@ void initialize_repository_version(int hash_algo, int reinit)\n static int create_default_files(const char *template_path,\n \t\t\t\tconst char *original_git_dir,\n \t\t\t\tconst char *initial_branch,\n-\t\t\t\tconst struct repository_format *fmt)\n+\t\t\t\tconst struct repository_format *fmt,\n+\t\t\t\tint quiet)\n {\n \tstruct stat st1;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -267,7 +268,7 @@ static int create_default_files(const char *template_path,\n \t\tchar *ref;\n \n \t\tif (!initial_branch)\n-\t\t\tinitial_branch = git_default_branch_name();\n+\t\t\tinitial_branch = git_default_branch_name(quiet);\n \n \t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n \t\tif (check_refname_format(ref, 0) < 0)\n@@ -438,7 +439,8 @@ int init_db(const char *git_dir, const char *real_git_dir,\n \tvalidate_hash_algorithm(&repo_fmt, hash);\n \n \treinit = create_default_files(template_dir, original_git_dir,\n-\t\t\t\t      initial_branch, &repo_fmt);\n+\t\t\t\t      initial_branch, &repo_fmt,\n+\t\t\t\t      flags & INIT_DB_QUIET);\n \tif (reinit && initial_branch)\n \t\twarning(_(\"re-init: ignored --initial-branch=%s\"),\n \t\t\tinitial_branch);\ndiff --git a/refs.c b/refs.c\nindex 392f0bbf68..8df03122d6 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -562,7 +562,7 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n \t\tstrvec_pushf(prefixes, *p, len, prefix);\n }\n \n-char *repo_default_branch_name(struct repository *r)\n+char *repo_default_branch_name(struct repository *r, int quiet)\n {\n \tconst char *config_key = \"init.defaultbranch\";\n \tconst char *config_display_key = \"init.defaultBranch\";\n@@ -585,12 +585,12 @@ char *repo_default_branch_name(struct repository *r)\n \treturn ret;\n }\n \n-const char *git_default_branch_name(void)\n+const char *git_default_branch_name(int quiet)\n {\n \tstatic char *ret;\n \n \tif (!ret)\n-\t\tret = repo_default_branch_name(the_repository);\n+\t\tret = repo_default_branch_name(the_repository, quiet);\n \n \treturn ret;\n }\ndiff --git a/refs.h b/refs.h\nindex 6695518156..ff05d2e9fe 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -170,8 +170,8 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n  * The return value of `repo_default_branch_name()` is an allocated string. The\n  * return value of `git_default_branch_name()` is a singleton.\n  */\n-const char *git_default_branch_name(void);\n-char *repo_default_branch_name(struct repository *r);\n+const char *git_default_branch_name(int quiet);\n+char *repo_default_branch_name(struct repository *r, int quiet);\n \n /*\n  * A ref_transaction represents a collection of reference updates that\ndiff --git a/remote.c b/remote.c\nindex 8a6dbbb903..bdb88d4b7d 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -284,7 +284,7 @@ static void read_branches_file(struct remote *remote)\n \tif (frag)\n \t\t*(frag++) = '\\0';\n \telse\n-\t\tfrag = (char *)git_default_branch_name();\n+\t\tfrag = (char *)git_default_branch_name(0);\n \n \tadd_url_alias(remote, strbuf_detach(&buf, NULL));\n \trefspec_appendf(&remote->fetch, \"refs/heads/%s:refs/heads/%s\",\n@@ -2206,7 +2206,8 @@ struct ref *guess_remote_head(const struct ref *head,\n \n \t/* If a remote branch exists with the default branch name, let's use it. */\n \tif (!all) {\n-\t\tchar *ref = xstrfmt(\"refs/heads/%s\", git_default_branch_name());\n+\t\tchar *ref = xstrfmt(\"refs/heads/%s\",\n+\t\t\t\t    git_default_branch_name(0));\n \n \t\tr = find_ref_by_name(refs, ref);\n \t\tfree(ref);\n-- \ngitgitgadget\n\n"},{"id":"410596","messageId":"8de0c0eb228c8d9608d3a78c992cbd6829cb9329.1606173607.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v2.git.git.1606173607.gitgitgadget@gmail.com","subject":"[PATCH v2 2/4] branch -m: allow renaming a yet-unborn branch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-23T23:20:05Z","receivedAt":"2020-11-23T23:20:34Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nIn one of the next commits, we would like to give users some advice\nregarding the initial branch name, and how to modify it.\n\nTo that end, it would be good if `git branch -m <name>` worked in a\nfreshly initialized repository without any commits. Let's make it so.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/branch.c | 3 ++-\n t/t0001-init.sh  | 6 ++++++\n 2 files changed, 8 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex efb30b8820..10609981e6 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -538,7 +538,8 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \t\tstrbuf_addf(&logmsg, \"Branch: renamed %s to %s\",\n \t\t\t    oldref.buf, newref.buf);\n \n-\tif (!copy && rename_ref(oldref.buf, newref.buf, logmsg.buf))\n+\tif (!copy && (oldname != head || !is_null_oid(&head_oid)) &&\n+\t    rename_ref(oldref.buf, newref.buf, logmsg.buf))\n \t\tdie(_(\"Branch rename failed\"));\n \tif (copy && copy_existing_ref(oldref.buf, newref.buf, logmsg.buf))\n \t\tdie(_(\"Branch copy failed\"));\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 69a320489f..69c5ad179c 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -571,4 +571,10 @@ test_expect_success 'invalid default branch name' '\n \ttest_i18ngrep \"invalid branch name\" err\n '\n \n+test_expect_success 'branch -m with the initial branch' '\n+\tgit init rename-initial-branch &&\n+\tgit -C rename-initial-branch branch -m renamed &&\n+\ttest renamed = $(git -C rename-initial-branch symbolic-ref --short HEAD)\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"410597","messageId":"bccef953913da629057b3e9b211bc54081fa4475.1606173607.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v2.git.git.1606173607.gitgitgadget@gmail.com","subject":"[PATCH v2 4/4] init: provide useful advice about init.defaultBranch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-23T23:20:07Z","receivedAt":"2020-11-23T23:20:34Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nTo give ample warning for users wishing to override Git's the fall-back\nfor an unconfigured `init.defaultBranch` (in case we decide to change it\nin a future Git version), let's introduce some advice that is shown upon\n`git init` when that value is not set.\n\nNote: two test cases in Git's test suite want to verify that the\n`stderr` output of `git init` is empty. With this patch, that is only\ntrue if `init.defaultBranch` is configured, so let's do exactly that in\nthose test cases. The same reasoning applies to `test_create_repo()`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n refs.c                  | 19 ++++++++++++++++++-\n t/t0001-init.sh         |  9 ++++++++-\n t/t1510-repo-setup.sh   |  2 +-\n t/test-lib-functions.sh |  3 ++-\n 4 files changed, 29 insertions(+), 4 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 8df03122d6..67275858fc 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -562,6 +562,20 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n \t\tstrvec_pushf(prefixes, *p, len, prefix);\n }\n \n+static const char default_branch_name_advice[] = N_(\n+\"Using '%s' as the name for the initial branch. This default branch name\\n\"\n+\"is subject to change. To configure the initial branch name to use in all\\n\"\n+\"of your new repositories, run:\\n\"\n+\"\\n\"\n+\"\\tgit config --global init.defaultBranch <name>\\n\"\n+\"\\n\"\n+\"Common names are 'main', 'trunk' and 'development'. If you merely wish\\n\"\n+\"to suppress this warning, you can also use the current default branch\\n\"\n+\"name. The current branch can be renamed via this command:\\n\"\n+\"\\n\"\n+\"\\tgit branch -m <name>\\n\"\n+);\n+\n char *repo_default_branch_name(struct repository *r, int quiet)\n {\n \tconst char *config_key = \"init.defaultbranch\";\n@@ -574,8 +588,11 @@ char *repo_default_branch_name(struct repository *r, int quiet)\n \telse if (repo_config_get_string(r, config_key, &ret) < 0)\n \t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n \n-\tif (!ret)\n+\tif (!ret) {\n \t\tret = xstrdup(\"master\");\n+\t\tif (!quiet)\n+\t\t\tadvise(_(default_branch_name_advice), ret);\n+\t}\n \n \tfull_ref = xstrfmt(\"refs/heads/%s\", ret);\n \tif (check_refname_format(full_ref, 0))\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 69c5ad179c..6f693d9609 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -163,7 +163,7 @@ test_expect_success 'reinit' '\n \t(\n \t\tmkdir again &&\n \t\tcd again &&\n-\t\tgit init >out1 2>err1 &&\n+\t\tgit -c init.defaultBranch=initial init >out1 2>err1 &&\n \t\tgit init >out2 2>err2\n \t) &&\n \ttest_i18ngrep \"Initialized empty\" again/out1 &&\n@@ -558,6 +558,13 @@ test_expect_success 'overridden default initial branch name (config)' '\n \tgrep nmb actual\n '\n \n+test_expect_success 'advice on unconfigured init.defaultBranch' '\n+\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git -c color.advice=always \\\n+\t\tinit unconfigured-default-branch-name 2>err &&\n+\ttest_decode_color <err >decoded &&\n+\ttest_i18ngrep \"<YELLOW>hint: \" decoded\n+'\n+\n test_expect_success 'overridden default main branch name (env)' '\n \ttest_config_global init.defaultBranch nmb &&\n \tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&\ndiff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh\nindex 9974457f56..5189a520a2 100755\n--- a/t/t1510-repo-setup.sh\n+++ b/t/t1510-repo-setup.sh\n@@ -79,7 +79,7 @@ setup_repo () {\n \tname=$1 worktreecfg=$2 gitfile=$3 barecfg=$4 &&\n \tsane_unset GIT_DIR GIT_WORK_TREE &&\n \n-\tgit init \"$name\" &&\n+\tgit -c init.defaultBranch=repo init \"$name\" &&\n \tmaybe_config \"$name/.git/config\" core.worktree \"$worktreecfg\" &&\n \tmaybe_config \"$name/.git/config\" core.bare \"$barecfg\" &&\n \tmkdir -p \"$name/sub/sub\" &&\ndiff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\nindex 59bbf75e83..68305a4939 100644\n--- a/t/test-lib-functions.sh\n+++ b/t/test-lib-functions.sh\n@@ -1202,7 +1202,8 @@ test_create_repo () {\n \tmkdir -p \"$repo\"\n \t(\n \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n-\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n+\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" \\\n+\t\t\t-c init.defaultBranch=${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master} init \\\n \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n \t\terror \"cannot run git init -- have you built things yet?\"\n \t\tmv .git/hooks .git/hooks-disabled\n-- \ngitgitgadget\n"},{"id":"410603","messageId":"xmqqd003ljru.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"8de0c0eb228c8d9608d3a78c992cbd6829cb9329.1606173607.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 2/4] branch -m: allow renaming a yet-unborn branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-23T23:45:41Z","receivedAt":"2020-11-23T23:46:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\nwrites:\n\n> @@ -538,7 +538,8 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n>  \t\tstrbuf_addf(&logmsg, \"Branch: renamed %s to %s\",\n>  \t\t\t    oldref.buf, newref.buf);\n>  \n> -\tif (!copy && rename_ref(oldref.buf, newref.buf, logmsg.buf))\n> +\tif (!copy && (oldname != head || !is_null_oid(&head_oid)) &&\n\nIt always makes readers uneasy to see pointer comparison of two\nstrings.  \n\nDoes this mean, after \"git -c init.defaultbranch=master init\",\n\n\tgit branch -m master main\n\nwould not work while\n\n\tgit branch -m main\n\nwould?  It would be easy to see with the attached patch to the test,\nI guess.\n\n> +\t    rename_ref(oldref.buf, newref.buf, logmsg.buf))\n>  \t\tdie(_(\"Branch rename failed\"));\n>  \tif (copy && copy_existing_ref(oldref.buf, newref.buf, logmsg.buf))\n>  \t\tdie(_(\"Branch copy failed\"));\n> diff --git a/t/t0001-init.sh b/t/t0001-init.sh\n> index 69a320489f..69c5ad179c 100755\n> --- a/t/t0001-init.sh\n> +++ b/t/t0001-init.sh\n> @@ -571,4 +571,10 @@ test_expect_success 'invalid default branch name' '\n>  \ttest_i18ngrep \"invalid branch name\" err\n>  '\n>  \n> +test_expect_success 'branch -m with the initial branch' '\n> +\tgit init rename-initial-branch &&\n> +\tgit -C rename-initial-branch branch -m renamed &&\n> +\ttest renamed = $(git -C rename-initial-branch symbolic-ref --short HEAD)\n> +'\n> +\n>  test_done\n\nThanks.\n\n\n t/t0001-init.sh | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git c/t/t0001-init.sh w/t/t0001-init.sh\nindex 69c5ad179c..07c34431d9 100755\n--- c/t/t0001-init.sh\n+++ w/t/t0001-init.sh\n@@ -577,4 +577,10 @@ test_expect_success 'branch -m with the initial branch' '\n \ttest renamed = $(git -C rename-initial-branch symbolic-ref --short HEAD)\n '\n \n+test_expect_success 'branch -m with the initial branch' '\n+\tgit -c init.defaultBranch=initial init rename-unborn-branch &&\n+\tgit -C rename-unborn-branch branch -m initial renamed &&\n+\ttest renamed = $(git -C rename-unborn-branch symbolic-ref --short HEAD)\n+'\n+\n test_done\n"},{"id":"410605","messageId":"xmqq8sarljfn.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"bccef953913da629057b3e9b211bc54081fa4475.1606173607.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 4/4] init: provide useful advice about init.defaultBranch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-23T23:53:00Z","receivedAt":"2020-11-23T23:53:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\nwrites:\n\n> +static const char default_branch_name_advice[] = N_(\n> +\"Using '%s' as the name for the initial branch. This default branch name\\n\"\n> +\"is subject to change. To configure the initial branch name to use in all\\n\"\n> +\"of your new repositories, run:\\n\"\n\nI think this is good, assuming that \"subject to change\" covers the\ncase where we end up doing nothing after all.  I'd feel safer if we\nsaid \"s/is subject to change/may change in the future/\", but this is\nnot a strong preference.\n\n> +\"\\n\"\n> +\"\\tgit config --global init.defaultBranch <name>\\n\"\n> +\"\\n\"\n> +\"Common names are 'main', 'trunk' and 'development'. If you merely wish\\n\"\n> +\"to suppress this warning, you can also use the current default branch\\n\"\n> +\"name. The current branch can be renamed via this command:\\n\"\n\nI think this is worse than the previous one.  Those who merely wish\nto suppress the message without wanting to commit to a particular\nname (i.e. they just want to take whatever the default we give them)\nwould be mislead and be frozen in time forever.  We do not give\n\"I'll just accept the default of the day\" choice, and that is OK,\nbut we want to be clear about it, which is why I've kept raising this\nas an issue.\n\n    To configure the initial branch name to use in all of your new\n    repositories and squelch this message, run:\n\nmay be better---it makes it clear that the offered two choices are\n(1) do nothing and see this message every time, or (2) commit to a\nname and not see this message again.\n\nThanks.\n"},{"id":"410648","messageId":"nycvar.QRO.7.76.6.2011240551050.56@tvgsbejvaqbjf.bet","threadId":"54691","inReplyTo":"xmqqd003ljru.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v2 2/4] branch -m: allow renaming a yet-unborn branch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-11-24T05:47:20Z","receivedAt":"2020-11-24T09:59:53Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\n\nOn Mon, 23 Nov 2020, Junio C Hamano wrote:\n\n> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> > @@ -538,7 +538,8 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n> >  \t\tstrbuf_addf(&logmsg, \"Branch: renamed %s to %s\",\n> >  \t\t\t    oldref.buf, newref.buf);\n> >\n> > -\tif (!copy && rename_ref(oldref.buf, newref.buf, logmsg.buf))\n> > +\tif (!copy && (oldname != head || !is_null_oid(&head_oid)) &&\n>\n> It always makes readers uneasy to see pointer comparison of two\n> strings.\n\nEven if it was on purpose ;-)\n\n> Does this mean, after \"git -c init.defaultbranch=master init\",\n>\n> \tgit branch -m master main\n>\n> would not work while\n>\n> \tgit branch -m main\n>\n> would?  It would be easy to see with the attached patch to the test,\n> I guess.\n\nAt first, I thought that it would be inappropriate to do that because it\nwould not work with unborn branches in a worktree other than the current\none. Like,\n\n\tgit worktree add --no-checkout --detach other\n\tgit -C other switch --orphan start-over-again\n\tgit branch -m start-over-again fresh-new-start\n\nOn second thought, that's a really obscure use case, anyway. It is not\neven possible to create a secondary worktree! I started down that rabbit\nhole, but think I'd better let it be. This is where I stopped:\n\n-- snip --\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 200da319f1d..c84bffe9632 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -489,6 +489,16 @@ static void reject_rebase_or_bisect_branch(const char *target)\n \tfree_worktrees(worktrees);\n }\n\n+static int is_unborn_branch(const char *branch_name, const char *full_ref_name)\n+{\n+\tint flags;\n+\n+\treturn (head && !strcmp(branch_name, head) && is_null_oid(&head_oid)) ||\n+\t\t(!resolve_ref_unsafe(full_ref_name, RESOLVE_REF_READING, NULL,\n+\t\t\t\t     &flags) &&\n+\t\t find_shared_symref(\"HEAD\", full_ref));\n+}\n+\n static void copy_or_rename_branch(const char *oldname, const char *newname, int copy, int force)\n {\n \tstruct strbuf oldref = STRBUF_INIT, newref = STRBUF_INIT, logmsg = STRBUF_INIT;\n@@ -538,8 +548,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \t\tstrbuf_addf(&logmsg, \"Branch: renamed %s to %s\",\n \t\t\t    oldref.buf, newref.buf);\n\n-\tif (!copy &&\n-\t    (!head || strcmp(oldname, head) || !is_null_oid(&head_oid)) &&\n+\tif (!copy && !is_unborn_branch(oldname, oldref.buf) &&\n \t    rename_ref(oldref.buf, newref.buf, logmsg.buf))\n \t\tdie(_(\"Branch rename failed\"));\n \tif (copy && copy_existing_ref(oldref.buf, newref.buf, logmsg.buf))\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 84047ac64e6..124abeedf19 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -586,4 +586,12 @@ test_expect_success 'branch -m with the initial branch' '\n \ttest again = $(git -C rename-initial symbolic-ref --short HEAD)\n '\n\n+test_expect_success 'branch -m with the initial branch in another worktree' '\n+\tgit -c init.defaultBranch=initial init rename-two &&\n+\ttest_commit -C rename-two initial &&\n+\tgit -C rename-two worktree add --no-checkout ../rename-worktree &&\n+\tgit -C rename-worktree switch --orphan brand-new-day &&\n+\tgit -C rename-two branch -m brand-new-day renamed\n+'\n+\n test_done\n-- snap --\n\nHaving said that, I fixed the `git branch -m <current-unborn> <new-name>`\nuse case; the fix will be part of v3.\n\nCiao,\nDscho\n"},{"id":"410649","messageId":"nycvar.QRO.7.76.6.2011240648160.56@tvgsbejvaqbjf.bet","threadId":"54691","inReplyTo":"xmqq8sarljfn.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v2 4/4] init: provide useful advice about init.defaultBranch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-11-24T05:57:16Z","receivedAt":"2020-11-24T10:09:34Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Mon, 23 Nov 2020, Junio C Hamano wrote:\n\n> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> > +static const char default_branch_name_advice[] = N_(\n> > +\"Using '%s' as the name for the initial branch. This default branch name\\n\"\n> > +\"is subject to change. To configure the initial branch name to use in all\\n\"\n> > +\"of your new repositories, run:\\n\"\n>\n> I think this is good, assuming that \"subject to change\" covers the\n> case where we end up doing nothing after all.  I'd feel safer if we\n> said \"s/is subject to change/may change in the future/\", but this is\n> not a strong preference.\n\nI'd rather keep the current form, as it sounds a bit more firm to me.\n\n> > +\"\\n\"\n> > +\"\\tgit config --global init.defaultBranch <name>\\n\"\n> > +\"\\n\"\n> > +\"Common names are 'main', 'trunk' and 'development'. If you merely wish\\n\"\n> > +\"to suppress this warning, you can also use the current default branch\\n\"\n> > +\"name. The current branch can be renamed via this command:\\n\"\n>\n> I think this is worse than the previous one.  Those who merely wish\n> to suppress the message without wanting to commit to a particular\n> name (i.e. they just want to take whatever the default we give them)\n> would be mislead and be frozen in time forever.  We do not give\n> \"I'll just accept the default of the day\" choice, and that is OK,\n> but we want to be clear about it, which is why I've kept raising this\n> as an issue.\n>\n>     To configure the initial branch name to use in all of your new\n>     repositories and squelch this message, run:\n>\n> may be better---it makes it clear that the offered two choices are\n> (1) do nothing and see this message every time, or (2) commit to a\n> name and not see this message again.\n\nWell, I think I finally understand what you are saying: there is a\nlegitimate need for a way to go with Git's preference but still suppress\nthat message.\n\nI introduced `advice.defaultBranchName` to that end, and now display\nprominently, at the top of the message, how to use that flag to avoid\nseeing this advice ever again.\n\nCiao,\nDscho\n"},{"id":"410680","messageId":"483e490349165223a80a0bdf7716c5189560c977.1606230450.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v3.git.git.1606230450.gitgitgadget@gmail.com","subject":"[PATCH v3 1/4] init: document `init.defaultBranch` better","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-24T15:07:26Z","receivedAt":"2020-11-24T15:08:03Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nOur documentation does not mention any future plan to change 'master' to\nother value. It is a good idea to document this, though.\n\nInitial-patch-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/git-init.txt | 11 +++++++----\n 1 file changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\nindex 59ecda6c17..2b399cb73d 100644\n--- a/Documentation/git-init.txt\n+++ b/Documentation/git-init.txt\n@@ -20,8 +20,9 @@ DESCRIPTION\n \n This command creates an empty Git repository - basically a `.git`\n directory with subdirectories for `objects`, `refs/heads`,\n-`refs/tags`, and template files.  An initial `HEAD` file that\n-references the HEAD of the master branch is also created.\n+`refs/tags`, and template files.  An initial branch without any\n+commits will be created (see the `--initial-branch` option below\n+for its name).\n \n If the `$GIT_DIR` environment variable is set then it specifies a path\n to use instead of `./.git` for the base of the repository.\n@@ -73,8 +74,10 @@ If this is reinitialization, the repository will be moved to the specified path.\n -b <branch-name>::\n --initial-branch=<branch-name>::\n \n-Use the specified name for the initial branch in the newly created repository.\n-If not specified, fall back to the default name: `master`.\n+Use the specified name for the initial branch in the newly created\n+repository.  If not specified, fall back to the default name (currently\n+`master`, but that will be changed in the future; the name can be customized\n+via the `init.defaultBranch` configuration variable).\n \n --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::\n \n-- \ngitgitgadget\n\n"},{"id":"410681","messageId":"pull.921.v3.git.git.1606230450.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v2.git.git.1606173607.gitgitgadget@gmail.com","subject":"[PATCH v3 0/4] Add helpful advice about init.defaultBranch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-24T15:07:25Z","receivedAt":"2020-11-24T15:08:04Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"It is our designated intention\n[https://sfconservancy.org/news/2020/jun/23/gitbranchname/] to \"to explore\nchanging the name of the first branch created automatically for new\nrepositories away from ‘master’\". Further, we promised that we \"will\nminimize disruption for Git's users and will include appropriate deprecation\nperiods\".\n\nTo that end, we first clarify git init's documentation (a lightly edited\nversion of Junio's patch\n[https://lore.kernel.org/git/xmqqd00a36wc.fsf@gitster.c.googlers.com]), and\nthen introduce a message giving advice to users running git init that the\nfall-back for init.defaultBranch is subject to change, and how to override\nGit's fall-back manually.\n\nThe beauty of this patch series, if I may say so, is that it does not commit\nus to any concrete plan, but opens the door for all options regarding the\ndefault branch name.\n\nChanges since v2:\n\n * git branch -m <initial> <renamed> now works, too\n * The config setting advice.defaultBranchName was introduced to allow\n   suppressing this warning specifically\n * The advice now first talks about the current default branch name, then\n   how to suppress the advice, and only then explains how to override the\n   default branch name (and that that will also prevent the message from\n   being shown)\n\nChanges since v1:\n\n * Grammar fix\n * Reworded advice and commit messages\n * test_create_repo already respected GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME,\n   but now does so more obviously\n * Allowed git branch -m <name> to rename unborn branches, so that the\n   advice actually works\n\nJohannes Schindelin (4):\n  init: document `init.defaultBranch` better\n  branch -m: allow renaming a yet-unborn branch\n  get_default_branch_name(): prepare for showing some advice\n  init: provide useful advice about init.defaultBranch\n\n Documentation/git-init.txt | 11 +++++++----\n advice.c                   |  1 +\n advice.h                   |  1 +\n builtin/branch.c           |  4 +++-\n builtin/clone.c            |  2 +-\n builtin/init-db.c          |  8 +++++---\n refs.c                     | 29 +++++++++++++++++++++++++----\n refs.h                     |  4 ++--\n remote.c                   |  5 +++--\n t/t0001-init.sh            | 17 ++++++++++++++++-\n t/t1510-repo-setup.sh      |  2 +-\n t/test-lib-functions.sh    |  3 ++-\n 12 files changed, 67 insertions(+), 20 deletions(-)\n\n\nbase-commit: faefdd61ec7c7f6f3c8c9907891465ac9a2a1475\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-921%2Fdscho%2Finit.defaultBranch-advice-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-921/dscho/init.defaultBranch-advice-v3\nPull-Request: https://github.com/git/git/pull/921\n\nRange-diff vs v2:\n\n 1:  483e490349 = 1:  483e490349 init: document `init.defaultBranch` better\n 2:  8de0c0eb22 ! 2:  6cbd6692c6 branch -m: allow renaming a yet-unborn branch\n     @@ builtin/branch.c: static void copy_or_rename_branch(const char *oldname, const c\n       \t\t\t    oldref.buf, newref.buf);\n       \n      -\tif (!copy && rename_ref(oldref.buf, newref.buf, logmsg.buf))\n     -+\tif (!copy && (oldname != head || !is_null_oid(&head_oid)) &&\n     ++\tif (!copy &&\n     ++\t    (!head || strcmp(oldname, head) || !is_null_oid(&head_oid)) &&\n      +\t    rename_ref(oldref.buf, newref.buf, logmsg.buf))\n       \t\tdie(_(\"Branch rename failed\"));\n       \tif (copy && copy_existing_ref(oldref.buf, newref.buf, logmsg.buf))\n     @@ t/t0001-init.sh: test_expect_success 'invalid default branch name' '\n       '\n       \n      +test_expect_success 'branch -m with the initial branch' '\n     -+\tgit init rename-initial-branch &&\n     -+\tgit -C rename-initial-branch branch -m renamed &&\n     -+\ttest renamed = $(git -C rename-initial-branch symbolic-ref --short HEAD)\n     ++\tgit init rename-initial &&\n     ++\tgit -C rename-initial branch -m renamed &&\n     ++\ttest renamed = $(git -C rename-initial symbolic-ref --short HEAD) &&\n     ++\tgit -C rename-initial branch -m renamed again &&\n     ++\ttest again = $(git -C rename-initial symbolic-ref --short HEAD)\n      +'\n      +\n       test_done\n 3:  03314f7ac6 = 3:  5fc15f7b9a get_default_branch_name(): prepare for showing some advice\n 4:  bccef95391 ! 4:  87c9306877 init: provide useful advice about init.defaultBranch\n     @@ Commit message\n          `git init` when that value is not set.\n      \n          Note: two test cases in Git's test suite want to verify that the\n     -    `stderr` output of `git init` is empty. With this patch, that is only\n     -    true if `init.defaultBranch` is configured, so let's do exactly that in\n     -    those test cases. The same reasoning applies to `test_create_repo()`.\n     +    `stderr` output of `git init` is empty. It is now necessary to suppress\n     +    the advice using the newly-added `advice.defaultBranchName` setting.\n     +    While not strictly necessary, we also set this to `false` in\n     +    `test_create_repo()`.\n      \n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n     + ## advice.c ##\n     +@@ advice.c: static struct {\n     + \t[ADVICE_AM_WORK_DIR] \t\t\t\t= { \"amWorkDir\", 1 },\n     + \t[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] \t= { \"checkoutAmbiguousRemoteBranchName\", 1 },\n     + \t[ADVICE_COMMIT_BEFORE_MERGE]\t\t\t= { \"commitBeforeMerge\", 1 },\n     ++\t[ADVICE_DEFAULT_BRANCH_NAME]\t\t\t= { \"defaultBranchName\", 1 },\n     + \t[ADVICE_DETACHED_HEAD]\t\t\t\t= { \"detachedHead\", 1 },\n     + \t[ADVICE_FETCH_SHOW_FORCED_UPDATES]\t\t= { \"fetchShowForcedUpdates\", 1 },\n     + \t[ADVICE_GRAFT_FILE_DEPRECATED]\t\t\t= { \"graftFileDeprecated\", 1 },\n     +\n     + ## advice.h ##\n     +@@ advice.h: extern int advice_add_empty_pathspec;\n     + \tADVICE_AM_WORK_DIR,\n     + \tADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,\n     + \tADVICE_COMMIT_BEFORE_MERGE,\n     ++\tADVICE_DEFAULT_BRANCH_NAME,\n     + \tADVICE_DETACHED_HEAD,\n     + \tADVICE_FETCH_SHOW_FORCED_UPDATES,\n     + \tADVICE_GRAFT_FILE_DEPRECATED,\n     +\n       ## refs.c ##\n     +@@\n     + #include \"strvec.h\"\n     + #include \"repository.h\"\n     + #include \"sigchain.h\"\n     ++#include \"advice.h\"\n     + \n     + /*\n     +  * List of all available backends\n      @@ refs.c: void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n       \t\tstrvec_pushf(prefixes, *p, len, prefix);\n       }\n       \n      +static const char default_branch_name_advice[] = N_(\n      +\"Using '%s' as the name for the initial branch. This default branch name\\n\"\n     -+\"is subject to change. To configure the initial branch name to use in all\\n\"\n     -+\"of your new repositories, run:\\n\"\n     ++\"is subject to change. To suppress this warning, run:\\n\"\n     ++\"\\n\"\n     ++\"\\tgit config --global advice.defaultBranchName false\\n\"\n     ++\"\\n\"\n     ++\"Alternatively, you can configure the initial branch name to use in all\\n\"\n     ++\"of your new repositories, which will also suppress this warning:\\n\"\n      +\"\\n\"\n      +\"\\tgit config --global init.defaultBranch <name>\\n\"\n      +\"\\n\"\n     -+\"Common names are 'main', 'trunk' and 'development'. If you merely wish\\n\"\n     -+\"to suppress this warning, you can also use the current default branch\\n\"\n     -+\"name. The current branch can be renamed via this command:\\n\"\n     ++\"Common names are 'main', 'trunk' and 'development'. The initial branch\\n\"\n     ++\"that was created can be renamed via this command:\\n\"\n      +\"\\n\"\n      +\"\\tgit branch -m <name>\\n\"\n      +);\n     @@ refs.c: char *repo_default_branch_name(struct repository *r, int quiet)\n      -\tif (!ret)\n      +\tif (!ret) {\n       \t\tret = xstrdup(\"master\");\n     -+\t\tif (!quiet)\n     ++\t\tif (!quiet && advice_enabled(ADVICE_DEFAULT_BRANCH_NAME))\n      +\t\t\tadvise(_(default_branch_name_advice), ret);\n      +\t}\n       \n     @@ t/t0001-init.sh: test_expect_success 'reinit' '\n       \t\tmkdir again &&\n       \t\tcd again &&\n      -\t\tgit init >out1 2>err1 &&\n     -+\t\tgit -c init.defaultBranch=initial init >out1 2>err1 &&\n     ++\t\tgit -c advice.defaultBranchName=false init >out1 2>err1 &&\n       \t\tgit init >out2 2>err2\n       \t) &&\n       \ttest_i18ngrep \"Initialized empty\" again/out1 &&\n     @@ t/t1510-repo-setup.sh: setup_repo () {\n       \tsane_unset GIT_DIR GIT_WORK_TREE &&\n       \n      -\tgit init \"$name\" &&\n     -+\tgit -c init.defaultBranch=repo init \"$name\" &&\n     ++\tgit -c advice.defaultBranchName=false init \"$name\" &&\n       \tmaybe_config \"$name/.git/config\" core.worktree \"$worktreecfg\" &&\n       \tmaybe_config \"$name/.git/config\" core.bare \"$barecfg\" &&\n       \tmkdir -p \"$name/sub/sub\" &&\n     @@ t/test-lib-functions.sh: test_create_repo () {\n       \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n      -\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n      +\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" \\\n     -+\t\t\t-c init.defaultBranch=${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master} init \\\n     ++\t\t\t-c advice.defaultBranchName=false init \\\n       \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n       \t\terror \"cannot run git init -- have you built things yet?\"\n       \t\tmv .git/hooks .git/hooks-disabled\n\n-- \ngitgitgadget\n"},{"id":"410682","messageId":"87c93068771238a65d0753cc41261c2a97ca4fd9.1606230450.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v3.git.git.1606230450.gitgitgadget@gmail.com","subject":"[PATCH v3 4/4] init: provide useful advice about init.defaultBranch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-24T15:07:29Z","receivedAt":"2020-11-24T15:08:04Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nTo give ample warning for users wishing to override Git's the fall-back\nfor an unconfigured `init.defaultBranch` (in case we decide to change it\nin a future Git version), let's introduce some advice that is shown upon\n`git init` when that value is not set.\n\nNote: two test cases in Git's test suite want to verify that the\n`stderr` output of `git init` is empty. It is now necessary to suppress\nthe advice using the newly-added `advice.defaultBranchName` setting.\nWhile not strictly necessary, we also set this to `false` in\n`test_create_repo()`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n advice.c                |  1 +\n advice.h                |  1 +\n refs.c                  | 23 ++++++++++++++++++++++-\n t/t0001-init.sh         |  9 ++++++++-\n t/t1510-repo-setup.sh   |  2 +-\n t/test-lib-functions.sh |  3 ++-\n 6 files changed, 35 insertions(+), 4 deletions(-)\n\ndiff --git a/advice.c b/advice.c\nindex 164742305f..8a14640193 100644\n--- a/advice.c\n+++ b/advice.c\n@@ -108,6 +108,7 @@ static struct {\n \t[ADVICE_AM_WORK_DIR] \t\t\t\t= { \"amWorkDir\", 1 },\n \t[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] \t= { \"checkoutAmbiguousRemoteBranchName\", 1 },\n \t[ADVICE_COMMIT_BEFORE_MERGE]\t\t\t= { \"commitBeforeMerge\", 1 },\n+\t[ADVICE_DEFAULT_BRANCH_NAME]\t\t\t= { \"defaultBranchName\", 1 },\n \t[ADVICE_DETACHED_HEAD]\t\t\t\t= { \"detachedHead\", 1 },\n \t[ADVICE_FETCH_SHOW_FORCED_UPDATES]\t\t= { \"fetchShowForcedUpdates\", 1 },\n \t[ADVICE_GRAFT_FILE_DEPRECATED]\t\t\t= { \"graftFileDeprecated\", 1 },\ndiff --git a/advice.h b/advice.h\nindex bc2432980a..1ae99a1b31 100644\n--- a/advice.h\n+++ b/advice.h\n@@ -46,6 +46,7 @@ extern int advice_add_empty_pathspec;\n \tADVICE_AM_WORK_DIR,\n \tADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,\n \tADVICE_COMMIT_BEFORE_MERGE,\n+\tADVICE_DEFAULT_BRANCH_NAME,\n \tADVICE_DETACHED_HEAD,\n \tADVICE_FETCH_SHOW_FORCED_UPDATES,\n \tADVICE_GRAFT_FILE_DEPRECATED,\ndiff --git a/refs.c b/refs.c\nindex 8df03122d6..c56bc1bcfb 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -18,6 +18,7 @@\n #include \"strvec.h\"\n #include \"repository.h\"\n #include \"sigchain.h\"\n+#include \"advice.h\"\n \n /*\n  * List of all available backends\n@@ -562,6 +563,23 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n \t\tstrvec_pushf(prefixes, *p, len, prefix);\n }\n \n+static const char default_branch_name_advice[] = N_(\n+\"Using '%s' as the name for the initial branch. This default branch name\\n\"\n+\"is subject to change. To suppress this warning, run:\\n\"\n+\"\\n\"\n+\"\\tgit config --global advice.defaultBranchName false\\n\"\n+\"\\n\"\n+\"Alternatively, you can configure the initial branch name to use in all\\n\"\n+\"of your new repositories, which will also suppress this warning:\\n\"\n+\"\\n\"\n+\"\\tgit config --global init.defaultBranch <name>\\n\"\n+\"\\n\"\n+\"Common names are 'main', 'trunk' and 'development'. The initial branch\\n\"\n+\"that was created can be renamed via this command:\\n\"\n+\"\\n\"\n+\"\\tgit branch -m <name>\\n\"\n+);\n+\n char *repo_default_branch_name(struct repository *r, int quiet)\n {\n \tconst char *config_key = \"init.defaultbranch\";\n@@ -574,8 +592,11 @@ char *repo_default_branch_name(struct repository *r, int quiet)\n \telse if (repo_config_get_string(r, config_key, &ret) < 0)\n \t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n \n-\tif (!ret)\n+\tif (!ret) {\n \t\tret = xstrdup(\"master\");\n+\t\tif (!quiet && advice_enabled(ADVICE_DEFAULT_BRANCH_NAME))\n+\t\t\tadvise(_(default_branch_name_advice), ret);\n+\t}\n \n \tfull_ref = xstrfmt(\"refs/heads/%s\", ret);\n \tif (check_refname_format(full_ref, 0))\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex bb23e56a16..84047ac64e 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -163,7 +163,7 @@ test_expect_success 'reinit' '\n \t(\n \t\tmkdir again &&\n \t\tcd again &&\n-\t\tgit init >out1 2>err1 &&\n+\t\tgit -c advice.defaultBranchName=false init >out1 2>err1 &&\n \t\tgit init >out2 2>err2\n \t) &&\n \ttest_i18ngrep \"Initialized empty\" again/out1 &&\n@@ -558,6 +558,13 @@ test_expect_success 'overridden default initial branch name (config)' '\n \tgrep nmb actual\n '\n \n+test_expect_success 'advice on unconfigured init.defaultBranch' '\n+\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git -c color.advice=always \\\n+\t\tinit unconfigured-default-branch-name 2>err &&\n+\ttest_decode_color <err >decoded &&\n+\ttest_i18ngrep \"<YELLOW>hint: \" decoded\n+'\n+\n test_expect_success 'overridden default main branch name (env)' '\n \ttest_config_global init.defaultBranch nmb &&\n \tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&\ndiff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh\nindex 9974457f56..5305566167 100755\n--- a/t/t1510-repo-setup.sh\n+++ b/t/t1510-repo-setup.sh\n@@ -79,7 +79,7 @@ setup_repo () {\n \tname=$1 worktreecfg=$2 gitfile=$3 barecfg=$4 &&\n \tsane_unset GIT_DIR GIT_WORK_TREE &&\n \n-\tgit init \"$name\" &&\n+\tgit -c advice.defaultBranchName=false init \"$name\" &&\n \tmaybe_config \"$name/.git/config\" core.worktree \"$worktreecfg\" &&\n \tmaybe_config \"$name/.git/config\" core.bare \"$barecfg\" &&\n \tmkdir -p \"$name/sub/sub\" &&\ndiff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\nindex 59bbf75e83..781d47a4bb 100644\n--- a/t/test-lib-functions.sh\n+++ b/t/test-lib-functions.sh\n@@ -1202,7 +1202,8 @@ test_create_repo () {\n \tmkdir -p \"$repo\"\n \t(\n \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n-\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n+\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" \\\n+\t\t\t-c advice.defaultBranchName=false init \\\n \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n \t\terror \"cannot run git init -- have you built things yet?\"\n \t\tmv .git/hooks .git/hooks-disabled\n-- \ngitgitgadget\n"},{"id":"410684","messageId":"6cbd6692c6a4d0586e3418225029e70b0001ffb1.1606230450.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v3.git.git.1606230450.gitgitgadget@gmail.com","subject":"[PATCH v3 2/4] branch -m: allow renaming a yet-unborn branch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-24T15:07:27Z","receivedAt":"2020-11-24T15:08:04Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nIn one of the next commits, we would like to give users some advice\nregarding the initial branch name, and how to modify it.\n\nTo that end, it would be good if `git branch -m <name>` worked in a\nfreshly initialized repository without any commits. Let's make it so.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/branch.c | 4 +++-\n t/t0001-init.sh  | 8 ++++++++\n 2 files changed, 11 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex efb30b8820..200da319f1 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -538,7 +538,9 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \t\tstrbuf_addf(&logmsg, \"Branch: renamed %s to %s\",\n \t\t\t    oldref.buf, newref.buf);\n \n-\tif (!copy && rename_ref(oldref.buf, newref.buf, logmsg.buf))\n+\tif (!copy &&\n+\t    (!head || strcmp(oldname, head) || !is_null_oid(&head_oid)) &&\n+\t    rename_ref(oldref.buf, newref.buf, logmsg.buf))\n \t\tdie(_(\"Branch rename failed\"));\n \tif (copy && copy_existing_ref(oldref.buf, newref.buf, logmsg.buf))\n \t\tdie(_(\"Branch copy failed\"));\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 69a320489f..bb23e56a16 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -571,4 +571,12 @@ test_expect_success 'invalid default branch name' '\n \ttest_i18ngrep \"invalid branch name\" err\n '\n \n+test_expect_success 'branch -m with the initial branch' '\n+\tgit init rename-initial &&\n+\tgit -C rename-initial branch -m renamed &&\n+\ttest renamed = $(git -C rename-initial symbolic-ref --short HEAD) &&\n+\tgit -C rename-initial branch -m renamed again &&\n+\ttest again = $(git -C rename-initial symbolic-ref --short HEAD)\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"410683","messageId":"5fc15f7b9adaf64c2fbfd58f6e96768f5b9d7f8b.1606230450.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v3.git.git.1606230450.gitgitgadget@gmail.com","subject":"[PATCH v3 3/4] get_default_branch_name(): prepare for showing some advice","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-11-24T15:07:28Z","receivedAt":"2020-11-24T15:08:05Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nWe are about to introduce a message giving users running `git init` some\nadvice about `init.defaultBranch`. This will necessarily be done in\n`repo_default_branch_name()`.\n\nNot all code paths want to show that advice, though. In particular, the\n`git clone` codepath _specifically_ asks for `init_db()` to be quiet,\nvia the `INIT_DB_QUIET` flag.\n\nIn preparation for showing users above-mentioned advice, let's change\nthe function signature of `get_default_branch_name()` to accept the\nparameter `quiet`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/clone.c   | 2 +-\n builtin/init-db.c | 8 +++++---\n refs.c            | 6 +++---\n refs.h            | 4 ++--\n remote.c          | 5 +++--\n 5 files changed, 14 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex a0841923cf..64b1784011 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -1323,7 +1323,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\tremote_head = NULL;\n \t\toption_no_checkout = 1;\n \t\tif (!option_bare) {\n-\t\t\tconst char *branch = git_default_branch_name();\n+\t\t\tconst char *branch = git_default_branch_name(0);\n \t\t\tchar *ref = xstrfmt(\"refs/heads/%s\", branch);\n \n \t\t\tinstall_branch_config(0, branch, remote_name, ref);\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 01bc648d41..dcc45bef51 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -202,7 +202,8 @@ void initialize_repository_version(int hash_algo, int reinit)\n static int create_default_files(const char *template_path,\n \t\t\t\tconst char *original_git_dir,\n \t\t\t\tconst char *initial_branch,\n-\t\t\t\tconst struct repository_format *fmt)\n+\t\t\t\tconst struct repository_format *fmt,\n+\t\t\t\tint quiet)\n {\n \tstruct stat st1;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -267,7 +268,7 @@ static int create_default_files(const char *template_path,\n \t\tchar *ref;\n \n \t\tif (!initial_branch)\n-\t\t\tinitial_branch = git_default_branch_name();\n+\t\t\tinitial_branch = git_default_branch_name(quiet);\n \n \t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n \t\tif (check_refname_format(ref, 0) < 0)\n@@ -438,7 +439,8 @@ int init_db(const char *git_dir, const char *real_git_dir,\n \tvalidate_hash_algorithm(&repo_fmt, hash);\n \n \treinit = create_default_files(template_dir, original_git_dir,\n-\t\t\t\t      initial_branch, &repo_fmt);\n+\t\t\t\t      initial_branch, &repo_fmt,\n+\t\t\t\t      flags & INIT_DB_QUIET);\n \tif (reinit && initial_branch)\n \t\twarning(_(\"re-init: ignored --initial-branch=%s\"),\n \t\t\tinitial_branch);\ndiff --git a/refs.c b/refs.c\nindex 392f0bbf68..8df03122d6 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -562,7 +562,7 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n \t\tstrvec_pushf(prefixes, *p, len, prefix);\n }\n \n-char *repo_default_branch_name(struct repository *r)\n+char *repo_default_branch_name(struct repository *r, int quiet)\n {\n \tconst char *config_key = \"init.defaultbranch\";\n \tconst char *config_display_key = \"init.defaultBranch\";\n@@ -585,12 +585,12 @@ char *repo_default_branch_name(struct repository *r)\n \treturn ret;\n }\n \n-const char *git_default_branch_name(void)\n+const char *git_default_branch_name(int quiet)\n {\n \tstatic char *ret;\n \n \tif (!ret)\n-\t\tret = repo_default_branch_name(the_repository);\n+\t\tret = repo_default_branch_name(the_repository, quiet);\n \n \treturn ret;\n }\ndiff --git a/refs.h b/refs.h\nindex 6695518156..ff05d2e9fe 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -170,8 +170,8 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n  * The return value of `repo_default_branch_name()` is an allocated string. The\n  * return value of `git_default_branch_name()` is a singleton.\n  */\n-const char *git_default_branch_name(void);\n-char *repo_default_branch_name(struct repository *r);\n+const char *git_default_branch_name(int quiet);\n+char *repo_default_branch_name(struct repository *r, int quiet);\n \n /*\n  * A ref_transaction represents a collection of reference updates that\ndiff --git a/remote.c b/remote.c\nindex 8a6dbbb903..bdb88d4b7d 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -284,7 +284,7 @@ static void read_branches_file(struct remote *remote)\n \tif (frag)\n \t\t*(frag++) = '\\0';\n \telse\n-\t\tfrag = (char *)git_default_branch_name();\n+\t\tfrag = (char *)git_default_branch_name(0);\n \n \tadd_url_alias(remote, strbuf_detach(&buf, NULL));\n \trefspec_appendf(&remote->fetch, \"refs/heads/%s:refs/heads/%s\",\n@@ -2206,7 +2206,8 @@ struct ref *guess_remote_head(const struct ref *head,\n \n \t/* If a remote branch exists with the default branch name, let's use it. */\n \tif (!all) {\n-\t\tchar *ref = xstrfmt(\"refs/heads/%s\", git_default_branch_name());\n+\t\tchar *ref = xstrfmt(\"refs/heads/%s\",\n+\t\t\t\t    git_default_branch_name(0));\n \n \t\tr = find_ref_by_name(refs, ref);\n \t\tfree(ref);\n-- \ngitgitgadget\n\n"},{"id":"410702","messageId":"xmqqd002jyvu.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"nycvar.QRO.7.76.6.2011240551050.56@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v2 2/4] branch -m: allow renaming a yet-unborn branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-24T20:14:29Z","receivedAt":"2020-11-24T20:14:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n>> > -\tif (!copy && rename_ref(oldref.buf, newref.buf, logmsg.buf))\n>> > +\tif (!copy && (oldname != head || !is_null_oid(&head_oid)) &&\n>>\n>> It always makes readers uneasy to see pointer comparison of two\n>> strings.\n>\n> Even if it was on purpose ;-)\n\nFWIW, for fun I dropped \"oldname != head ||\" and tried to run the\nwhole testsuite (plus the \"branch -m src dst\" form test I gave\nearlier), and it almost passed all of them except one, which was\nsurprising.\n\n> +\tif (!copy && !is_unborn_branch(oldname, oldref.buf) &&\n>  \t    rename_ref(oldref.buf, newref.buf, logmsg.buf))\n\nYeah, a helper function makes it much more clear what is going on.\n\n> Having said that, I fixed the `git branch -m <current-unborn> <new-name>`\n> use case; the fix will be part of v3.\n\n;-)\n"},{"id":"410705","messageId":"xmqq8saqjx2n.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"nycvar.QRO.7.76.6.2011240648160.56@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v2 4/4] init: provide useful advice about init.defaultBranch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-24T20:53:36Z","receivedAt":"2020-11-24T20:53:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n>>     To configure the initial branch name to use in all of your new\n>>     repositories and squelch this message, run:\n>>\n>> may be better---it makes it clear that the offered two choices are\n>> (1) do nothing and see this message every time, or (2) commit to a\n>> name and not see this message again.\n>\n> Well, I think I finally understand what you are saying: there is a\n> legitimate need for a way to go with Git's preference but still suppress\n> that message.\n\nI am not saying it is a legitimate need.  I just wanted to make it\nclear that we deliberately chose not to grant that wish in the\nmessage.  An advice flag in this context means that the users can\nchoose to let their distro and sysadm to flip the default silently,\nwhich is much worse than having to see the message every time they\nstart a new repository with \"git init\".\n\n\n"},{"id":"411870","messageId":"nycvar.QRO.7.76.6.2012091513540.25979@tvgsbejvaqbjf.bet","threadId":"54691","inReplyTo":"xmqq8saqjx2n.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v2 4/4] init: provide useful advice about init.defaultBranch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-12-09T14:47:05Z","receivedAt":"2020-12-09T14:49:20Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Tue, 24 Nov 2020, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n>\n> >>     To configure the initial branch name to use in all of your new\n> >>     repositories and squelch this message, run:\n> >>\n> >> may be better---it makes it clear that the offered two choices are\n> >> (1) do nothing and see this message every time, or (2) commit to a\n> >> name and not see this message again.\n> >\n> > Well, I think I finally understand what you are saying: there is a\n> > legitimate need for a way to go with Git's preference but still suppress\n> > that message.\n>\n> I am not saying it is a legitimate need.  I just wanted to make it\n> clear that we deliberately chose not to grant that wish in the\n> message.  An advice flag in this context means that the users can\n> choose to let their distro and sysadm to flip the default silently,\n> which is much worse than having to see the message every time they\n> start a new repository with \"git init\".\n\nThe distribution already can add patches, so this objection is a red\nherring. The sysadm can pick a different value for `init.defaultBranch`\nand dictate to the user silently what initial branch name to use, so that\nis also a red herring.\n\nI still think that there is a legitimate need for this config option to\nturn the advice off, without having to override Git's default branch name.\n\nIn particular in this context, I would think that most users will want to\njust go with whatever is Git's default.\n\nCiao,\nDscho\n"},{"id":"411940","messageId":"xmqqblf21v9e.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"nycvar.QRO.7.76.6.2012091513540.25979@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v2 4/4] init: provide useful advice about init.defaultBranch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-12-09T22:15:25Z","receivedAt":"2020-12-09T22:16:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> On Tue, 24 Nov 2020, Junio C Hamano wrote:\n>\n>> I am not saying it is a legitimate need.  I just wanted to make it\n>> clear that we deliberately chose not to grant that wish in the\n>> message.  An advice flag in this context means that the users can\n>> choose to let their distro and sysadm to flip the default silently,\n>> which is much worse than having to see the message every time they\n>> start a new repository with \"git init\".\n>\n> The distribution already can add patches, so this objection is a red\n> herring. The sysadm can pick a different value for `init.defaultBranch`\n> and dictate to the user silently what initial branch name to use, so that\n> is also a red herring.\n\nThe \"setting init.defaultBranch is the only way to squelch\" approach\nmeans the ~/.gitconfig will have the settings soon after the user\nstarts using Git and /etc/gitconfig will not allow administrators to\nforce their will over what the user decides to use.  Distros adding\npatches to strip configurability by setting init.defaultBranch in\nuser's ~/.gitconfig?  Is that the kind of possibilities worth\ndiscussing?\n\nSo, no, your counter-argument above is nothing but a red-herring.\n\nIf you want a counter-argument, please explain why \"I am fine to see\nthe default flipped to whatever the tool picks and having no control\nover when the flipping happens\" can be a sensible choice for users\nwith what kind of workflows.  The only folks I can think of who\nwould be fine with that are (1) those who do not create the second\nbranch in the repository and will stay on the primary branch\nforever, and (2) those who immediately rename the branch to what\nthey want after \"git init\".  For other folks, such a choice is a\ndisaster waiting to happen, and it just feels irresponsible to offer\nsuch a choice, at least to me.\n\nThanks.\n"},{"id":"411954","messageId":"CAMP44s0H-bpmYF-iTy1n=kGgn9sGdofNLoG0-w_S9+9jU-259A@mail.gmail.com","threadId":"54691","inReplyTo":"nycvar.QRO.7.76.6.2012091513540.25979@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v2 4/4] init: provide useful advice about init.defaultBranch","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2020-12-10T00:40:45Z","receivedAt":"2020-12-10T00:42:00Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Wed, Dec 9, 2020 at 5:24 PM Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> On Tue, 24 Nov 2020, Junio C Hamano wrote:\n\n> The distribution already can add patches, so this objection is a red\n> herring. The sysadm can pick a different value for `init.defaultBranch`\n> and dictate to the user silently what initial branch name to use, so that\n> is also a red herring.\n\nYes, but if they do; they have picked the ball. The user would blame\nthem--and not Git--for any unexpected change in behavior.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"412017","messageId":"pull.921.v4.git.git.1607637517.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v3.git.git.1606230450.gitgitgadget@gmail.com","subject":"[PATCH v4 0/4] Add helpful advice about init.defaultBranch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-12-10T21:58:32Z","receivedAt":"2020-12-10T22:57:58Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"It is our designated intention\n[https://sfconservancy.org/news/2020/jun/23/gitbranchname/] to \"to explore\nchanging the name of the first branch created automatically for new\nrepositories away from ‘master’\". Further, we promised that we \"will\nminimize disruption for Git's users and will include appropriate deprecation\nperiods\".\n\nTo that end, we first clarify git init's documentation (a lightly edited\nversion of Junio's patch\n[https://lore.kernel.org/git/xmqqd00a36wc.fsf@gitster.c.googlers.com]), and\nthen introduce a message giving advice to users running git init that the\nfall-back for init.defaultBranch is subject to change, and how to override\nGit's fall-back manually.\n\nThe beauty of this patch series, if I may say so, is that it does not commit\nus to any concrete plan, but opens the door for all options regarding the\ndefault branch name.\n\nChanges since v3:\n\n * Kicked out advice.defaultBranchName again. The advice can now only be\n   suppressed by setting init.defaultBranch.\n\nChanges since v2:\n\n * git branch -m <initial> <renamed> now works, too\n * The config setting advice.defaultBranchName was introduced to allow\n   suppressing this warning specifically\n * The advice now first talks about the current default branch name, then\n   how to suppress the advice, and only then explains how to override the\n   default branch name (and that that will also prevent the message from\n   being shown)\n\nChanges since v1:\n\n * Grammar fix\n * Reworded advice and commit messages\n * test_create_repo already respected GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME,\n   but now does so more obviously\n * Allowed git branch -m <name> to rename unborn branches, so that the\n   advice actually works\n\nJohannes Schindelin (4):\n  init: document `init.defaultBranch` better\n  branch -m: allow renaming a yet-unborn branch\n  get_default_branch_name(): prepare for showing some advice\n  init: provide useful advice about init.defaultBranch\n\n Documentation/git-init.txt | 11 +++++++----\n builtin/branch.c           |  4 +++-\n builtin/clone.c            |  2 +-\n builtin/init-db.c          |  8 +++++---\n refs.c                     | 24 ++++++++++++++++++++----\n refs.h                     |  4 ++--\n remote.c                   |  5 +++--\n t/t0001-init.sh            | 17 ++++++++++++++++-\n t/t1510-repo-setup.sh      |  2 +-\n t/test-lib-functions.sh    |  4 +++-\n 10 files changed, 61 insertions(+), 20 deletions(-)\n\n\nbase-commit: faefdd61ec7c7f6f3c8c9907891465ac9a2a1475\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-921%2Fdscho%2Finit.defaultBranch-advice-v4\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-921/dscho/init.defaultBranch-advice-v4\nPull-Request: https://github.com/git/git/pull/921\n\nRange-diff vs v3:\n\n 1:  483e4903491 = 1:  483e4903491 init: document `init.defaultBranch` better\n 2:  6cbd6692c6a = 2:  6cbd6692c6a branch -m: allow renaming a yet-unborn branch\n 3:  5fc15f7b9ad = 3:  5fc15f7b9ad get_default_branch_name(): prepare for showing some advice\n 4:  87c93068771 ! 4:  2f21c505d56 init: provide useful advice about init.defaultBranch\n     @@ Commit message\n      \n          Note: two test cases in Git's test suite want to verify that the\n          `stderr` output of `git init` is empty. It is now necessary to suppress\n     -    the advice using the newly-added `advice.defaultBranchName` setting.\n     -    While not strictly necessary, we also set this to `false` in\n     +    the advice, we now do that via the `init.defaultBranch` setting. While\n     +    not strictly necessary, we also set this to `false` in\n          `test_create_repo()`.\n      \n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n     - ## advice.c ##\n     -@@ advice.c: static struct {\n     - \t[ADVICE_AM_WORK_DIR] \t\t\t\t= { \"amWorkDir\", 1 },\n     - \t[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] \t= { \"checkoutAmbiguousRemoteBranchName\", 1 },\n     - \t[ADVICE_COMMIT_BEFORE_MERGE]\t\t\t= { \"commitBeforeMerge\", 1 },\n     -+\t[ADVICE_DEFAULT_BRANCH_NAME]\t\t\t= { \"defaultBranchName\", 1 },\n     - \t[ADVICE_DETACHED_HEAD]\t\t\t\t= { \"detachedHead\", 1 },\n     - \t[ADVICE_FETCH_SHOW_FORCED_UPDATES]\t\t= { \"fetchShowForcedUpdates\", 1 },\n     - \t[ADVICE_GRAFT_FILE_DEPRECATED]\t\t\t= { \"graftFileDeprecated\", 1 },\n     -\n     - ## advice.h ##\n     -@@ advice.h: extern int advice_add_empty_pathspec;\n     - \tADVICE_AM_WORK_DIR,\n     - \tADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,\n     - \tADVICE_COMMIT_BEFORE_MERGE,\n     -+\tADVICE_DEFAULT_BRANCH_NAME,\n     - \tADVICE_DETACHED_HEAD,\n     - \tADVICE_FETCH_SHOW_FORCED_UPDATES,\n     - \tADVICE_GRAFT_FILE_DEPRECATED,\n     -\n       ## refs.c ##\n     -@@\n     - #include \"strvec.h\"\n     - #include \"repository.h\"\n     - #include \"sigchain.h\"\n     -+#include \"advice.h\"\n     - \n     - /*\n     -  * List of all available backends\n      @@ refs.c: void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n       \t\tstrvec_pushf(prefixes, *p, len, prefix);\n       }\n       \n      +static const char default_branch_name_advice[] = N_(\n      +\"Using '%s' as the name for the initial branch. This default branch name\\n\"\n     -+\"is subject to change. To suppress this warning, run:\\n\"\n     -+\"\\n\"\n     -+\"\\tgit config --global advice.defaultBranchName false\\n\"\n     -+\"\\n\"\n     -+\"Alternatively, you can configure the initial branch name to use in all\\n\"\n     -+\"of your new repositories, which will also suppress this warning:\\n\"\n     ++\"is subject to change. To configure the initial branch name to use in all\\n\"\n     ++\"of your new repositories, which will suppress this warning, call:\\n\"\n      +\"\\n\"\n      +\"\\tgit config --global init.defaultBranch <name>\\n\"\n      +\"\\n\"\n     @@ refs.c: char *repo_default_branch_name(struct repository *r, int quiet)\n      -\tif (!ret)\n      +\tif (!ret) {\n       \t\tret = xstrdup(\"master\");\n     -+\t\tif (!quiet && advice_enabled(ADVICE_DEFAULT_BRANCH_NAME))\n     ++\t\tif (!quiet)\n      +\t\t\tadvise(_(default_branch_name_advice), ret);\n      +\t}\n       \n     @@ t/t0001-init.sh: test_expect_success 'reinit' '\n       \t\tmkdir again &&\n       \t\tcd again &&\n      -\t\tgit init >out1 2>err1 &&\n     -+\t\tgit -c advice.defaultBranchName=false init >out1 2>err1 &&\n     ++\t\tgit -c init.defaultBranch=initial init >out1 2>err1 &&\n       \t\tgit init >out2 2>err2\n       \t) &&\n       \ttest_i18ngrep \"Initialized empty\" again/out1 &&\n     @@ t/t1510-repo-setup.sh: setup_repo () {\n       \tsane_unset GIT_DIR GIT_WORK_TREE &&\n       \n      -\tgit init \"$name\" &&\n     -+\tgit -c advice.defaultBranchName=false init \"$name\" &&\n     ++\tgit -c init.defaultBranch=initial init \"$name\" &&\n       \tmaybe_config \"$name/.git/config\" core.worktree \"$worktreecfg\" &&\n       \tmaybe_config \"$name/.git/config\" core.bare \"$barecfg\" &&\n       \tmkdir -p \"$name/sub/sub\" &&\n     @@ t/test-lib-functions.sh: test_create_repo () {\n       \t(\n       \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n      -\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n     -+\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" \\\n     -+\t\t\t-c advice.defaultBranchName=false init \\\n     ++\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" -c \\\n     ++\t\t\tinit.defaultBranch=\"${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}\" \\\n     ++\t\t\tinit \\\n       \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n       \t\terror \"cannot run git init -- have you built things yet?\"\n       \t\tmv .git/hooks .git/hooks-disabled\n\n-- \ngitgitgadget\n"},{"id":"412018","messageId":"2f21c505d560132b4563849f955554fc7d79a9cb.1607637517.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v4.git.git.1607637517.gitgitgadget@gmail.com","subject":"[PATCH v4 4/4] init: provide useful advice about init.defaultBranch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-12-10T21:58:36Z","receivedAt":"2020-12-10T23:00:56Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nTo give ample warning for users wishing to override Git's the fall-back\nfor an unconfigured `init.defaultBranch` (in case we decide to change it\nin a future Git version), let's introduce some advice that is shown upon\n`git init` when that value is not set.\n\nNote: two test cases in Git's test suite want to verify that the\n`stderr` output of `git init` is empty. It is now necessary to suppress\nthe advice, we now do that via the `init.defaultBranch` setting. While\nnot strictly necessary, we also set this to `false` in\n`test_create_repo()`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n refs.c                  | 18 +++++++++++++++++-\n t/t0001-init.sh         |  9 ++++++++-\n t/t1510-repo-setup.sh   |  2 +-\n t/test-lib-functions.sh |  4 +++-\n 4 files changed, 29 insertions(+), 4 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 8df03122d69..6e047b3d1b4 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -562,6 +562,19 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n \t\tstrvec_pushf(prefixes, *p, len, prefix);\n }\n \n+static const char default_branch_name_advice[] = N_(\n+\"Using '%s' as the name for the initial branch. This default branch name\\n\"\n+\"is subject to change. To configure the initial branch name to use in all\\n\"\n+\"of your new repositories, which will suppress this warning, call:\\n\"\n+\"\\n\"\n+\"\\tgit config --global init.defaultBranch <name>\\n\"\n+\"\\n\"\n+\"Common names are 'main', 'trunk' and 'development'. The initial branch\\n\"\n+\"that was created can be renamed via this command:\\n\"\n+\"\\n\"\n+\"\\tgit branch -m <name>\\n\"\n+);\n+\n char *repo_default_branch_name(struct repository *r, int quiet)\n {\n \tconst char *config_key = \"init.defaultbranch\";\n@@ -574,8 +587,11 @@ char *repo_default_branch_name(struct repository *r, int quiet)\n \telse if (repo_config_get_string(r, config_key, &ret) < 0)\n \t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n \n-\tif (!ret)\n+\tif (!ret) {\n \t\tret = xstrdup(\"master\");\n+\t\tif (!quiet)\n+\t\t\tadvise(_(default_branch_name_advice), ret);\n+\t}\n \n \tfull_ref = xstrfmt(\"refs/heads/%s\", ret);\n \tif (check_refname_format(full_ref, 0))\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex bb23e56a165..0803994874f 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -163,7 +163,7 @@ test_expect_success 'reinit' '\n \t(\n \t\tmkdir again &&\n \t\tcd again &&\n-\t\tgit init >out1 2>err1 &&\n+\t\tgit -c init.defaultBranch=initial init >out1 2>err1 &&\n \t\tgit init >out2 2>err2\n \t) &&\n \ttest_i18ngrep \"Initialized empty\" again/out1 &&\n@@ -558,6 +558,13 @@ test_expect_success 'overridden default initial branch name (config)' '\n \tgrep nmb actual\n '\n \n+test_expect_success 'advice on unconfigured init.defaultBranch' '\n+\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git -c color.advice=always \\\n+\t\tinit unconfigured-default-branch-name 2>err &&\n+\ttest_decode_color <err >decoded &&\n+\ttest_i18ngrep \"<YELLOW>hint: \" decoded\n+'\n+\n test_expect_success 'overridden default main branch name (env)' '\n \ttest_config_global init.defaultBranch nmb &&\n \tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&\ndiff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh\nindex 9974457f561..bbfe05b8e4a 100755\n--- a/t/t1510-repo-setup.sh\n+++ b/t/t1510-repo-setup.sh\n@@ -79,7 +79,7 @@ setup_repo () {\n \tname=$1 worktreecfg=$2 gitfile=$3 barecfg=$4 &&\n \tsane_unset GIT_DIR GIT_WORK_TREE &&\n \n-\tgit init \"$name\" &&\n+\tgit -c init.defaultBranch=initial init \"$name\" &&\n \tmaybe_config \"$name/.git/config\" core.worktree \"$worktreecfg\" &&\n \tmaybe_config \"$name/.git/config\" core.bare \"$barecfg\" &&\n \tmkdir -p \"$name/sub/sub\" &&\ndiff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\nindex 59bbf75e832..9910102ae1f 100644\n--- a/t/test-lib-functions.sh\n+++ b/t/test-lib-functions.sh\n@@ -1202,7 +1202,9 @@ test_create_repo () {\n \tmkdir -p \"$repo\"\n \t(\n \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n-\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n+\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" -c \\\n+\t\t\tinit.defaultBranch=\"${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}\" \\\n+\t\t\tinit \\\n \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n \t\terror \"cannot run git init -- have you built things yet?\"\n \t\tmv .git/hooks .git/hooks-disabled\n-- \ngitgitgadget\n"},{"id":"412019","messageId":"6cbd6692c6a4d0586e3418225029e70b0001ffb1.1607637517.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v4.git.git.1607637517.gitgitgadget@gmail.com","subject":"[PATCH v4 2/4] branch -m: allow renaming a yet-unborn branch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-12-10T21:58:34Z","receivedAt":"2020-12-10T23:03:03Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nIn one of the next commits, we would like to give users some advice\nregarding the initial branch name, and how to modify it.\n\nTo that end, it would be good if `git branch -m <name>` worked in a\nfreshly initialized repository without any commits. Let's make it so.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/branch.c | 4 +++-\n t/t0001-init.sh  | 8 ++++++++\n 2 files changed, 11 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex efb30b88206..200da319f1d 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -538,7 +538,9 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \t\tstrbuf_addf(&logmsg, \"Branch: renamed %s to %s\",\n \t\t\t    oldref.buf, newref.buf);\n \n-\tif (!copy && rename_ref(oldref.buf, newref.buf, logmsg.buf))\n+\tif (!copy &&\n+\t    (!head || strcmp(oldname, head) || !is_null_oid(&head_oid)) &&\n+\t    rename_ref(oldref.buf, newref.buf, logmsg.buf))\n \t\tdie(_(\"Branch rename failed\"));\n \tif (copy && copy_existing_ref(oldref.buf, newref.buf, logmsg.buf))\n \t\tdie(_(\"Branch copy failed\"));\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 69a320489fc..bb23e56a165 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -571,4 +571,12 @@ test_expect_success 'invalid default branch name' '\n \ttest_i18ngrep \"invalid branch name\" err\n '\n \n+test_expect_success 'branch -m with the initial branch' '\n+\tgit init rename-initial &&\n+\tgit -C rename-initial branch -m renamed &&\n+\ttest renamed = $(git -C rename-initial symbolic-ref --short HEAD) &&\n+\tgit -C rename-initial branch -m renamed again &&\n+\ttest again = $(git -C rename-initial symbolic-ref --short HEAD)\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"412020","messageId":"nycvar.QRO.7.76.6.2012101309590.25979@tvgsbejvaqbjf.bet","threadId":"54691","inReplyTo":"xmqqblf21v9e.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v2 4/4] init: provide useful advice about init.defaultBranch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-12-10T12:12:08Z","receivedAt":"2020-12-10T23:06:48Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Wed, 9 Dec 2020, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n>\n> > On Tue, 24 Nov 2020, Junio C Hamano wrote:\n> >\n> >> I am not saying it is a legitimate need.  I just wanted to make it\n> >> clear that we deliberately chose not to grant that wish in the\n> >> message.  An advice flag in this context means that the users can\n> >> choose to let their distro and sysadm to flip the default silently,\n> >> which is much worse than having to see the message every time they\n> >> start a new repository with \"git init\".\n> >\n> > The distribution already can add patches, so this objection is a red\n> > herring. The sysadm can pick a different value for `init.defaultBranch`\n> > and dictate to the user silently what initial branch name to use, so that\n> > is also a red herring.\n>\n> The \"setting init.defaultBranch is the only way to squelch\" approach\n> means the ~/.gitconfig will have the settings soon after the user\n> starts using Git and /etc/gitconfig will not allow administrators to\n> force their will over what the user decides to use.  Distros adding\n> patches to strip configurability by setting init.defaultBranch in\n> user's ~/.gitconfig?  Is that the kind of possibilities worth\n> discussing?\n>\n> So, no, your counter-argument above is nothing but a red-herring.\n>\n> If you want a counter-argument, please explain why \"I am fine to see\n> the default flipped to whatever the tool picks and having no control\n> over when the flipping happens\" can be a sensible choice for users\n> with what kind of workflows.  The only folks I can think of who\n> would be fine with that are (1) those who do not create the second\n> branch in the repository and will stay on the primary branch\n> forever, and (2) those who immediately rename the branch to what\n> they want after \"git init\".  For other folks, such a choice is a\n> disaster waiting to happen, and it just feels irresponsible to offer\n> such a choice, at least to me.\n\nI'll make this short.\n\nI talked to a couple Git users whether they'd be fine if `git init` used a\ndifferent branch name by default, and everybody I asked said essentially\n\"yeah, whatever, I don't really care\".\n\nFor that reason, Git for Windows' installer has that option, and will keep\noffering it.\n\nCiao,\nDscho\n"},{"id":"412024","messageId":"483e490349165223a80a0bdf7716c5189560c977.1607637517.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v4.git.git.1607637517.gitgitgadget@gmail.com","subject":"[PATCH v4 1/4] init: document `init.defaultBranch` better","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-12-10T21:58:33Z","receivedAt":"2020-12-10T23:14:47Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nOur documentation does not mention any future plan to change 'master' to\nother value. It is a good idea to document this, though.\n\nInitial-patch-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/git-init.txt | 11 +++++++----\n 1 file changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\nindex 59ecda6c17d..2b399cb73d7 100644\n--- a/Documentation/git-init.txt\n+++ b/Documentation/git-init.txt\n@@ -20,8 +20,9 @@ DESCRIPTION\n \n This command creates an empty Git repository - basically a `.git`\n directory with subdirectories for `objects`, `refs/heads`,\n-`refs/tags`, and template files.  An initial `HEAD` file that\n-references the HEAD of the master branch is also created.\n+`refs/tags`, and template files.  An initial branch without any\n+commits will be created (see the `--initial-branch` option below\n+for its name).\n \n If the `$GIT_DIR` environment variable is set then it specifies a path\n to use instead of `./.git` for the base of the repository.\n@@ -73,8 +74,10 @@ If this is reinitialization, the repository will be moved to the specified path.\n -b <branch-name>::\n --initial-branch=<branch-name>::\n \n-Use the specified name for the initial branch in the newly created repository.\n-If not specified, fall back to the default name: `master`.\n+Use the specified name for the initial branch in the newly created\n+repository.  If not specified, fall back to the default name (currently\n+`master`, but that will be changed in the future; the name can be customized\n+via the `init.defaultBranch` configuration variable).\n \n --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::\n \n-- \ngitgitgadget\n\n"},{"id":"412025","messageId":"5fc15f7b9adaf64c2fbfd58f6e96768f5b9d7f8b.1607637517.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v4.git.git.1607637517.gitgitgadget@gmail.com","subject":"[PATCH v4 3/4] get_default_branch_name(): prepare for showing some advice","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-12-10T21:58:35Z","receivedAt":"2020-12-10T23:19:20Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nWe are about to introduce a message giving users running `git init` some\nadvice about `init.defaultBranch`. This will necessarily be done in\n`repo_default_branch_name()`.\n\nNot all code paths want to show that advice, though. In particular, the\n`git clone` codepath _specifically_ asks for `init_db()` to be quiet,\nvia the `INIT_DB_QUIET` flag.\n\nIn preparation for showing users above-mentioned advice, let's change\nthe function signature of `get_default_branch_name()` to accept the\nparameter `quiet`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/clone.c   | 2 +-\n builtin/init-db.c | 8 +++++---\n refs.c            | 6 +++---\n refs.h            | 4 ++--\n remote.c          | 5 +++--\n 5 files changed, 14 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex a0841923cfe..64b17840112 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -1323,7 +1323,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\tremote_head = NULL;\n \t\toption_no_checkout = 1;\n \t\tif (!option_bare) {\n-\t\t\tconst char *branch = git_default_branch_name();\n+\t\t\tconst char *branch = git_default_branch_name(0);\n \t\t\tchar *ref = xstrfmt(\"refs/heads/%s\", branch);\n \n \t\t\tinstall_branch_config(0, branch, remote_name, ref);\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 01bc648d416..dcc45bef514 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -202,7 +202,8 @@ void initialize_repository_version(int hash_algo, int reinit)\n static int create_default_files(const char *template_path,\n \t\t\t\tconst char *original_git_dir,\n \t\t\t\tconst char *initial_branch,\n-\t\t\t\tconst struct repository_format *fmt)\n+\t\t\t\tconst struct repository_format *fmt,\n+\t\t\t\tint quiet)\n {\n \tstruct stat st1;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -267,7 +268,7 @@ static int create_default_files(const char *template_path,\n \t\tchar *ref;\n \n \t\tif (!initial_branch)\n-\t\t\tinitial_branch = git_default_branch_name();\n+\t\t\tinitial_branch = git_default_branch_name(quiet);\n \n \t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n \t\tif (check_refname_format(ref, 0) < 0)\n@@ -438,7 +439,8 @@ int init_db(const char *git_dir, const char *real_git_dir,\n \tvalidate_hash_algorithm(&repo_fmt, hash);\n \n \treinit = create_default_files(template_dir, original_git_dir,\n-\t\t\t\t      initial_branch, &repo_fmt);\n+\t\t\t\t      initial_branch, &repo_fmt,\n+\t\t\t\t      flags & INIT_DB_QUIET);\n \tif (reinit && initial_branch)\n \t\twarning(_(\"re-init: ignored --initial-branch=%s\"),\n \t\t\tinitial_branch);\ndiff --git a/refs.c b/refs.c\nindex 392f0bbf68b..8df03122d69 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -562,7 +562,7 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n \t\tstrvec_pushf(prefixes, *p, len, prefix);\n }\n \n-char *repo_default_branch_name(struct repository *r)\n+char *repo_default_branch_name(struct repository *r, int quiet)\n {\n \tconst char *config_key = \"init.defaultbranch\";\n \tconst char *config_display_key = \"init.defaultBranch\";\n@@ -585,12 +585,12 @@ char *repo_default_branch_name(struct repository *r)\n \treturn ret;\n }\n \n-const char *git_default_branch_name(void)\n+const char *git_default_branch_name(int quiet)\n {\n \tstatic char *ret;\n \n \tif (!ret)\n-\t\tret = repo_default_branch_name(the_repository);\n+\t\tret = repo_default_branch_name(the_repository, quiet);\n \n \treturn ret;\n }\ndiff --git a/refs.h b/refs.h\nindex 66955181569..ff05d2e9fe2 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -170,8 +170,8 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n  * The return value of `repo_default_branch_name()` is an allocated string. The\n  * return value of `git_default_branch_name()` is a singleton.\n  */\n-const char *git_default_branch_name(void);\n-char *repo_default_branch_name(struct repository *r);\n+const char *git_default_branch_name(int quiet);\n+char *repo_default_branch_name(struct repository *r, int quiet);\n \n /*\n  * A ref_transaction represents a collection of reference updates that\ndiff --git a/remote.c b/remote.c\nindex 8a6dbbb9030..bdb88d4b7dd 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -284,7 +284,7 @@ static void read_branches_file(struct remote *remote)\n \tif (frag)\n \t\t*(frag++) = '\\0';\n \telse\n-\t\tfrag = (char *)git_default_branch_name();\n+\t\tfrag = (char *)git_default_branch_name(0);\n \n \tadd_url_alias(remote, strbuf_detach(&buf, NULL));\n \trefspec_appendf(&remote->fetch, \"refs/heads/%s:refs/heads/%s\",\n@@ -2206,7 +2206,8 @@ struct ref *guess_remote_head(const struct ref *head,\n \n \t/* If a remote branch exists with the default branch name, let's use it. */\n \tif (!all) {\n-\t\tchar *ref = xstrfmt(\"refs/heads/%s\", git_default_branch_name());\n+\t\tchar *ref = xstrfmt(\"refs/heads/%s\",\n+\t\t\t\t    git_default_branch_name(0));\n \n \t\tr = find_ref_by_name(refs, ref);\n \t\tfree(ref);\n-- \ngitgitgadget\n\n"},{"id":"412026","messageId":"xmqqpn3hqlu4.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"nycvar.QRO.7.76.6.2012101309590.25979@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v2 4/4] init: provide useful advice about init.defaultBranch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-12-10T23:32:03Z","receivedAt":"2020-12-10T23:34:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> I talked to a couple Git users whether they'd be fine if `git init` used a\n> different branch name by default, and everybody I asked said essentially\n> \"yeah, whatever, I don't really care\".\n\nYeah, I would expect that, too.  They would not have asked about the\ndetails on when that switchover of the default would happen, and\nwould not have been told that the timing is not under their control.\nI would answer to such a question with \"yeah, whatever.\" that does\nnot give you an assurance that I won't complain when the switchover\nactually happens ;-).\n\n\n"},{"id":"412028","messageId":"CAMP44s0mEsfmc7gT6Yv10_nt8d=HrbETmnwNNqxVmRGdHSOHYw@mail.gmail.com","threadId":"54691","inReplyTo":"2f21c505d560132b4563849f955554fc7d79a9cb.1607637517.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v4 4/4] init: provide useful advice about init.defaultBranch","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2020-12-11T00:15:52Z","receivedAt":"2020-12-11T00:18:47Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Thu, Dec 10, 2020 at 3:58 PM Johannes Schindelin via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n\n> +static const char default_branch_name_advice[] = N_(\n> +\"Using '%s' as the name for the initial branch. This default branch name\\n\"\n> +\"is subject to change. To configure the initial branch name to use in all\\n\"\n> +\"of your new repositories, which will suppress this warning, call:\\n\"\n> +\"\\n\"\n> +\"\\tgit config --global init.defaultBranch <name>\\n\"\n> +\"\\n\"\n> +\"Common names are 'main', 'trunk' and 'development'. The initial branch\\n\"\n\nThis is disingenuous; the most common name is \"master\"... by far. In a\ncouple years this might change, but not right now.\n\nIf you don't want to mention \"master\", then don't mention \"common\nnames\" that are not really the most common names.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"412029","messageId":"CAMP44s3mtCd9RnZdW7-HLcKVG13UW8u_1VNC0_7jByQRv61+vw@mail.gmail.com","threadId":"54691","inReplyTo":"483e490349165223a80a0bdf7716c5189560c977.1607637517.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v4 1/4] init: document `init.defaultBranch` better","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2020-12-11T00:24:09Z","receivedAt":"2020-12-11T00:26:15Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Thu, Dec 10, 2020 at 3:58 PM Johannes Schindelin via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n>\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n>\n> Our documentation does not mention any future plan to change 'master' to\n> other value. It is a good idea to document this, though.\n>\n> Initial-patch-by: Junio C Hamano <gitster@pobox.com>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>  Documentation/git-init.txt | 11 +++++++----\n>  1 file changed, 7 insertions(+), 4 deletions(-)\n>\n> diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\n> index 59ecda6c17d..2b399cb73d7 100644\n> --- a/Documentation/git-init.txt\n> +++ b/Documentation/git-init.txt\n> @@ -20,8 +20,9 @@ DESCRIPTION\n>\n>  This command creates an empty Git repository - basically a `.git`\n>  directory with subdirectories for `objects`, `refs/heads`,\n> -`refs/tags`, and template files.  An initial `HEAD` file that\n> -references the HEAD of the master branch is also created.\n\nThe current sentence: \"An initial `HEAD` file that references the HEAD\nof the master branch is also created.\" is still true. There's no need\nto change that (yet).\n\n> +`refs/tags`, and template files.  An initial branch without any\n> +commits will be created (see the `--initial-branch` option below\n> +for its name).\n\nPerhaps: (see the `--initial-branch` option below to choose another name).\n\n>  If the `$GIT_DIR` environment variable is set then it specifies a path\n>  to use instead of `./.git` for the base of the repository.\n> @@ -73,8 +74,10 @@ If this is reinitialization, the repository will be moved to the specified path.\n>  -b <branch-name>::\n>  --initial-branch=<branch-name>::\n>\n> -Use the specified name for the initial branch in the newly created repository.\n> -If not specified, fall back to the default name: `master`.\n> +Use the specified name for the initial branch in the newly created\n\nAgain; the default name has not changed.\n\n> +repository.  If not specified, fall back to the default name (currently\n> +`master`, but that will be changed in the future; the name can be customized\n> +via the `init.defaultBranch` configuration variable).\n\nWait a second. The advice warning said \"this is subject to change\",\nand the documentation says \"that will be changed in the future\". Which\nis it?\n\n\"I might give you a fine\", and \"I will give you a fine\" are most\ndefinitely not the same thing.\n\nEither say \"this is subject to change\" in both the documentation and\nthe warning. Or say \"that will be changed in the future\".\n\nDon't say one thing in one and another thing in the other.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"412032","messageId":"xmqq360dqgpa.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"CAMP44s0mEsfmc7gT6Yv10_nt8d=HrbETmnwNNqxVmRGdHSOHYw@mail.gmail.com","subject":"Re: [PATCH v4 4/4] init: provide useful advice about init.defaultBranch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-12-11T01:22:57Z","receivedAt":"2020-12-11T01:24:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> On Thu, Dec 10, 2020 at 3:58 PM Johannes Schindelin via GitGitGadget\n> <gitgitgadget@gmail.com> wrote:\n>\n>> +static const char default_branch_name_advice[] = N_(\n>> +\"Using '%s' as the name for the initial branch. This default branch name\\n\"\n>> +\"is subject to change. To configure the initial branch name to use in all\\n\"\n>> +\"of your new repositories, which will suppress this warning, call:\\n\"\n>> +\"\\n\"\n>> +\"\\tgit config --global init.defaultBranch <name>\\n\"\n>> +\"\\n\"\n>> +\"Common names are 'main', 'trunk' and 'development'. The initial branch\\n\"\n>\n> This is disingenuous; the most common name is \"master\"... by far. In a\n> couple years this might change, but not right now.\n>\n> If you don't want to mention \"master\", then don't mention \"common\n> names\" that are not really the most common names.\n\nNames commonly chosen by those who want to move away from 'master'\nare...\n\n"},{"id":"412034","messageId":"CAMP44s3bhPP4BcNCfa4KeaoaDLm+XZqV1cX8wyaMmZyHzJujuw@mail.gmail.com","threadId":"54691","inReplyTo":"xmqq360dqgpa.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v4 4/4] init: provide useful advice about init.defaultBranch","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2020-12-11T02:00:12Z","receivedAt":"2020-12-11T02:02:04Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Thu, Dec 10, 2020 at 7:23 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Felipe Contreras <felipe.contreras@gmail.com> writes:\n>\n> > On Thu, Dec 10, 2020 at 3:58 PM Johannes Schindelin via GitGitGadget\n> > <gitgitgadget@gmail.com> wrote:\n> >\n> >> +static const char default_branch_name_advice[] = N_(\n> >> +\"Using '%s' as the name for the initial branch. This default branch name\\n\"\n> >> +\"is subject to change. To configure the initial branch name to use in all\\n\"\n> >> +\"of your new repositories, which will suppress this warning, call:\\n\"\n> >> +\"\\n\"\n> >> +\"\\tgit config --global init.defaultBranch <name>\\n\"\n> >> +\"\\n\"\n> >> +\"Common names are 'main', 'trunk' and 'development'. The initial branch\\n\"\n> >\n> > This is disingenuous; the most common name is \"master\"... by far. In a\n> > couple years this might change, but not right now.\n> >\n> > If you don't want to mention \"master\", then don't mention \"common\n> > names\" that are not really the most common names.\n>\n> Names commonly chosen by those who want to move away from 'master'\n> are...\n\nBut we don't want to spill drama into the user interface.\n\nI think the vast majority of users haven't heard of this drama. Just\nlike the vast majority of users had not heard of the git-foo\nobsoletion even after several years. Our vantage point is skewed for\nbeing too close to Git development.\n\nThose users will ask: \"who wants to move away from 'master'?\"\n\nIf we don't presume our users have the same knowledge as us, we have to explain:\n\n  Names commonly chosen by those who want to move away from 'master'\n  are; 'main', 'trunk', and 'development'. For more information read\n  this post:\n  https://dev.to/rhymu8354/git-renaming-the-master-branch-137b.\n\nI say don't. If the user wants to know why anyone would want to change\n\"the default branch name\", she can google it and find out.\n\nCheer.\n\n-- \nFelipe Contreras\n"},{"id":"412045","messageId":"xmqqblf0opwn.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"CAMP44s3mtCd9RnZdW7-HLcKVG13UW8u_1VNC0_7jByQRv61+vw@mail.gmail.com","subject":"Re: [PATCH v4 1/4] init: document `init.defaultBranch` better","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-12-11T05:47:04Z","receivedAt":"2020-12-11T05:48:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n>> -`refs/tags`, and template files.  An initial `HEAD` file that\n>> -references the HEAD of the master branch is also created.\n>> +`refs/tags`, and template files.  An initial branch without any\n>> +commits will be created (see the `--initial-branch` option below\n>> +for its name).\n>\n> The current sentence: \"An initial `HEAD` file that references the HEAD\n> of the master branch is also created.\" is still true. There's no need\n> to change that (yet).\n\nThe change updates the description for readability, lowering the\ntechnical level of description, and correcting inaccuracies.\n\n - The readers in the context of understanding what \"git init\"\n   performs does not have to know nor care that HEAD is implemented\n   as a file.  In fact, there is an effort to introduce HEAD and\n   other refs that are implemented as individual files under\n   $GIT_DIR/.  Dropping the word \"file\" is to correct these.\n\n - Also we no longer say \"the HEAD of\" a branch, even if we used to\n   use that expression.  When we really need to refer to the commit\n   directly pointed at by a branch ref, we say \"the tip of\" instead\n   there days.\n\n - It used to be left unsaid that the initial branch begins its life\n   without any commit.  Now it does.\n\nNone of these is about \"'master' or any other name?\" issue.\n\n> Perhaps: (see the `--initial-branch` option below to choose another name).\n\nThat changes the meaning of the explanation.  It is compensating for\nnot saying what the name of the initial branch is, and is not trying\nto teach that the name can be changed.  The text in the patch is good\nas-is.\n"},{"id":"412047","messageId":"xmqqsg8cnaqs.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"CAMP44s3mtCd9RnZdW7-HLcKVG13UW8u_1VNC0_7jByQRv61+vw@mail.gmail.com","subject":"Re: [PATCH v4 1/4] init: document `init.defaultBranch` better","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-12-11T05:59:55Z","receivedAt":"2020-12-11T06:01:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> On Thu, Dec 10, 2020 at 3:58 PM Johannes Schindelin via GitGitGadget\n>\n>> +repository.  If not specified, fall back to the default name (currently\n>> +`master`, but that will be changed in the future; the name can be customized\n>> +via the `init.defaultBranch` configuration variable).\n>\n> Wait a second. The advice warning said \"this is subject to change\",\n> and the documentation says \"that will be changed in the future\". Which\n> is it?\n>\n> \"I might give you a fine\", and \"I will give you a fine\" are most\n> definitely not the same thing.\n\nI think we say \"this is subject to change\" in other places, and I\nagree that this part should match to avoid confusing readers,\nespecially the non-native ones like me.\n\n    If not specified, fall back to the default name (currently\n    `master`, but this is subject to change in the future; ...\n\nwould be more consistent.\n"},{"id":"412048","messageId":"CAMP44s1qW=_x6FeU7-dho+bxmY+0n4EehW8-Xy3PX_+sbhjmcg@mail.gmail.com","threadId":"54691","inReplyTo":"xmqqblf0opwn.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v4 1/4] init: document `init.defaultBranch` better","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2020-12-11T06:26:51Z","receivedAt":"2020-12-11T06:28:49Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Thu, Dec 10, 2020 at 11:47 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Felipe Contreras <felipe.contreras@gmail.com> writes:\n>\n> >> -`refs/tags`, and template files.  An initial `HEAD` file that\n> >> -references the HEAD of the master branch is also created.\n> >> +`refs/tags`, and template files.  An initial branch without any\n> >> +commits will be created (see the `--initial-branch` option below\n> >> +for its name).\n> >\n> > The current sentence: \"An initial `HEAD` file that references the HEAD\n> > of the master branch is also created.\" is still true. There's no need\n> > to change that (yet).\n>\n> The change updates the description for readability, lowering the\n> technical level of description, and correcting inaccuracies.\n\nOK.\n\n>  - The readers in the context of understanding what \"git init\"\n>    performs does not have to know nor care that HEAD is implemented\n>    as a file.  In fact, there is an effort to introduce HEAD and\n>    other refs that are implemented as individual files under\n>    $GIT_DIR/.  Dropping the word \"file\" is to correct these.\n\nRight.\n\n>  - Also we no longer say \"the HEAD of\" a branch, even if we used to\n>    use that expression.  When we really need to refer to the commit\n>    directly pointed at by a branch ref, we say \"the tip of\" instead\n>    there days.\n\nSure.\n\n>  - It used to be left unsaid that the initial branch begins its life\n>    without any commit.  Now it does.\n\nOK.\n\n> None of these is about \"'master' or any other name?\" issue.\n\nIndeed, but the commit message clearly states:\n\n  Our documentation does not mention any future plan to change 'master'\n  to other value. It is a good idea to document this, though.\n\nIt doesn't say anything about improving the documentation of \"git\ninit\", nor any of your three points. The main intention is clear.\n\nOn top of your three points it sneaks another change; avoiding the\n\"master\" branch name. If this really had nothing to do with the\n\"master\" branch name, it could very well be sent as a separate\nindependent patch.\n\nThe following text has your three valid points, but doesn't sneak in\nthe extra change:\n\n  An initial \"master\" branch without any commits will be created (see\n  the `--initial-branch` option below to choose another name).\n\n> > Perhaps: (see the `--initial-branch` option below to choose another name).\n>\n> That changes the meaning of the explanation.  It is compensating for\n> not saying what the name of the initial branch is, and is not trying\n> to teach that the name can be changed.  The text in the patch is good\n> as-is.\n\nIn English parentheses are used to clarify information, and typically\nit's *supplementary* information. That is; the sentence must stand on\nits own without them.\n\nThis sentence is missing crucial information and it doesn't stand on its own:\n\n  An initial branch without any commits will be created.\n\nThis one does stand on its own:\n\n  An initial \"master\" branch without any commits will be created.\n\n(and doesn't omit any current information.)\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"412067","messageId":"nycvar.QRO.7.76.6.2012110145200.25979@tvgsbejvaqbjf.bet","threadId":"54691","inReplyTo":"xmqq360dqgpa.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v4 4/4] init: provide useful advice about init.defaultBranch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-12-11T00:47:00Z","receivedAt":"2020-12-11T11:07:58Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Thu, 10 Dec 2020, Junio C Hamano wrote:\n\n> Felipe Contreras <felipe.contreras@gmail.com> writes:\n>\n> > On Thu, Dec 10, 2020 at 3:58 PM Johannes Schindelin via GitGitGadget\n> > <gitgitgadget@gmail.com> wrote:\n> >\n> >> +static const char default_branch_name_advice[] = N_(\n> >> +\"Using '%s' as the name for the initial branch. This default branch name\\n\"\n> >> +\"is subject to change. To configure the initial branch name to use in all\\n\"\n> >> +\"of your new repositories, which will suppress this warning, call:\\n\"\n> >> +\"\\n\"\n> >> +\"\\tgit config --global init.defaultBranch <name>\\n\"\n> >> +\"\\n\"\n> >> +\"Common names are 'main', 'trunk' and 'development'. The initial branch\\n\"\n> >\n> > This is disingenuous; the most common name is \"master\"... by far. In a\n> > couple years this might change, but not right now.\n> >\n> > If you don't want to mention \"master\", then don't mention \"common\n> > names\" that are not really the most common names.\n>\n> Names commonly chosen by those who want to move away from 'master'\n> are...\n\n\"those who want to move away\" sounds a bit too non-committal for my\nliking. So I changed it to:\n\n\tNames commonly chosen instead of 'master' are 'main', 'trunk'\n\tand 'development'.\n\nWhile at it, I also improved the next sentence:\n\n\t The just-created branch can be renamed via this command:\n\nCiao,\nDscho\n"},{"id":"412071","messageId":"ac7b352a0ba604f9b10a5a5ce5487d1002169443.1607686618.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v5.git.git.1607686618.gitgitgadget@gmail.com","subject":"[PATCH v5 2/4] branch -m: allow renaming a yet-unborn branch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-12-11T11:36:55Z","receivedAt":"2020-12-11T11:38:42Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nIn one of the next commits, we would like to give users some advice\nregarding the initial branch name, and how to modify it.\n\nTo that end, it would be good if `git branch -m <name>` worked in a\nfreshly initialized repository without any commits. Let's make it so.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/branch.c | 4 +++-\n t/t0001-init.sh  | 8 ++++++++\n 2 files changed, 11 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex efb30b88206..200da319f1d 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -538,7 +538,9 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \t\tstrbuf_addf(&logmsg, \"Branch: renamed %s to %s\",\n \t\t\t    oldref.buf, newref.buf);\n \n-\tif (!copy && rename_ref(oldref.buf, newref.buf, logmsg.buf))\n+\tif (!copy &&\n+\t    (!head || strcmp(oldname, head) || !is_null_oid(&head_oid)) &&\n+\t    rename_ref(oldref.buf, newref.buf, logmsg.buf))\n \t\tdie(_(\"Branch rename failed\"));\n \tif (copy && copy_existing_ref(oldref.buf, newref.buf, logmsg.buf))\n \t\tdie(_(\"Branch copy failed\"));\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 69a320489fc..bb23e56a165 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -571,4 +571,12 @@ test_expect_success 'invalid default branch name' '\n \ttest_i18ngrep \"invalid branch name\" err\n '\n \n+test_expect_success 'branch -m with the initial branch' '\n+\tgit init rename-initial &&\n+\tgit -C rename-initial branch -m renamed &&\n+\ttest renamed = $(git -C rename-initial symbolic-ref --short HEAD) &&\n+\tgit -C rename-initial branch -m renamed again &&\n+\ttest again = $(git -C rename-initial symbolic-ref --short HEAD)\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"412072","messageId":"ce35cf3da65c60980d1dfdce20928a1498b6390b.1607686618.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v5.git.git.1607686618.gitgitgadget@gmail.com","subject":"[PATCH v5 1/4] init: document `init.defaultBranch` better","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-12-11T11:36:54Z","receivedAt":"2020-12-11T11:38:42Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nOur documentation does not mention any future plan to change 'master' to\nother value. It is a good idea to document this, though.\n\nInitial-patch-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/git-init.txt | 11 +++++++----\n 1 file changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\nindex 59ecda6c17d..b611d80697d 100644\n--- a/Documentation/git-init.txt\n+++ b/Documentation/git-init.txt\n@@ -20,8 +20,9 @@ DESCRIPTION\n \n This command creates an empty Git repository - basically a `.git`\n directory with subdirectories for `objects`, `refs/heads`,\n-`refs/tags`, and template files.  An initial `HEAD` file that\n-references the HEAD of the master branch is also created.\n+`refs/tags`, and template files.  An initial branch without any\n+commits will be created (see the `--initial-branch` option below\n+for its name).\n \n If the `$GIT_DIR` environment variable is set then it specifies a path\n to use instead of `./.git` for the base of the repository.\n@@ -73,8 +74,10 @@ If this is reinitialization, the repository will be moved to the specified path.\n -b <branch-name>::\n --initial-branch=<branch-name>::\n \n-Use the specified name for the initial branch in the newly created repository.\n-If not specified, fall back to the default name: `master`.\n+Use the specified name for the initial branch in the newly created\n+repository.  If not specified, fall back to the default name (currently\n+`master`, but this is subject to change in the future; the name can be\n+customized via the `init.defaultBranch` configuration variable).\n \n --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::\n \n-- \ngitgitgadget\n\n"},{"id":"412073","messageId":"aba72340c87e93836ffc5b572257cc41e4b1bc12.1607686618.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v5.git.git.1607686618.gitgitgadget@gmail.com","subject":"[PATCH v5 3/4] get_default_branch_name(): prepare for showing some advice","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-12-11T11:36:56Z","receivedAt":"2020-12-11T11:39:14Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nWe are about to introduce a message giving users running `git init` some\nadvice about `init.defaultBranch`. This will necessarily be done in\n`repo_default_branch_name()`.\n\nNot all code paths want to show that advice, though. In particular, the\n`git clone` codepath _specifically_ asks for `init_db()` to be quiet,\nvia the `INIT_DB_QUIET` flag.\n\nIn preparation for showing users above-mentioned advice, let's change\nthe function signature of `get_default_branch_name()` to accept the\nparameter `quiet`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/clone.c   | 2 +-\n builtin/init-db.c | 8 +++++---\n refs.c            | 6 +++---\n refs.h            | 4 ++--\n remote.c          | 5 +++--\n 5 files changed, 14 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex a0841923cfe..64b17840112 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -1323,7 +1323,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\tremote_head = NULL;\n \t\toption_no_checkout = 1;\n \t\tif (!option_bare) {\n-\t\t\tconst char *branch = git_default_branch_name();\n+\t\t\tconst char *branch = git_default_branch_name(0);\n \t\t\tchar *ref = xstrfmt(\"refs/heads/%s\", branch);\n \n \t\t\tinstall_branch_config(0, branch, remote_name, ref);\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 01bc648d416..dcc45bef514 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -202,7 +202,8 @@ void initialize_repository_version(int hash_algo, int reinit)\n static int create_default_files(const char *template_path,\n \t\t\t\tconst char *original_git_dir,\n \t\t\t\tconst char *initial_branch,\n-\t\t\t\tconst struct repository_format *fmt)\n+\t\t\t\tconst struct repository_format *fmt,\n+\t\t\t\tint quiet)\n {\n \tstruct stat st1;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -267,7 +268,7 @@ static int create_default_files(const char *template_path,\n \t\tchar *ref;\n \n \t\tif (!initial_branch)\n-\t\t\tinitial_branch = git_default_branch_name();\n+\t\t\tinitial_branch = git_default_branch_name(quiet);\n \n \t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n \t\tif (check_refname_format(ref, 0) < 0)\n@@ -438,7 +439,8 @@ int init_db(const char *git_dir, const char *real_git_dir,\n \tvalidate_hash_algorithm(&repo_fmt, hash);\n \n \treinit = create_default_files(template_dir, original_git_dir,\n-\t\t\t\t      initial_branch, &repo_fmt);\n+\t\t\t\t      initial_branch, &repo_fmt,\n+\t\t\t\t      flags & INIT_DB_QUIET);\n \tif (reinit && initial_branch)\n \t\twarning(_(\"re-init: ignored --initial-branch=%s\"),\n \t\t\tinitial_branch);\ndiff --git a/refs.c b/refs.c\nindex 392f0bbf68b..8df03122d69 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -562,7 +562,7 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n \t\tstrvec_pushf(prefixes, *p, len, prefix);\n }\n \n-char *repo_default_branch_name(struct repository *r)\n+char *repo_default_branch_name(struct repository *r, int quiet)\n {\n \tconst char *config_key = \"init.defaultbranch\";\n \tconst char *config_display_key = \"init.defaultBranch\";\n@@ -585,12 +585,12 @@ char *repo_default_branch_name(struct repository *r)\n \treturn ret;\n }\n \n-const char *git_default_branch_name(void)\n+const char *git_default_branch_name(int quiet)\n {\n \tstatic char *ret;\n \n \tif (!ret)\n-\t\tret = repo_default_branch_name(the_repository);\n+\t\tret = repo_default_branch_name(the_repository, quiet);\n \n \treturn ret;\n }\ndiff --git a/refs.h b/refs.h\nindex 66955181569..ff05d2e9fe2 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -170,8 +170,8 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n  * The return value of `repo_default_branch_name()` is an allocated string. The\n  * return value of `git_default_branch_name()` is a singleton.\n  */\n-const char *git_default_branch_name(void);\n-char *repo_default_branch_name(struct repository *r);\n+const char *git_default_branch_name(int quiet);\n+char *repo_default_branch_name(struct repository *r, int quiet);\n \n /*\n  * A ref_transaction represents a collection of reference updates that\ndiff --git a/remote.c b/remote.c\nindex 8a6dbbb9030..bdb88d4b7dd 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -284,7 +284,7 @@ static void read_branches_file(struct remote *remote)\n \tif (frag)\n \t\t*(frag++) = '\\0';\n \telse\n-\t\tfrag = (char *)git_default_branch_name();\n+\t\tfrag = (char *)git_default_branch_name(0);\n \n \tadd_url_alias(remote, strbuf_detach(&buf, NULL));\n \trefspec_appendf(&remote->fetch, \"refs/heads/%s:refs/heads/%s\",\n@@ -2206,7 +2206,8 @@ struct ref *guess_remote_head(const struct ref *head,\n \n \t/* If a remote branch exists with the default branch name, let's use it. */\n \tif (!all) {\n-\t\tchar *ref = xstrfmt(\"refs/heads/%s\", git_default_branch_name());\n+\t\tchar *ref = xstrfmt(\"refs/heads/%s\",\n+\t\t\t\t    git_default_branch_name(0));\n \n \t\tr = find_ref_by_name(refs, ref);\n \t\tfree(ref);\n-- \ngitgitgadget\n\n"},{"id":"412074","messageId":"ce26446b1a2e7bf14cdf814ca56c37b2e7d6b578.1607686618.git.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v5.git.git.1607686618.gitgitgadget@gmail.com","subject":"[PATCH v5 4/4] init: provide useful advice about init.defaultBranch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-12-11T11:36:57Z","receivedAt":"2020-12-11T11:39:14Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nTo give ample warning for users wishing to override Git's the fall-back\nfor an unconfigured `init.defaultBranch` (in case we decide to change it\nin a future Git version), let's introduce some advice that is shown upon\n`git init` when that value is not set.\n\nNote: two test cases in Git's test suite want to verify that the\n`stderr` output of `git init` is empty. It is now necessary to suppress\nthe advice, we now do that via the `init.defaultBranch` setting. While\nnot strictly necessary, we also set this to `false` in\n`test_create_repo()`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n refs.c                  | 18 +++++++++++++++++-\n t/t0001-init.sh         |  9 ++++++++-\n t/t1510-repo-setup.sh   |  2 +-\n t/test-lib-functions.sh |  4 +++-\n 4 files changed, 29 insertions(+), 4 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 8df03122d69..13dc2c3291b 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -562,6 +562,19 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n \t\tstrvec_pushf(prefixes, *p, len, prefix);\n }\n \n+static const char default_branch_name_advice[] = N_(\n+\"Using '%s' as the name for the initial branch. This default branch name\\n\"\n+\"is subject to change. To configure the initial branch name to use in all\\n\"\n+\"of your new repositories, which will suppress this warning, call:\\n\"\n+\"\\n\"\n+\"\\tgit config --global init.defaultBranch <name>\\n\"\n+\"\\n\"\n+\"Names commonly chosen instead of 'master' are 'main', 'trunk' and\\n\"\n+\"'development'. The just-created branch can be renamed via this command:\\n\"\n+\"\\n\"\n+\"\\tgit branch -m <name>\\n\"\n+);\n+\n char *repo_default_branch_name(struct repository *r, int quiet)\n {\n \tconst char *config_key = \"init.defaultbranch\";\n@@ -574,8 +587,11 @@ char *repo_default_branch_name(struct repository *r, int quiet)\n \telse if (repo_config_get_string(r, config_key, &ret) < 0)\n \t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n \n-\tif (!ret)\n+\tif (!ret) {\n \t\tret = xstrdup(\"master\");\n+\t\tif (!quiet)\n+\t\t\tadvise(_(default_branch_name_advice), ret);\n+\t}\n \n \tfull_ref = xstrfmt(\"refs/heads/%s\", ret);\n \tif (check_refname_format(full_ref, 0))\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex bb23e56a165..0803994874f 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -163,7 +163,7 @@ test_expect_success 'reinit' '\n \t(\n \t\tmkdir again &&\n \t\tcd again &&\n-\t\tgit init >out1 2>err1 &&\n+\t\tgit -c init.defaultBranch=initial init >out1 2>err1 &&\n \t\tgit init >out2 2>err2\n \t) &&\n \ttest_i18ngrep \"Initialized empty\" again/out1 &&\n@@ -558,6 +558,13 @@ test_expect_success 'overridden default initial branch name (config)' '\n \tgrep nmb actual\n '\n \n+test_expect_success 'advice on unconfigured init.defaultBranch' '\n+\tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git -c color.advice=always \\\n+\t\tinit unconfigured-default-branch-name 2>err &&\n+\ttest_decode_color <err >decoded &&\n+\ttest_i18ngrep \"<YELLOW>hint: \" decoded\n+'\n+\n test_expect_success 'overridden default main branch name (env)' '\n \ttest_config_global init.defaultBranch nmb &&\n \tGIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&\ndiff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh\nindex 9974457f561..bbfe05b8e4a 100755\n--- a/t/t1510-repo-setup.sh\n+++ b/t/t1510-repo-setup.sh\n@@ -79,7 +79,7 @@ setup_repo () {\n \tname=$1 worktreecfg=$2 gitfile=$3 barecfg=$4 &&\n \tsane_unset GIT_DIR GIT_WORK_TREE &&\n \n-\tgit init \"$name\" &&\n+\tgit -c init.defaultBranch=initial init \"$name\" &&\n \tmaybe_config \"$name/.git/config\" core.worktree \"$worktreecfg\" &&\n \tmaybe_config \"$name/.git/config\" core.bare \"$barecfg\" &&\n \tmkdir -p \"$name/sub/sub\" &&\ndiff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\nindex 59bbf75e832..9910102ae1f 100644\n--- a/t/test-lib-functions.sh\n+++ b/t/test-lib-functions.sh\n@@ -1202,7 +1202,9 @@ test_create_repo () {\n \tmkdir -p \"$repo\"\n \t(\n \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n-\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n+\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" -c \\\n+\t\t\tinit.defaultBranch=\"${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}\" \\\n+\t\t\tinit \\\n \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n \t\terror \"cannot run git init -- have you built things yet?\"\n \t\tmv .git/hooks .git/hooks-disabled\n-- \ngitgitgadget\n"},{"id":"412075","messageId":"pull.921.v5.git.git.1607686618.gitgitgadget@gmail.com","threadId":"54691","inReplyTo":"pull.921.v4.git.git.1607637517.gitgitgadget@gmail.com","subject":"[PATCH v5 0/4] Add helpful advice about init.defaultBranch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-12-11T11:36:53Z","receivedAt":"2020-12-11T11:39:46Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"It is our designated intention\n[https://sfconservancy.org/news/2020/jun/23/gitbranchname/] to \"to explore\nchanging the name of the first branch created automatically for new\nrepositories away from ‘master’\". Further, we promised that we \"will\nminimize disruption for Git's users and will include appropriate deprecation\nperiods\".\n\nTo that end, we first clarify git init's documentation (a lightly edited\nversion of Junio's patch\n[https://lore.kernel.org/git/xmqqd00a36wc.fsf@gitster.c.googlers.com]), and\nthen introduce a message giving advice to users running git init that the\nfall-back for init.defaultBranch is subject to change, and how to override\nGit's fall-back manually.\n\nThe beauty of this patch series, if I may say so, is that it does not commit\nus to any concrete plan, but opens the door for all options regarding the\ndefault branch name.\n\nChanges since v4:\n\n * Reworded the documentation to weaken the \"will be changed in the future\"\n   to \"is subject to change\".\n * Reworded the advice to explicitly mention \"instead of 'master'\".\n\nChanges since v3:\n\n * Kicked out advice.defaultBranchName again. The advice can now only be\n   suppressed by setting init.defaultBranch.\n\nChanges since v2:\n\n * git branch -m <initial> <renamed> now works, too\n * The config setting advice.defaultBranchName was introduced to allow\n   suppressing this warning specifically\n * The advice now first talks about the current default branch name, then\n   how to suppress the advice, and only then explains how to override the\n   default branch name (and that that will also prevent the message from\n   being shown)\n\nChanges since v1:\n\n * Grammar fix\n * Reworded advice and commit messages\n * test_create_repo already respected GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME,\n   but now does so more obviously\n * Allowed git branch -m <name> to rename unborn branches, so that the\n   advice actually works\n\nJohannes Schindelin (4):\n  init: document `init.defaultBranch` better\n  branch -m: allow renaming a yet-unborn branch\n  get_default_branch_name(): prepare for showing some advice\n  init: provide useful advice about init.defaultBranch\n\n Documentation/git-init.txt | 11 +++++++----\n builtin/branch.c           |  4 +++-\n builtin/clone.c            |  2 +-\n builtin/init-db.c          |  8 +++++---\n refs.c                     | 24 ++++++++++++++++++++----\n refs.h                     |  4 ++--\n remote.c                   |  5 +++--\n t/t0001-init.sh            | 17 ++++++++++++++++-\n t/t1510-repo-setup.sh      |  2 +-\n t/test-lib-functions.sh    |  4 +++-\n 10 files changed, 61 insertions(+), 20 deletions(-)\n\n\nbase-commit: faefdd61ec7c7f6f3c8c9907891465ac9a2a1475\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-921%2Fdscho%2Finit.defaultBranch-advice-v5\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-921/dscho/init.defaultBranch-advice-v5\nPull-Request: https://github.com/git/git/pull/921\n\nRange-diff vs v4:\n\n 1:  483e4903491 ! 1:  ce35cf3da65 init: document `init.defaultBranch` better\n     @@ Documentation/git-init.txt: If this is reinitialization, the repository will be\n      -If not specified, fall back to the default name: `master`.\n      +Use the specified name for the initial branch in the newly created\n      +repository.  If not specified, fall back to the default name (currently\n     -+`master`, but that will be changed in the future; the name can be customized\n     -+via the `init.defaultBranch` configuration variable).\n     ++`master`, but this is subject to change in the future; the name can be\n     ++customized via the `init.defaultBranch` configuration variable).\n       \n       --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::\n       \n 2:  6cbd6692c6a = 2:  ac7b352a0ba branch -m: allow renaming a yet-unborn branch\n 3:  5fc15f7b9ad = 3:  aba72340c87 get_default_branch_name(): prepare for showing some advice\n 4:  2f21c505d56 ! 4:  ce26446b1a2 init: provide useful advice about init.defaultBranch\n     @@ refs.c: void expand_ref_prefix(struct strvec *prefixes, const char *prefix)\n      +\"\\n\"\n      +\"\\tgit config --global init.defaultBranch <name>\\n\"\n      +\"\\n\"\n     -+\"Common names are 'main', 'trunk' and 'development'. The initial branch\\n\"\n     -+\"that was created can be renamed via this command:\\n\"\n     ++\"Names commonly chosen instead of 'master' are 'main', 'trunk' and\\n\"\n     ++\"'development'. The just-created branch can be renamed via this command:\\n\"\n      +\"\\n\"\n      +\"\\tgit branch -m <name>\\n\"\n      +);\n\n-- \ngitgitgadget\n"},{"id":"415961","messageId":"20210202212451.GC2091@szeder.dev","threadId":"54691","inReplyTo":"ce26446b1a2e7bf14cdf814ca56c37b2e7d6b578.1607686618.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v5 4/4] init: provide useful advice about init.defaultBranch","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2021-02-02T21:24:51Z","receivedAt":"2021-02-02T21:25:59Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Fri, Dec 11, 2020 at 11:36:57AM +0000, Johannes Schindelin via GitGitGadget wrote:\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> \n> To give ample warning for users wishing to override Git's the fall-back\n> for an unconfigured `init.defaultBranch` (in case we decide to change it\n> in a future Git version), let's introduce some advice that is shown upon\n> `git init` when that value is not set.\n> \n> Note: two test cases in Git's test suite want to verify that the\n> `stderr` output of `git init` is empty. It is now necessary to suppress\n> the advice, we now do that via the `init.defaultBranch` setting. While\n> not strictly necessary, we also set this to `false` in\n> `test_create_repo()`.\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n\n> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n> index 59bbf75e832..9910102ae1f 100644\n> --- a/t/test-lib-functions.sh\n> +++ b/t/test-lib-functions.sh\n> @@ -1202,7 +1202,9 @@ test_create_repo () {\n>  \tmkdir -p \"$repo\"\n>  \t(\n>  \t\tcd \"$repo\" || error \"Cannot setup test environment\"\n> -\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n> +\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" -c \\\n> +\t\t\tinit.defaultBranch=\"${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}\" \\\n> +\t\t\tinit \\\n>  \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n\nThis breaks GIT_TEST_INSTALLED when the given Git version doesn't yet\ncontain 8b1fa77867 (Allow passing of configuration parameters in the\ncommand line, 2010-03-26):\n\n  $ GIT_TEST_INSTALLED=.../v1.6.0/bin/ ./t9999-test.sh -x\n  Unknown option: -c\n  usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]\n  error: cannot run git init -- have you built things yet?\n\n\n>  \t\terror \"cannot run git init -- have you built things yet?\"\n>  \t\tmv .git/hooks .git/hooks-disabled\n> -- \n> gitgitgadget\n"},{"id":"415970","messageId":"xmqqsg6eds5e.fsf@gitster.c.googlers.com","threadId":"54691","inReplyTo":"20210202212451.GC2091@szeder.dev","subject":"Re: [PATCH v5 4/4] init: provide useful advice about init.defaultBranch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-02-02T22:25:01Z","receivedAt":"2021-02-02T22:28:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder.dev@gmail.com> writes:\n\n>> -\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n>> +\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" -c \\\n>> +\t\t\tinit.defaultBranch=\"${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}\" \\\n>> +\t\t\tinit \\\n>>  \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n>\n> This breaks GIT_TEST_INSTALLED when the given Git version doesn't yet\n> contain 8b1fa77867 (Allow passing of configuration parameters in the\n> command line, 2010-03-26):\n\nYes, but test-installed is about running an old version of Git on\nthe current Git test suite.  In the tests we make liberal use of\n\"git -c <var>=<val>\", which such an old version of Git has no chance\nof passing.  So...\n"},{"id":"416027","messageId":"20210203052018.GE2091@szeder.dev","threadId":"54691","inReplyTo":"xmqqsg6eds5e.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v5 4/4] init: provide useful advice about init.defaultBranch","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2021-02-03T05:20:18Z","receivedAt":"2021-02-03T05:22:17Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Tue, Feb 02, 2021 at 02:25:01PM -0800, Junio C Hamano wrote:\n> SZEDER Gábor <szeder.dev@gmail.com> writes:\n> \n> >> -\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n> >> +\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" -c \\\n> >> +\t\t\tinit.defaultBranch=\"${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}\" \\\n> >> +\t\t\tinit \\\n> >>  \t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n> >\n> > This breaks GIT_TEST_INSTALLED when the given Git version doesn't yet\n> > contain 8b1fa77867 (Allow passing of configuration parameters in the\n> > command line, 2010-03-26):\n> \n> Yes, but test-installed is about running an old version of Git on\n> the current Git test suite.  In the tests we make liberal use of\n> \"git -c <var>=<val>\", which such an old version of Git has no chance\n> of passing.  So...\n\nI've never run the whole test suite with GIT_TEST_INSTALLED for the\nexact reason you mentioned.  However, I do regularly use it with\ncustom tests using only commands and options that already existed as\nearly as v1.6.0 (my go-to \"old\" version) to check when some\ninteresting or puzzling behavior appeared, and did just that yesterday\nas well.\n\n"}]}