{"thread":{"id":"53651","subject":"[PATCH 0/9] Allow overriding the default name of the default branch","startedAt":"2020-06-10T21:19:37Z","lastAt":"2020-07-14T14:55:44Z","messageCount":180,"participants":["Johannes Schindelin via GitGitGadget","Don Goodman-Wilson via GitGitGadget","Matt Rogers","Junio C Hamano","brian m. carlson","Eric Sunshine","Taylor Blau","Phillip Wood","Alban Gruin","Johannes Schindelin","Johannes Sixt","Pratyush Yadav","Denton Liu","Junio C Hamano via GitGitGadget","Ævar Arnfjörð Bjarmason","Jeff King","Elijah Newren","Philippe Blain","Đoàn Trần Công Danh","Edward Thomson"],"isPatch":true,"patchVersion":1,"patchTotal":9},"messages":[{"id":"399451","messageId":"pull.656.git.1591823971.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":null,"subject":"[PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-10T21:19:21Z","receivedAt":"2020-06-10T21:19:37Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"A growing number of open source projects aims to avoid the branch name \nmaster due to its negative connotation. See [1] for an existing discussion\non this. The links [2], [3], and [4] describe community-driven ways for\nusers to rename their default branches or use template edits to set a new\ndefault branch name.\n\n[1] \nhttps://lore.kernel.org/git/CAOAHyQwyXC1Z3v7BZAC+Bq6JBaM7FvBenA-1fcqeDV==apdWDg@mail.gmail.com/\n\n[2] https://twitter.com/mislav/status/1270388510684598272\n\n[3] \nhttps://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx\n\n[4] https://github.com/ethomson/retarget_prs\n\nBy necessity, existing repositories require a lot of manual work to move\naway from that branch name, but it should be much easier for new\nrepositories.\n\nThis patch series allows overriding the branch name being used for new\nrepositories' main branch. The main way to do this is the new \ncore.defaultBranchName config option. This first patch was contributed by\nnewcomer Dan Goodman-Wilson. Thanks for the contribution!\n\nThe other patches follow other places where \"master\" is hard-coded and use\nthe new git_default_branch_name() method to consume the config option before\nfalling back to \"master\".\n\nThe last patch updates documentation only after the config option is ready\nto apply to all of these scenarios.\n\nThis series DOES NOT change the default automatically, but only provides an\nopt-in mechanism for interested users. It also presents a way forward for\nsuch a transition, if and when we decide to do so. Specifically, the new\nGIT_TEST_DEFAULT_BRANCH_NAME environment variable could be used to update\ntest scripts on an individual basis instead of all-at-once.\n\nDon Goodman-Wilson (1):\n  init: allow overriding the default branch name for new repositories\n\nJohannes Schindelin (8):\n  remote: respect `core.defaultBranchName`\n  send-pack/transport-helper: respect `core.defaultBranchName`\n  testsvn: respect `core.defaultBranchName`\n  submodule: use the (possibly overridden) default branch name\n  clone: learn about the possibly-configured default branch name\n  fmt-merge-msg: learn about the possibly-configured default branch name\n  fast-export: respect the possibly-overridden default branch name\n  Document how the default branch name can be overridden\n\n Documentation/config/core.txt |  4 ++++\n builtin/clone.c               | 14 +++++++++++---\n builtin/fast-export.c         | 10 +++++++---\n builtin/init-db.c             |  8 +++++---\n builtin/submodule--helper.c   | 10 ++++++++--\n fmt-merge-msg.c               |  6 ++++--\n refs.c                        | 34 ++++++++++++++++++++++++++++++++++\n refs.h                        |  6 ++++++\n remote-testsvn.c              | 11 ++++++++---\n remote.c                      | 12 ++++++++----\n send-pack.c                   |  6 +++++-\n t/README                      |  4 ++++\n t/t0001-init.sh               | 20 ++++++++++++++++++++\n t/t5609-clone-branch.sh       |  9 +++++++++\n t/t6200-fmt-merge-msg.sh      |  8 ++++++++\n transport-helper.c            |  6 +++++-\n 16 files changed, 146 insertions(+), 22 deletions(-)\n\n\nbase-commit: 0313f36c6ebecb3bffe6f15cf25a4883100f0214\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-656%2Fdscho%2Fdefault-branch-name-option-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-656/dscho/default-branch-name-option-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/656\n-- \ngitgitgadget\n"},{"id":"399452","messageId":"90912e32da1192cfc3b39a18cb606caa46e85b1c.1591823971.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"[PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Don Goodman-Wilson via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-10T21:19:22Z","receivedAt":"2020-06-10T21:19:38Z","isPatch":true,"sender":{"key":"don@goodman-wilson.com","avatar":"https://gravatar.com/avatar/9819ec326d55ea4c398b8ff018dcf63b4e9603b00db9cc019c725bffc9c05d17?d=mp&s=160"},"body":"From: Don Goodman-Wilson <don@goodman-wilson.com>\n\nThere is a growing number of projects trying to avoid the non-inclusive\nname `master` in their repositories. For existing repositories, this\nrequires manual work. For new repositories, the only way to do that\nautomatically is by copying all of Git's template directory, then\nhard-coding the desired default branch name into the `.git/HEAD` file,\nand then configuring `init.templateDir` to point to those copied\ntemplate files.\n\nTo make this process much less cumbersome, let's introduce support for\n`core.defaultBranchName`. That way, users won't need to keep their\ncopied template files up to date, and won't interfere with default hooks\ninstalled by their administrators.\n\nWhile at it, also let users set the default branch name via the\nenvironment variable `GIT_TEST_DEFAULT_BRANCH_NAME`, in preparation for\nadjusting Git's test suite to a more inclusive default branch name. As\nis common in Git, the `GIT_TEST_*` variable takes precedence over the\nconfig setting.\n\nNote: we use the prefix `core.` instead of `init.` because we want to\nadjust also `git clone`, `git fmt-merge-msg` and other commands over the\ncourse of the next commits to respect this setting.\n\nHelped-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nHelped-by: Derrick Stolee <dstolee@microsoft.com>\nSigned-off-by: Don Goodman-Wilson <don@goodman-wilson.com>\n---\n builtin/init-db.c |  8 +++++---\n refs.c            | 34 ++++++++++++++++++++++++++++++++++\n refs.h            |  6 ++++++\n t/t0001-init.sh   | 20 ++++++++++++++++++++\n 4 files changed, 65 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 0b7222e7188..99792adfd43 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -258,15 +258,17 @@ static int create_default_files(const char *template_path,\n \t\tdie(\"failed to set up refs db: %s\", err.buf);\n \n \t/*\n-\t * Create the default symlink from \".git/HEAD\" to the \"master\"\n-\t * branch, if it does not exist yet.\n+\t * Create the default symlink from \".git/HEAD\" to the default\n+\t * branch name, if it does not exist yet.\n \t */\n \tpath = git_path_buf(&buf, \"HEAD\");\n \treinit = (!access(path, R_OK)\n \t\t  || readlink(path, junk, sizeof(junk)-1) != -1);\n \tif (!reinit) {\n-\t\tif (create_symref(\"HEAD\", \"refs/heads/master\", NULL) < 0)\n+\t\tchar *default_ref = git_default_branch_name(0);\n+\t\tif (create_symref(\"HEAD\", default_ref, NULL) < 0)\n \t\t\texit(1);\n+\t\tfree(default_ref);\n \t}\n \n \tinitialize_repository_version(fmt->hash_algo);\ndiff --git a/refs.c b/refs.c\nindex 224ff66c7bb..8499b3865cb 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -560,6 +560,40 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n \t\targv_array_pushf(prefixes, *p, len, prefix);\n }\n \n+char *git_default_branch_name(int short_name)\n+{\n+\tconst char *branch_name = getenv(\"GIT_TEST_DEFAULT_BRANCH_NAME\");\n+\tchar *from_config = NULL, *prefixed;\n+\n+\t/*\n+\t * If the default branch name was not specified via the environment\n+\t * variable GIT_TEST_DEFAULT_BRANCH_NAME, retrieve it from the config\n+\t * setting core.defaultBranchName. If neither are set, fall back to the\n+\t * hard-coded default.\n+\t */\n+\tif (!branch_name || !*branch_name) {\n+\t\tif (git_config_get_string(\"core.defaultbranchname\",\n+\t\t\t\t\t  &from_config) < 0)\n+\t\t\tdie(_(\"Could not retrieve `core.defaultBranchName`\"));\n+\n+\t\tif (from_config)\n+\t\t\tbranch_name = from_config;\n+\t\telse\n+\t\t\tbranch_name = \"master\";\n+\t}\n+\n+\tif (short_name)\n+\t\treturn from_config ? from_config : xstrdup(branch_name);\n+\n+\t/* prepend \"refs/heads/\" to the branch name */\n+\tprefixed = xstrfmt(\"refs/heads/%s\", branch_name);\n+\tif (check_refname_format(prefixed, 0))\n+\t\tdie(_(\"invalid default branch name: '%s'\"), branch_name);\n+\n+\tfree(from_config);\n+\treturn prefixed;\n+}\n+\n /*\n  * *string and *len will only be substituted, and *string returned (for\n  * later free()ing) if the string passed in is a magic short-hand form\ndiff --git a/refs.h b/refs.h\nindex a92d2c74c83..e8d4f6e2f13 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -154,6 +154,12 @@ int repo_dwim_log(struct repository *r, const char *str, int len, struct object_\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \n+/*\n+ * Retrieves the name of the default branch. If `short_name` is non-zero, the\n+ * branch name will be prefixed with \"refs/heads/\".\n+ */\n+char *git_default_branch_name(int short_name);\n+\n /*\n  * A ref_transaction represents a collection of reference updates that\n  * should succeed or fail together.\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 1edd5aeb8f0..b144cd8f46b 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -464,4 +464,24 @@ test_expect_success MINGW 'redirect std handles' '\n \tgrep \"Needed a single revision\" output.txt\n '\n \n+test_expect_success 'custom default branch name from config' '\n+\tgit config --global core.defaultbranchname nmb &&\n+\tGIT_TEST_DEFAULT_BRANCH_NAME= git init custom-config &&\n+\tgit config --global --unset core.defaultbranchname &&\n+\tgit -C custom-config symbolic-ref HEAD >actual &&\n+\tgrep nmb actual\n+'\n+\n+test_expect_success 'custom default branch name from env' '\n+\tGIT_TEST_DEFAULT_BRANCH_NAME=nmb git init custom-env &&\n+\tgit -C custom-env symbolic-ref HEAD >actual &&\n+\tgrep nmb actual\n+'\n+\n+test_expect_success 'invalid custom default branch name' '\n+\ttest_must_fail env GIT_TEST_DEFAULT_BRANCH_NAME=\"with space\" \\\n+\t\tgit init custom-invalid 2>err &&\n+\ttest_i18ngrep \"invalid default branch name\" err\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"399453","messageId":"c9c9c81068e24972e084956aa3b09a3ec0eb98c1.1591823971.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"[PATCH 3/9] send-pack/transport-helper: respect `core.defaultBranchName`","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-10T21:19:24Z","receivedAt":"2020-06-10T21:19: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\nWhen mentioning the default branch name in an error message, we want to\ngo with the preference specified by the user.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n send-pack.c        | 6 +++++-\n transport-helper.c | 6 +++++-\n 2 files changed, 10 insertions(+), 2 deletions(-)\n\ndiff --git a/send-pack.c b/send-pack.c\nindex 0abee22283d..f7747bed1c9 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -405,8 +405,12 @@ int send_pack(struct send_pack_args *args,\n \t}\n \n \tif (!remote_refs) {\n+\t\tchar *branch_name = git_default_branch_name(1);\n+\n \t\tfprintf(stderr, \"No refs in common and none specified; doing nothing.\\n\"\n-\t\t\t\"Perhaps you should specify a branch such as 'master'.\\n\");\n+\t\t\t\"Perhaps you should specify a branch such as '%s'.\\n\",\n+\t\t\tbranch_name);\n+\t\tfree(branch_name);\n \t\treturn 0;\n \t}\n \tif (args->atomic && !atomic_supported)\ndiff --git a/transport-helper.c b/transport-helper.c\nindex a46afcb69db..cc8ae5c67ca 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -1044,9 +1044,13 @@ static int push_refs(struct transport *transport,\n \t}\n \n \tif (!remote_refs) {\n+\t\tchar *branch_name = git_default_branch_name(1);\n+\n \t\tfprintf(stderr,\n \t\t\t_(\"No refs in common and none specified; doing nothing.\\n\"\n-\t\t\t  \"Perhaps you should specify a branch such as 'master'.\\n\"));\n+\t\t\t  \"Perhaps you should specify a branch such as '%s'.\\n\"),\n+\t\t\tbranch_name);\n+\t\tfree(branch_name);\n \t\treturn 0;\n \t}\n \n-- \ngitgitgadget\n\n"},{"id":"399454","messageId":"06a2cea051c01ebee38c9910425171f112daf41a.1591823971.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"[PATCH 2/9] remote: respect `core.defaultBranchName`","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-10T21:19:23Z","receivedAt":"2020-06-10T21:19: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\nWhen guessing the default branch name of a remote, and there are no refs\nto guess from, we want to go with the preference specified by the user\nfor the fall-back.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n remote.c | 12 ++++++++----\n 1 file changed, 8 insertions(+), 4 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex 534c6426f1e..95fa8cc78e0 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -256,7 +256,7 @@ static void read_remotes_file(struct remote *remote)\n \n static void read_branches_file(struct remote *remote)\n {\n-\tchar *frag;\n+\tchar *frag, *default_branch_name = NULL;\n \tstruct strbuf buf = STRBUF_INIT;\n \tFILE *f = fopen_or_warn(git_path(\"branches/%s\", remote->name), \"r\");\n \n@@ -276,7 +276,7 @@ static void read_branches_file(struct remote *remote)\n \n \t/*\n \t * The branches file would have URL and optionally\n-\t * #branch specified.  The \"master\" (or specified) branch is\n+\t * #branch specified.  The default (or specified) branch is\n \t * fetched and stored in the local branch matching the\n \t * remote name.\n \t */\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 = \"master\";\n+\t\tfrag = default_branch_name = git_default_branch_name(1);\n \n \tadd_url_alias(remote, strbuf_detach(&buf, NULL));\n \tstrbuf_addf(&buf, \"refs/heads/%s:refs/heads/%s\",\n@@ -299,6 +299,7 @@ static void read_branches_file(struct remote *remote)\n \tstrbuf_addf(&buf, \"HEAD:refs/heads/%s\", frag);\n \trefspec_append(&remote->push, buf.buf);\n \tremote->fetch_tags = 1; /* always auto-follow */\n+\tfree(default_branch_name);\n \tstrbuf_release(&buf);\n }\n \n@@ -2099,7 +2100,10 @@ struct ref *guess_remote_head(const struct ref *head,\n \n \t/* If refs/heads/master could be right, it is. */\n \tif (!all) {\n-\t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n+\t\tchar *name = git_default_branch_name(0);\n+\n+\t\tr = find_ref_by_name(refs, name);\n+\t\tfree(name);\n \t\tif (r && oideq(&r->old_oid, &head->old_oid))\n \t\t\treturn copy_ref(r);\n \t}\n-- \ngitgitgadget\n\n"},{"id":"399455","messageId":"e849def4a8c5cc291839ef4514a386df0c148b2e.1591823971.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"[PATCH 7/9] fmt-merge-msg: learn about the possibly-configured default branch name","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-10T21:19:28Z","receivedAt":"2020-06-10T21:19:44Z","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\nWhen formatting the commit message for merge commits, Git appends \"into\n<branch-name>\" unless the current branch is the default branch.\n\nNow that we can configure what the default branch name should be, we\nwill want to respect that setting in that scenario rather than using the\ncompiled-in default branch name.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n fmt-merge-msg.c          | 6 ++++--\n t/t6200-fmt-merge-msg.sh | 8 ++++++++\n 2 files changed, 12 insertions(+), 2 deletions(-)\n\ndiff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\nindex 72d32bd73b1..5e5c1d86f1c 100644\n--- a/fmt-merge-msg.c\n+++ b/fmt-merge-msg.c\n@@ -407,7 +407,7 @@ static void fmt_merge_msg_title(struct strbuf *out,\n \t\t\t\tconst char *current_branch)\n {\n \tint i = 0;\n-\tchar *sep = \"\";\n+\tchar *sep = \"\", *default_branch_name;\n \n \tstrbuf_addstr(out, \"Merge \");\n \tfor (i = 0; i < srcs.nr; i++) {\n@@ -451,10 +451,12 @@ static void fmt_merge_msg_title(struct strbuf *out,\n \t\t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n \t}\n \n-\tif (!strcmp(\"master\", current_branch))\n+\tdefault_branch_name = git_default_branch_name(1);\n+\tif (!strcmp(default_branch_name, current_branch))\n \t\tstrbuf_addch(out, '\\n');\n \telse\n \t\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n+\tfree(default_branch_name);\n }\n \n static void fmt_tag_signature(struct strbuf *tagbuf,\ndiff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh\nindex e4c2a6eca43..a23cd157ffd 100755\n--- a/t/t6200-fmt-merge-msg.sh\n+++ b/t/t6200-fmt-merge-msg.sh\n@@ -158,6 +158,14 @@ test_expect_success 'setup FETCH_HEAD' '\n \tgit fetch . left\n '\n \n+test_expect_success 'with overridden default branch name' '\n+\ttest_config core.defaultBranchName default &&\n+\ttest_when_finished \"git switch master\" &&\n+\tgit switch -c default &&\n+\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n+\t! grep \"into default\" actual\n+'\n+\n test_expect_success 'merge.log=3 limits shortlog length' '\n \tcat >expected <<-EOF &&\n \tMerge branch ${apos}left${apos}\n-- \ngitgitgadget\n\n"},{"id":"399456","messageId":"cce86c06bbf459ecbfddf21b1417bacc12315e3e.1591823971.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"[PATCH 6/9] clone: learn about the possibly-configured default branch name","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-10T21:19:27Z","receivedAt":"2020-06-10T21:19:45Z","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\nWhen cloning a repository without any branches, Git chooses a default\nbranch name for the as-yet unborn branch.\n\nNow that we can configure what the default branch name should be, we\nwill want `git clone` to respect that setting.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/clone.c         | 14 +++++++++++---\n t/t5609-clone-branch.sh |  9 +++++++++\n 2 files changed, 20 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex cb48a291caf..a21d3e99f82 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -1263,9 +1263,17 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\tremote_head_points_at = NULL;\n \t\tremote_head = NULL;\n \t\toption_no_checkout = 1;\n-\t\tif (!option_bare)\n-\t\t\tinstall_branch_config(0, \"master\", option_origin,\n-\t\t\t\t\t      \"refs/heads/master\");\n+\t\tif (!option_bare) {\n+\t\t\tchar *default_branch = git_default_branch_name(0);\n+\t\t\tconst char *nick;\n+\n+\t\t\tif (!skip_prefix(default_branch, \"refs/heads/\", &nick))\n+\t\t\t\tBUG(\"unexpected default branch '%s'\",\n+\t\t\t\t    default_branch);\n+\t\t\tinstall_branch_config(0, nick, option_origin,\n+\t\t\t\t\t      default_branch);\n+\t\t\tfree(default_branch);\n+\t\t}\n \t}\n \n \twrite_refspec_config(src_ref_prefix, our_head_points_at,\ndiff --git a/t/t5609-clone-branch.sh b/t/t5609-clone-branch.sh\nindex 6e7a7be0522..66af3ac2669 100755\n--- a/t/t5609-clone-branch.sh\n+++ b/t/t5609-clone-branch.sh\n@@ -67,4 +67,13 @@ test_expect_success 'clone -b not allowed with empty repos' '\n \ttest_must_fail git clone -b branch empty clone-branch-empty\n '\n \n+test_expect_success 'chooses correct default branch name' '\n+\tGIT_TEST_DEFAULT_BRANCH_NAME= \\\n+\t\tgit -c core.defaultBranchName=up clone empty whats-up &&\n+\ttest_write_lines refs/heads/up refs/heads/up >expect &&\n+\tgit -C whats-up symbolic-ref HEAD >actual &&\n+\tgit -C whats-up config branch.up.merge >>actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"399457","messageId":"1efe848f2b029e572cea61cadcfe36b9d3797836.1591823971.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"[PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-10T21:19:29Z","receivedAt":"2020-06-10T21:19:46Z","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\nWhen anonymizing commit history, we are careful to leave the branch name\nof the default branch alone.\n\nWhen the default branch name is overridden via the config or via the\nenvironment variable, we will want `git fast-export` to use that\noverridden name instead.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/fast-export.c | 10 +++++++---\n 1 file changed, 7 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 85868162eec..028dd9969a2 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -515,13 +515,17 @@ static const char *anonymize_refname(const char *refname)\n \t};\n \tstatic struct hashmap refs;\n \tstatic struct strbuf anon = STRBUF_INIT;\n+\tstatic char *default_branch_name;\n \tint i;\n \n \t/*\n-\t * We also leave \"master\" as a special case, since it does not reveal\n-\t * anything interesting.\n+\t * We also leave the default branch name as a special case, since it\n+\t * does not reveal anything interesting.\n \t */\n-\tif (!strcmp(refname, \"refs/heads/master\"))\n+\tif (!default_branch_name)\n+\t\tdefault_branch_name = git_default_branch_name(0);\n+\n+\tif (!strcmp(refname, default_branch_name))\n \t\treturn refname;\n \n \tstrbuf_reset(&anon);\n-- \ngitgitgadget\n\n"},{"id":"399458","messageId":"f680e66dd6ddfc5294d04ddd11d4b2bd4ec1520c.1591823971.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"[PATCH 9/9] Document how the default branch name can be overridden","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-10T21:19:30Z","receivedAt":"2020-06-10T21:19:48Z","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\nThere is a `GIT_TEST_*` environment variable and a `core.` config\nsetting (with the former taking precendence over the latter) to allow\noverriding what name Git uses by default as main branch of new\nrepositories.\n\nNow that all kinds of Git operations have learned to respect those,\nlet's document them.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/config/core.txt | 4 ++++\n t/README                      | 4 ++++\n 2 files changed, 8 insertions(+)\n\ndiff --git a/Documentation/config/core.txt b/Documentation/config/core.txt\nindex 74619a9c03b..a11e1abdf59 100644\n--- a/Documentation/config/core.txt\n+++ b/Documentation/config/core.txt\n@@ -626,3 +626,7 @@ core.abbrev::\n \tin your repository, which hopefully is enough for\n \tabbreviated object names to stay unique for some time.\n \tThe minimum length is 4.\n+\n+core.defaultBranchName::\n+\tAllows overriding the default branch name e.g. when initializing\n+\ta new repository or when cloning an empty repository.\ndiff --git a/t/README b/t/README\nindex cf863837ab9..b32f520a27f 100644\n--- a/t/README\n+++ b/t/README\n@@ -421,6 +421,10 @@ GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=<boolean>, when true (which is\n the default when running tests), errors out when an abbreviated option\n is used.\n \n+GIT_TEST_DEFAULT_BRANCH_NAME allows overriding the default branch name\n+that is used for example when initializing new repositories, or when\n+cloning a repository that has no branches yet.\n+\n Naming Tests\n ------------\n \n-- \ngitgitgadget\n"},{"id":"399459","messageId":"06ef42052d534a668bf5227e79f1ca3b5c6aa2c1.1591823971.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"[PATCH 5/9] submodule: use the (possibly overridden) default branch name","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-10T21:19:26Z","receivedAt":"2020-06-10T21:19:49Z","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 allow for overriding the default branch name, we have introduced a\nconfig setting. With this patch, the `git submodule` command learns\nabout this, too.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/submodule--helper.c | 10 ++++++++--\n 1 file changed, 8 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 46c03d2a126..0b4abb5a64b 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1980,8 +1980,14 @@ static const char *remote_submodule_branch(const char *path)\n \t\tbranch = sub->branch;\n \tfree(key);\n \n-\tif (!branch)\n-\t\treturn \"master\";\n+\tif (!branch) {\n+\t\tstatic char *default_branch;\n+\n+\t\tif (!default_branch)\n+\t\t\tdefault_branch = git_default_branch_name(1);\n+\n+\t\treturn default_branch;\n+\t}\n \n \tif (!strcmp(branch, \".\")) {\n \t\tconst char *refname = resolve_ref_unsafe(\"HEAD\", 0, NULL, NULL);\n-- \ngitgitgadget\n\n"},{"id":"399460","messageId":"73cb567cd33e29d22f1a6b853925c68282da5298.1591823971.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"[PATCH 4/9] testsvn: respect `core.defaultBranchName`","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-10T21:19:25Z","receivedAt":"2020-06-10T21:19:51Z","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\nSince the default branch name can now be configured, the `testsvn`\nremote helper needs to be told about it.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n remote-testsvn.c | 11 ++++++++---\n 1 file changed, 8 insertions(+), 3 deletions(-)\n\ndiff --git a/remote-testsvn.c b/remote-testsvn.c\nindex 3af708c5b67..a48d74f35cd 100644\n--- a/remote-testsvn.c\n+++ b/remote-testsvn.c\n@@ -13,7 +13,7 @@\n static const char *url;\n static int dump_from_file;\n static const char *private_ref;\n-static const char *remote_ref = \"refs/heads/master\";\n+static char *remote_ref;\n static const char *marksfilename, *notes_ref;\n struct rev_note { unsigned int rev_nr; };\n \n@@ -286,7 +286,7 @@ int cmd_main(int argc, const char **argv)\n \t\t\tprivate_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT,\n \t\t\tnotes_ref_sb = STRBUF_INIT;\n \tstatic struct remote *remote;\n-\tconst char *url_in;\n+\tconst char *url_in, *default_branch;\n \n \tsetup_git_directory();\n \tif (argc < 2 || argc > 3) {\n@@ -294,6 +294,10 @@ int cmd_main(int argc, const char **argv)\n \t\treturn 1;\n \t}\n \n+\tremote_ref = git_default_branch_name(0);\n+\tif (!skip_prefix(remote_ref, \"refs/heads/\", &default_branch))\n+\t\tBUG(\"unexpected remote_ref '%s'\", remote_ref);\n+\n \tremote = remote_get(argv[1]);\n \turl_in = (argc == 3) ? argv[2] : remote->url[0];\n \n@@ -306,7 +310,8 @@ int cmd_main(int argc, const char **argv)\n \t\turl = url_sb.buf;\n \t}\n \n-\tstrbuf_addf(&private_ref_sb, \"refs/svn/%s/master\", remote->name);\n+\tstrbuf_addf(&private_ref_sb, \"refs/svn/%s/%s\",\n+\t\t    remote->name, default_branch);\n \tprivate_ref = private_ref_sb.buf;\n \n \tstrbuf_addf(&notes_ref_sb, \"refs/notes/%s/revs\", remote->name);\n-- \ngitgitgadget\n\n"},{"id":"399462","messageId":"CAOjrSZvm9QNUttUNVBEUMPJ8zgYEoAnSPN5_6N5uwpiM1sVrcQ@mail.gmail.com","threadId":"53651","inReplyTo":"1efe848f2b029e572cea61cadcfe36b9d3797836.1591823971.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Matt Rogers","fromEmail":"mattr94@gmail.com","sentAt":"2020-06-10T21:54:01Z","receivedAt":"2020-06-10T21:54:14Z","isPatch":true,"sender":{"key":"mattr94@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5719846?v=4"},"body":"> -        * We also leave \"master\" as a special case, since it does not reveal\n> -        * anything interesting.\n> +        * We also leave the default branch name as a special case, since it\n> +        * does not reveal anything interesting.\n>          */\nI feel this is a weird thing to do, since you're trying to anonymize the branch\nname,and now the default branch is identifiable with your config file.  For\nexample, if the default branch contains the name of my project/repo then this\nsounds like a recipe for accidentally sharing it. I feel a better\nalternative would\nbe to exclude nothing from the anonymization or the proposed default default\nbranch name\n\n\n> -       if (!strcmp(refname, \"refs/heads/master\"))\n> +       if (!default_branch_name)\n> +               default_branch_name = git_default_branch_name(0);\n> +\n> +       if (!strcmp(refname, default_branch_name))\n>                 return refname;\n>\n>         strbuf_reset(&anon);\n> --\n> gitgitgadget\n>\n\n\n-- \nMatthew Rogers\n"},{"id":"399467","messageId":"xmqqsgf2eden.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"cce86c06bbf459ecbfddf21b1417bacc12315e3e.1591823971.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 6/9] clone: learn about the possibly-configured default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-10T22:58:40Z","receivedAt":"2020-06-10T22:58:49Z","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> @@ -1263,9 +1263,17 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n>  \t\tremote_head_points_at = NULL;\n>  \t\tremote_head = NULL;\n>  \t\toption_no_checkout = 1;\n> -\t\tif (!option_bare)\n> -\t\t\tinstall_branch_config(0, \"master\", option_origin,\n> -\t\t\t\t\t      \"refs/heads/master\");\n> +\t\tif (!option_bare) {\n> +\t\t\tchar *default_branch = git_default_branch_name(0);\n> +\t\t\tconst char *nick;\n> +\n> +\t\t\tif (!skip_prefix(default_branch, \"refs/heads/\", &nick))\n> +\t\t\t\tBUG(\"unexpected default branch '%s'\",\n> +\t\t\t\t    default_branch);\n> +\t\t\tinstall_branch_config(0, nick, option_origin,\n> +\t\t\t\t\t      default_branch);\n> +\t\t\tfree(default_branch);\n> +\t\t}\n\nGood catch.  Normal clone would follow whatever primary branch the\nother side uses by pointing at it with its \"HEAD\" but this codepath\nto deal with a clone of an empty repository needs to use a default,\nso this is an appropriate change.\n\n>  \twrite_refspec_config(src_ref_prefix, our_head_points_at,\n> diff --git a/t/t5609-clone-branch.sh b/t/t5609-clone-branch.sh\n> index 6e7a7be0522..66af3ac2669 100755\n> --- a/t/t5609-clone-branch.sh\n> +++ b/t/t5609-clone-branch.sh\n> @@ -67,4 +67,13 @@ test_expect_success 'clone -b not allowed with empty repos' '\n>  \ttest_must_fail git clone -b branch empty clone-branch-empty\n>  '\n>  \n> +test_expect_success 'chooses correct default branch name' '\n> +\tGIT_TEST_DEFAULT_BRANCH_NAME= \\\n> +\t\tgit -c core.defaultBranchName=up clone empty whats-up &&\n> +\ttest_write_lines refs/heads/up refs/heads/up >expect &&\n> +\tgit -C whats-up symbolic-ref HEAD >actual &&\n> +\tgit -C whats-up config branch.up.merge >>actual &&\n> +\ttest_cmp expect actual\n> +'\n> +\n>  test_done\n"},{"id":"399468","messageId":"xmqqo8pqedcg.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"e849def4a8c5cc291839ef4514a386df0c148b2e.1591823971.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 7/9] fmt-merge-msg: learn about the possibly-configured default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-10T22:59:59Z","receivedAt":"2020-06-10T23:00: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> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n>\n> When formatting the commit message for merge commits, Git appends \"into\n> <branch-name>\" unless the current branch is the default branch.\n>\n> Now that we can configure what the default branch name should be, we\n> will want to respect that setting in that scenario rather than using the\n> compiled-in default branch name.\n>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>  fmt-merge-msg.c          | 6 ++++--\n>  t/t6200-fmt-merge-msg.sh | 8 ++++++++\n>  2 files changed, 12 insertions(+), 2 deletions(-)\n>\n> diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\n> index 72d32bd73b1..5e5c1d86f1c 100644\n> --- a/fmt-merge-msg.c\n> +++ b/fmt-merge-msg.c\n> @@ -407,7 +407,7 @@ static void fmt_merge_msg_title(struct strbuf *out,\n>  \t\t\t\tconst char *current_branch)\n>  {\n>  \tint i = 0;\n> -\tchar *sep = \"\";\n> +\tchar *sep = \"\", *default_branch_name;\n>  \n>  \tstrbuf_addstr(out, \"Merge \");\n>  \tfor (i = 0; i < srcs.nr; i++) {\n> @@ -451,10 +451,12 @@ static void fmt_merge_msg_title(struct strbuf *out,\n>  \t\t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n>  \t}\n>  \n> -\tif (!strcmp(\"master\", current_branch))\n> +\tdefault_branch_name = git_default_branch_name(1);\n> +\tif (!strcmp(default_branch_name, current_branch))\n>  \t\tstrbuf_addch(out, '\\n');\n>  \telse\n>  \t\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n> +\tfree(default_branch_name);\n>  }\n\nGood.  J6t reminded me earlier about this one when I said \"except\nfor 'init' and 'clone' (when it cannot tell what primary branch the\nsource of the clone uses), we do not need a hardcoded 'master'\", and\nthe series covers this case.  Very pleased.\n\n\n>  static void fmt_tag_signature(struct strbuf *tagbuf,\n> diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh\n> index e4c2a6eca43..a23cd157ffd 100755\n> --- a/t/t6200-fmt-merge-msg.sh\n> +++ b/t/t6200-fmt-merge-msg.sh\n> @@ -158,6 +158,14 @@ test_expect_success 'setup FETCH_HEAD' '\n>  \tgit fetch . left\n>  '\n>  \n> +test_expect_success 'with overridden default branch name' '\n> +\ttest_config core.defaultBranchName default &&\n> +\ttest_when_finished \"git switch master\" &&\n> +\tgit switch -c default &&\n> +\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n> +\t! grep \"into default\" actual\n> +'\n> +\n>  test_expect_success 'merge.log=3 limits shortlog length' '\n>  \tcat >expected <<-EOF &&\n>  \tMerge branch ${apos}left${apos}\n"},{"id":"399469","messageId":"xmqqk10eecsg.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-10T23:11:59Z","receivedAt":"2020-06-10T23:12:05Z","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> A growing number of open source projects aims to avoid the branch name \n> master due to its negative connotation. See [1] for an existing discussion\n> on this. The links [2], [3], and [4] describe community-driven ways for\n> users to rename their default branches or use template edits to set a new\n> default branch name.\n\nI scanned the series quickly and the patches seem to cover all the\nplaces I was aware of that has the hard-coded knowledge of the\ndefault branch name being 'master'.  Looking good.\n\n> This series DOES NOT change the default automatically, but only provides an\n> opt-in mechanism for interested users. It also presents a way forward for\n> such a transition, if and when we decide to do so. Specifically, the new\n> GIT_TEST_DEFAULT_BRANCH_NAME environment variable could be used to update\n> test scripts on an individual basis instead of all-at-once.\n\nYes.  I've been thinking about a way that does not hurt workflows\nused in existing projects while allowing a \"git init\" that is run to\ncreate a new repository by a new user who does not have any special\ncustomization in ~/.gitconfig to use the branch name that replaces\nthe 'master' (I do not mind changing away from 'master', but I am\nnot yet convinced it should be 'main', by the way---the actual\nchoice of the final name does not matter at this point of the design\nof backward compatibility plan).  \n\nI think \"git init\" that is creating a new repository (iow, do not do\nanything when reinitializing an existing repostiory) can\n\n - look at config.defaultBranchName in /etc/gitconfig or\n   ~/.gitconfig before initializing the per-repository config in\n   $GIT_DIR/config it just created (or it is about to create).\n\n - if there is no config.defaultBranchName configured, then set the\n   per-repository configuration to 'main' in the per-repository\n   configuration.  Otherwise do not do anything.\n\nAnd then we make sure Don's git_default_branch_name() works this\nway:\n\n (0) if there is config.defaultBranchName in relevant config file\n     (i.e. /etc/gitconfig, ~/.gitconfig or per-repo config), use the\n     specified name.\n\n (1) otherwise use 'master' (not 'main').\n\nThat way, an existing repository will keep using 'master' unless the\nuser shows the preference (and accepts responsibilities for possible\nfallouts) in ~/.gitconfig or the repository's .git/config, while a\nnew repository created by a user who does not show any particular\npreference will use 'main'.\n\n\n"},{"id":"399473","messageId":"20200610232246.GT6569@camp.crustytoothpaste.net","threadId":"53651","inReplyTo":"90912e32da1192cfc3b39a18cb606caa46e85b1c.1591823971.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2020-06-10T23:22:46Z","receivedAt":"2020-06-10T23:23:24Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2020-06-10 at 21:19:22, Don Goodman-Wilson via GitGitGadget wrote:\n> +\t/* prepend \"refs/heads/\" to the branch name */\n> +\tprefixed = xstrfmt(\"refs/heads/%s\", branch_name);\n> +\tif (check_refname_format(prefixed, 0))\n> +\t\tdie(_(\"invalid default branch name: '%s'\"), branch_name);\n\nI'm glad to see this part and a check for it in the test below.  We\nwouldn't want a typo to create a broken branch name.\n\n> +test_expect_success 'invalid custom default branch name' '\n> +\ttest_must_fail env GIT_TEST_DEFAULT_BRANCH_NAME=\"with space\" \\\n> +\t\tgit init custom-invalid 2>err &&\n> +\ttest_i18ngrep \"invalid default branch name\" err\n> +'\n> +\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"399474","messageId":"xmqqbllqec5b.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"CAOjrSZvm9QNUttUNVBEUMPJ8zgYEoAnSPN5_6N5uwpiM1sVrcQ@mail.gmail.com","subject":"Re: [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-10T23:25:52Z","receivedAt":"2020-06-10T23:25:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matt Rogers <mattr94@gmail.com> writes:\n\n>> -        * We also leave \"master\" as a special case, since it does not reveal\n>> -        * anything interesting.\n>> +        * We also leave the default branch name as a special case, since it\n>> +        * does not reveal anything interesting.\n>>          */\n> I feel this is a weird thing to do, since you're trying to anonymize the branch\n> name,and now the default branch is identifiable with your config file.  For\n> example, if the default branch contains the name of my project/repo then this\n> sounds like a recipe for accidentally sharing it. I feel a better\n> alternative would\n> be to exclude nothing from the anonymization or the proposed default default\n> branch name\n\nI wonder if anything bad happens if we keep *no* refs intact in this\nfunction.  \"Since it does not reveal anything interesting\" is an\nexcuse why not munging it may be OK, but it does not explain why we\nprefer not munging it actively.\n\nIf there is no reason to keep _some_ refs as-is, I agree that it is\nperfectly sensible not to have this special case at all.\n\nThanks.\n\n>> -       if (!strcmp(refname, \"refs/heads/master\"))\n>> +       if (!default_branch_name)\n>> +               default_branch_name = git_default_branch_name(0);\n>> +\n>> +       if (!strcmp(refname, default_branch_name))\n>>                 return refname;\n>>\n>>         strbuf_reset(&anon);\n>> --\n>> gitgitgadget\n>>\n"},{"id":"399477","messageId":"20200610233912.GU6569@camp.crustytoothpaste.net","threadId":"53651","inReplyTo":"CAOjrSZvm9QNUttUNVBEUMPJ8zgYEoAnSPN5_6N5uwpiM1sVrcQ@mail.gmail.com","subject":"Re: [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2020-06-10T23:39:12Z","receivedAt":"2020-06-10T23:39:49Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2020-06-10 at 21:54:01, Matt Rogers wrote:\n> > -        * We also leave \"master\" as a special case, since it does not reveal\n> > -        * anything interesting.\n> > +        * We also leave the default branch name as a special case, since it\n> > +        * does not reveal anything interesting.\n> >          */\n> I feel this is a weird thing to do, since you're trying to anonymize the branch\n> name,and now the default branch is identifiable with your config file.  For\n> example, if the default branch contains the name of my project/repo then this\n> sounds like a recipe for accidentally sharing it. I feel a better\n> alternative would\n> be to exclude nothing from the anonymization or the proposed default default\n> branch name\n\nI think this is fine because it only reveals the name of your particular\nchoice of default branch.  The goal of the --anonymize option is to\nallow people to maintain the structure of their repositories while\nstripping private information from them, primarily for debugging\npurposes (e.g., providing to us for troubleshooting).\n\nThe things people want to prevent exposing are their code, data, project\nnames, user names, etc.: that is, anything identifying, privileged, or\nprivate.  The default branch name isn't any of those things; we know you\nhave one, and for troubleshooting purposes, we aren't that interested in\nwhat you called it.  You've almost certainly picked it out of a set of\none of 20 words that people use for this purpose, none of which are\nprivate, and all of which are shared by millions of other repositories.\n\nIn the extremely unlikely case that it does matter, invoking git with\nsomething like \"-c default.branch=$(git hash-object /dev/null)\" would be\nsufficient to anonymize all branches.\n\nI should point out that people frequently ask for the output of \"git\nconfig -l\" for troubleshooting, and most people wouldn't consider their\ndefault branch name to be worth sanitizing there.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"399478","messageId":"20200610234150.GV6569@camp.crustytoothpaste.net","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2020-06-10T23:41:50Z","receivedAt":"2020-06-10T23:42:27Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2020-06-10 at 21:19:21, Johannes Schindelin via GitGitGadget wrote:\n> A growing number of open source projects aims to avoid the branch name \n> master due to its negative connotation. See [1] for an existing discussion\n> on this. The links [2], [3], and [4] describe community-driven ways for\n> users to rename their default branches or use template edits to set a new\n> default branch name.\n> \n> [1] \n> https://lore.kernel.org/git/CAOAHyQwyXC1Z3v7BZAC+Bq6JBaM7FvBenA-1fcqeDV==apdWDg@mail.gmail.com/\n> \n> [2] https://twitter.com/mislav/status/1270388510684598272\n> \n> [3] \n> https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx\n> \n> [4] https://github.com/ethomson/retarget_prs\n> \n> By necessity, existing repositories require a lot of manual work to move\n> away from that branch name, but it should be much easier for new\n> repositories.\n> \n> This patch series allows overriding the branch name being used for new\n> repositories' main branch. The main way to do this is the new \n> core.defaultBranchName config option. This first patch was contributed by\n> newcomer Dan Goodman-Wilson. Thanks for the contribution!\n> \n> The other patches follow other places where \"master\" is hard-coded and use\n> the new git_default_branch_name() method to consume the config option before\n> falling back to \"master\".\n> \n> The last patch updates documentation only after the config option is ready\n> to apply to all of these scenarios.\n> \n> This series DOES NOT change the default automatically, but only provides an\n> opt-in mechanism for interested users. It also presents a way forward for\n> such a transition, if and when we decide to do so. Specifically, the new\n> GIT_TEST_DEFAULT_BRANCH_NAME environment variable could be used to update\n> test scripts on an individual basis instead of all-at-once.\n\nI've looked over this series, and I have no additional comments beyond\nwhat I've mentioned and what Junio pointed out at the end of the series.\nWith those provisos, I'm generally happy with it, and glad to see these\npatches hit the list.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"399482","messageId":"CAPig+cSnEvVB5vsffFXidG1-XNxDX10u2XhD9NqV3pwh8zyxxw@mail.gmail.com","threadId":"53651","inReplyTo":"90912e32da1192cfc3b39a18cb606caa46e85b1c.1591823971.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-06-11T00:16:38Z","receivedAt":"2020-06-11T00:16:54Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Wed, Jun 10, 2020 at 5:19 PM Don Goodman-Wilson via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n> [...]\n> To make this process much less cumbersome, let's introduce support for\n> `core.defaultBranchName`. That way, users won't need to keep their\n> copied template files up to date, and won't interfere with default hooks\n> installed by their administrators.\n> [...]\n> Signed-off-by: Don Goodman-Wilson <don@goodman-wilson.com>\n> ---\n> diff --git a/refs.c b/refs.c\n> @@ -560,6 +560,40 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n> +                       die(_(\"Could not retrieve `core.defaultBranchName`\"));\n\nNit: here the error message is capitalized...\n\n> +               if (from_config)\n> +                       branch_name = from_config;\n> +               else\n> +                       branch_name = \"master\";\n\nNon-actionable nit: could be written:\n\n    branch_name = from_config ? from_config : \"master\";\n\n> +       }\n> +\n> +       if (short_name)\n> +               return from_config ? from_config : xstrdup(branch_name);\n\nThe logic overall is a bit difficult to follow when trying to\nunderstand when and when not to duplicate the string and when and when\nnot to free(), but seems to be correct.\n\n> +       /* prepend \"refs/heads/\" to the branch name */\n> +       prefixed = xstrfmt(\"refs/heads/%s\", branch_name);\n> +       if (check_refname_format(prefixed, 0))\n> +               die(_(\"invalid default branch name: '%s'\"), branch_name);\n\nHere, the error message is not capitalized. It would be nice for both\nmessages to share a common capitalization scheme. These days, we tend\nto favor _not_ capitalizing error messages, so perhaps remove\ncapitalization from the earlier one.\n\n> +/*\n> + * Retrieves the name of the default branch. If `short_name` is non-zero, the\n> + * branch name will be prefixed with \"refs/heads/\".\n> + */\n> +char *git_default_branch_name(int short_name);\n\nOverall, the internal logic regarding duplicating/freeing strings\nwould probably be easier to grok if there were two separate functions:\n\n    char *git_default_branch_name(void);\n    char *git_default_ref_name(void);\n\nbut that's subjective.\n"},{"id":"399483","messageId":"xmqq3672e9p2.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"f680e66dd6ddfc5294d04ddd11d4b2bd4ec1520c.1591823971.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 9/9] Document how the default branch name can be overridden","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-11T00:18:49Z","receivedAt":"2020-06-11T00:18:58Z","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> diff --git a/Documentation/config/core.txt b/Documentation/config/core.txt\n> index 74619a9c03b..a11e1abdf59 100644\n> --- a/Documentation/config/core.txt\n> +++ b/Documentation/config/core.txt\n> @@ -626,3 +626,7 @@ core.abbrev::\n>  \tin your repository, which hopefully is enough for\n>  \tabbreviated object names to stay unique for some time.\n>  \tThe minimum length is 4.\n> +\n> +core.defaultBranchName::\n> +\tAllows overriding the default branch name e.g. when initializing\n> +\ta new repository or when cloning an empty repository.\n\nAs we saw in [PATCH 7/9], it also affects for which branch an\nauto-generated merge message omits \"into $branch\" at the end.\n\nThe behaviour change of \"merge\" might matter more than we think here\nin a hand-wavy way, and it certainly does affect more than 'init'\nand 'clone' (both of which are one time operation per repository),\nbecause setting this in ~/.gitconfig would affect all the\nrepositories, whose merges into their 'master' suddenly starts\nsaying \"into master\" at the end, unlike existing merges.  So it\nprobably is worth highlighting it here.\n\n> diff --git a/t/README b/t/README\n> index cf863837ab9..b32f520a27f 100644\n> --- a/t/README\n> +++ b/t/README\n> @@ -421,6 +421,10 @@ GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=<boolean>, when true (which is\n>  the default when running tests), errors out when an abbreviated option\n>  is used.\n>  \n> +GIT_TEST_DEFAULT_BRANCH_NAME allows overriding the default branch name\n> +that is used for example when initializing new repositories, or when\n> +cloning a repository that has no branches yet.\n> +\n>  Naming Tests\n>  ------------\n"},{"id":"399484","messageId":"CAOjrSZvV6+ApfmOBa7rdXDPQJbExRsOfodO16i_1N5QjjhCB1w@mail.gmail.com","threadId":"53651","inReplyTo":"20200610233912.GU6569@camp.crustytoothpaste.net","subject":"Re: [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Matt Rogers","fromEmail":"mattr94@gmail.com","sentAt":"2020-06-11T00:20:39Z","receivedAt":"2020-06-11T00:20:53Z","isPatch":true,"sender":{"key":"mattr94@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5719846?v=4"},"body":"> I think this is fine because it only reveals the name of your particular\n> choice of default branch.  The goal of the --anonymize option is to\n> allow people to maintain the structure of their repositories while\n> stripping private information from them, primarily for debugging\n> purposes (e.g., providing to us for troubleshooting).\n>\n> The things people want to prevent exposing are their code, data, project\n> names, user names, etc.: that is, anything identifying, privileged, or\n> private.  The default branch name isn't any of those things; we know you\n> have one, and for troubleshooting purposes, we aren't that interested in\n> what you called it.  You've almost certainly picked it out of a set of\n> one of 20 words that people use for this purpose, none of which are\n> private, and all of which are shared by millions of other repositories.\n>\n\nI think that's not very convincing.  If branch names in general are identifying\nenough to warrant anonymization then shouldn't the default name be too?\n\n> In the extremely unlikely case that it does matter, invoking git with\n> something like \"-c default.branch=$(git hash-object /dev/null)\" would be\n> sufficient to anonymize all branches.\n>\n> I should point out that people frequently ask for the output of \"git\n> config -l\" for troubleshooting, and most people wouldn't consider their\n> default branch name to be worth sanitizing there.\n\nI think this is a little presumptuous, most people wouldn't consider it to be\nworth sanitizing because there isn't currently such a config setting.  If I give\nyou the the output of \"git config -l\" then I think it's obvious that all of my\nconfiguration settings will be included (and therefore I can choose to sanitize\naccordingly), but if I'm giving an exported repository I think should be\nanonymized, but my default branch, which someone could innocently base on a\nproject or company name, could easily be accidentally included in that output\nwhich could lead to a frustrating experience\n\n\n> --\n> brian m. carlson: Houston, Texas, US\n> OpenPGP: https://keybase.io/bk2204\n\n\n\n-- \nMatthew Rogers\n"},{"id":"399488","messageId":"20200611010720.GA21728@syl.local","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2020-06-11T01:07:20Z","receivedAt":"2020-06-11T01:07:25Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Hi Johannes (and Dan)\n\nOn Wed, Jun 10, 2020 at 09:19:21PM +0000, Johannes Schindelin via GitGitGadget wrote:\n> A growing number of open source projects aims to avoid the branch name\n> master due to its negative connotation. See [1] for an existing discussion\n> on this. The links [2], [3], and [4] describe community-driven ways for\n> users to rename their default branches or use template edits to set a new\n> default branch name.\n>\n> [1]\n> https://lore.kernel.org/git/CAOAHyQwyXC1Z3v7BZAC+Bq6JBaM7FvBenA-1fcqeDV==apdWDg@mail.gmail.com/\n>\n> [2] https://twitter.com/mislav/status/1270388510684598272\n>\n> [3]\n> https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx\n>\n> [4] https://github.com/ethomson/retarget_prs\n>\n> By necessity, existing repositories require a lot of manual work to move\n> away from that branch name, but it should be much easier for new\n> repositories.\n\nThis is (somewhat) orthogonal to the topic here, but I wonder if we\ncould be doing anything to make this easier for users.\n\nCould servers remember that a branch has ``moved'' and alert users as\nsuch when they pull? Even better, it would be nice if this alert from\nthe server could allow clients to automatically rename their refs\nappropriately so that this transition is as easy as possible, even for\nexisting repositories.\n\n> This patch series allows overriding the branch name being used for new\n> repositories' main branch. The main way to do this is the new\n> core.defaultBranchName config option. This first patch was contributed by\n> newcomer Dan Goodman-Wilson. Thanks for the contribution!\n\nWelcome, Dan! This is a fantastic first contribution, and I would be\nhonored to help and move this forward in anyway that I can.\n\nI should note that I am technically \"out of office\" (which normally\nwouldn't mean much, but this time means that I am on a road-trip, and so\nam only at my computer infrequently). I am catching up on just a few\nemails here, but I'll be able to help out more (and would be honored to\ndo so) once I am really back next Monday.\n\n> The other patches follow other places where \"master\" is hard-coded and use\n> the new git_default_branch_name() method to consume the config option before\n> falling back to \"master\".\n>\n> The last patch updates documentation only after the config option is ready\n> to apply to all of these scenarios.\n>\n> This series DOES NOT change the default automatically, but only provides an\n> opt-in mechanism for interested users. It also presents a way forward for\n> such a transition, if and when we decide to do so. Specifically, the new\n> GIT_TEST_DEFAULT_BRANCH_NAME environment variable could be used to update\n> test scripts on an individual basis instead of all-at-once.\n\nProvided that the eventual plan is to seriously evaluate a name other\nthan \"master\", I think that this is a good way forward that clears the\nway for us to make this change easily, without forcing us to come to a\nconclusion on what name will replace \"master\" today.\n\nFor what it's worth, I am completely in favor of abandoning this term.\nMy colleagues at GitHub (as has been mentioned previously on the list)\nare in favor of this as well, and it is my understanding that other\nproviders feel similarly.\n\nI would be in favor of any non-offensive name that we can reach\nconsensus on. \"trunk\" sounds nice to me, but I think that it may cause\nproblems for non-native English speakers, so perhaps \"main\" or\n\"default\" would suffice (maybe \"main\" is better, since it retains muscle\nmemory for the first two characters without being offensive--at least,\nas far as I can tell. If I am wrong, please correct me and we should\nconsider something else).\n\nAll of that said, I can't emphasize enough how little I care about\n*what* name we replace \"master\" with, so long as it is (1) replaced with\na non-offensive term, (2) that that change is done uniformly throughout\nthe \"Git Ecosystem\" and (3) that the community can reach consensus on\nthe new term in a respectful, appropriate, and considerate way. I only\nprovided a few suggestions to get the conversation flowing, although I\nsuspect that my help isn't needed there.\n\n> Don Goodman-Wilson (1):\n>   init: allow overriding the default branch name for new repositories\n>\n> Johannes Schindelin (8):\n>   remote: respect `core.defaultBranchName`\n>   send-pack/transport-helper: respect `core.defaultBranchName`\n>   testsvn: respect `core.defaultBranchName`\n>   submodule: use the (possibly overridden) default branch name\n>   clone: learn about the possibly-configured default branch name\n>   fmt-merge-msg: learn about the possibly-configured default branch name\n>   fast-export: respect the possibly-overridden default branch name\n>   Document how the default branch name can be overridden\n>\n>  Documentation/config/core.txt |  4 ++++\n>  builtin/clone.c               | 14 +++++++++++---\n>  builtin/fast-export.c         | 10 +++++++---\n>  builtin/init-db.c             |  8 +++++---\n>  builtin/submodule--helper.c   | 10 ++++++++--\n>  fmt-merge-msg.c               |  6 ++++--\n>  refs.c                        | 34 ++++++++++++++++++++++++++++++++++\n>  refs.h                        |  6 ++++++\n>  remote-testsvn.c              | 11 ++++++++---\n>  remote.c                      | 12 ++++++++----\n>  send-pack.c                   |  6 +++++-\n>  t/README                      |  4 ++++\n>  t/t0001-init.sh               | 20 ++++++++++++++++++++\n>  t/t5609-clone-branch.sh       |  9 +++++++++\n>  t/t6200-fmt-merge-msg.sh      |  8 ++++++++\n>  transport-helper.c            |  6 +++++-\n>  16 files changed, 146 insertions(+), 22 deletions(-)\n>\n>\n> base-commit: 0313f36c6ebecb3bffe6f15cf25a4883100f0214\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-656%2Fdscho%2Fdefault-branch-name-option-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-656/dscho/default-branch-name-option-v1\n> Pull-Request: https://github.com/gitgitgadget/git/pull/656\n> --\n> gitgitgadget\n\nThanks,\nTaylor\n"},{"id":"399497","messageId":"xmqq3672cgw8.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"CAOjrSZvV6+ApfmOBa7rdXDPQJbExRsOfodO16i_1N5QjjhCB1w@mail.gmail.com","subject":"Re: [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-11T05:26:15Z","receivedAt":"2020-06-11T05:26:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matt Rogers <mattr94@gmail.com> writes:\n\n> I think that's not very convincing.  If branch names in general are identifying\n> enough to warrant anonymization then shouldn't the default name be too?\n\nIt is a good argument.  I also heard a rumor that often branch names\ncontain codewords given to pre-released hardware that are highly\nconfidential in certain circles, and heard that it is one of the\nreasons why Gerrit has server side ACL that lets you hide some\nbranches from authenticated users that can access other branches.\n\nAgain, the original comment explains why 'master' without such a\nconfiguration knob was not worth protecting, but what it does not\nexplain is why keeping it (and only that branch name) unmunged gives\na more useful result than munging everything.  From the point of\nview of \"I want to debug the shape of the DAG, without the actual\nuser data\", munging 'master' to 'ref47' while other branches like\n'next' are munged to 'ref%d' does not make it harder to use or less\nuseful for the debugging than only 'master' is kept intact in the\noutput stream.\n"},{"id":"399498","messageId":"xmqqy2oub1l3.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"xmqqk10eecsg.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-11T05:42:16Z","receivedAt":"2020-06-11T05:42:22Z","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> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n> ...\n>> This series DOES NOT change the default automatically, but only provides an\n>> opt-in mechanism for interested users. It also presents a way forward for\n>> such a transition, if and when we decide to do so. Specifically, the new\n>> GIT_TEST_DEFAULT_BRANCH_NAME environment variable could be used to update\n>> test scripts on an individual basis instead of all-at-once.\n>\n> Yes.  I've been thinking about a way that does not hurt workflows\n> used in existing projects while allowing a \"git init\" that is run to\n> create a new repository by a new user who does not have any special\n> customization in ~/.gitconfig to use the branch name that replaces\n> the 'master' (I do not mind changing away from 'master', but I am\n> not yet convinced it should be 'main', by the way---the actual\n> choice of the final name does not matter at this point of the design\n> of backward compatibility plan).  \n>\n> I think \"git init\" that is creating a new repository (iow, do not do\n> anything when reinitializing an existing repostiory) can\n>\n>  - look at config.defaultBranchName in /etc/gitconfig or\n>    ~/.gitconfig before initializing the per-repository config in\n>    $GIT_DIR/config it just created (or it is about to create).\n>\n>  - if there is no config.defaultBranchName configured, then set the\n>    per-repository configuration to 'main' in the per-repository\n>    configuration.  Otherwise do not do anything.\n>\n> And then we make sure Don's git_default_branch_name() works this\n> way:\n>\n>  (0) if there is config.defaultBranchName in relevant config file\n>      (i.e. /etc/gitconfig, ~/.gitconfig or per-repo config), use the\n>      specified name.\n>\n>  (1) otherwise use 'master' (not 'main').\n>\n> That way, an existing repository will keep using 'master' unless the\n> user shows the preference (and accepts responsibilities for possible\n> fallouts) in ~/.gitconfig or the repository's .git/config, while a\n> new repository created by a user who does not show any particular\n> preference will use 'main'.\n\nA useful addition to these 9-patch series (i.e. even before the\ndefault for vanilla usage gets changed) might be to give an example\nto use \"git config\" to grab the default branch name, e.g.\n\n    name=$(git config core.defaultBranchName || echo master)\n\nBetter yet (because the above forces the end users to write 'master'\nin their script), we might want to teach \"git var\" about the\nvariable, so that the above can be written like so:\n\n    name=$(git var defaultBranchName)\n\nFor those not so familiar with \"git var\", it is a command to query\n\"magic\" variables whose value can be retrieved from different places\nand is backed by non-trivial logic.  \"What's the editor to be used?\"\nis queried by \"git var GIT_EDITOR\", but that is not a simple:\n\n    if test -n \"$GIT_EDITOR\"\n    then\n\techo \"$GIT_EDITOR\"\n    else\n\techo vi\n    fi\n\nIt takes the fallback `EDITOR` environment variable, and core.editor\nconfiguration variable, into account, for example.\n\nSimilarly, \"what is the default branch name\" is not just about the\nvalue of one configuration variable.  GIT_TEST_DEFAULT_BRANCH_NAME\nenvironment needs to be consulted, and when there is nothing\nconfigured, it needs to say 'master', so that end-users who use \"git\nvar\" do not have to hardcode the string 'master' in their script.\n\n\n"},{"id":"399506","messageId":"be09ffbb-4e38-5b67-54da-0b60d5e2d8c3@gmail.com","threadId":"53651","inReplyTo":"90912e32da1192cfc3b39a18cb606caa46e85b1c.1591823971.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2020-06-11T09:35:45Z","receivedAt":"2020-06-11T09:35:52Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 10/06/2020 22:19, Don Goodman-Wilson via GitGitGadget wrote:\n> From: Don Goodman-Wilson <don@goodman-wilson.com>\n> \n> There is a growing number of projects trying to avoid the non-inclusive\n> name `master` in their repositories.\n\nI think it would be helpful to explain why 'master' is no-inclusive even\nif it originates from the concept of a master copy. i.e. it suggests\nmaster/slave even if git is not based on that concept.\n\nHave you got some examples of projects that have changed and the names\nthat they are using? I think it would be helpful if we can agree on a\nreplacement for master - if every repository uses a different name for\nits main branch it adds an extra complication for new contributors to\nthose projects.\n\n For existing repositories, this\n> requires manual work. For new repositories, the only way to do that\n> automatically is by copying all of Git's template directory, then\n> hard-coding the desired default branch name into the `.git/HEAD` file,\n> and then configuring `init.templateDir` to point to those copied\n> template files.\n> \n> To make this process much less cumbersome, let's introduce support for\n> `core.defaultBranchName`. That way, users won't need to keep their\n> copied template files up to date, and won't interfere with default hooks\n> installed by their administrators.\n> \n> While at it, also let users set the default branch name via the\n> environment variable `GIT_TEST_DEFAULT_BRANCH_NAME`,\n\nI'm not sure we usually promote the use of GIT_TEST_... environment\nvariables outside of the test suite.\n\n> in preparation for\n> adjusting Git's test suite to a more inclusive default branch name. As\n> is common in Git, the `GIT_TEST_*` variable takes precedence over the\n> config setting.\n> \n> Note: we use the prefix `core.` instead of `init.` because we want to\n> adjust also `git clone`, `git fmt-merge-msg` and other commands over the\n> course of the next commits to respect this setting.\n> \n> Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> Helped-by: Derrick Stolee <dstolee@microsoft.com>\n> Signed-off-by: Don Goodman-Wilson <don@goodman-wilson.com>\n> ---\n>  builtin/init-db.c |  8 +++++---\n>  refs.c            | 34 ++++++++++++++++++++++++++++++++++\n>  refs.h            |  6 ++++++\n>  t/t0001-init.sh   | 20 ++++++++++++++++++++\n>  4 files changed, 65 insertions(+), 3 deletions(-)\n> \n> diff --git a/builtin/init-db.c b/builtin/init-db.c\n> index 0b7222e7188..99792adfd43 100644\n> --- a/builtin/init-db.c\n> +++ b/builtin/init-db.c\n> @@ -258,15 +258,17 @@ static int create_default_files(const char *template_path,\n>  \t\tdie(\"failed to set up refs db: %s\", err.buf);\n>  \n>  \t/*\n> -\t * Create the default symlink from \".git/HEAD\" to the \"master\"\n> -\t * branch, if it does not exist yet.\n> +\t * Create the default symlink from \".git/HEAD\" to the default\n> +\t * branch name, if it does not exist yet.\n>  \t */\n>  \tpath = git_path_buf(&buf, \"HEAD\");\n>  \treinit = (!access(path, R_OK)\n>  \t\t  || readlink(path, junk, sizeof(junk)-1) != -1);\n>  \tif (!reinit) {\n> -\t\tif (create_symref(\"HEAD\", \"refs/heads/master\", NULL) < 0)\n> +\t\tchar *default_ref = git_default_branch_name(0);\n> +\t\tif (create_symref(\"HEAD\", default_ref, NULL) < 0)\n>  \t\t\texit(1);\n> +\t\tfree(default_ref);\n>  \t}\n>  \n>  \tinitialize_repository_version(fmt->hash_algo);\n> diff --git a/refs.c b/refs.c\n> index 224ff66c7bb..8499b3865cb 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -560,6 +560,40 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n>  \t\targv_array_pushf(prefixes, *p, len, prefix);\n>  }\n>  \n> +char *git_default_branch_name(int short_name)\n> +{\n> +\tconst char *branch_name = getenv(\"GIT_TEST_DEFAULT_BRANCH_NAME\");\n> +\tchar *from_config = NULL, *prefixed;\n> +\n> +\t/*\n> +\t * If the default branch name was not specified via the environment\n> +\t * variable GIT_TEST_DEFAULT_BRANCH_NAME, retrieve it from the config\n> +\t * setting core.defaultBranchName. If neither are set, fall back to the\n> +\t * hard-coded default.\n> +\t */\n> +\tif (!branch_name || !*branch_name) {\n> +\t\tif (git_config_get_string(\"core.defaultbranchname\",\n> +\t\t\t\t\t  &from_config) < 0)\n> +\t\t\tdie(_(\"Could not retrieve `core.defaultBranchName`\"));\n> +\n> +\t\tif (from_config)\n> +\t\t\tbranch_name = from_config;\n> +\t\telse\n> +\t\t\tbranch_name = \"master\";\n> +\t}\n> +\n> +\tif (short_name)\n> +\t\treturn from_config ? from_config : xstrdup(branch_name);\n\nIf short_name is set we return without validating the name is that\nintentional?\n\n> +\n> +\t/* prepend \"refs/heads/\" to the branch name */\n> +\tprefixed = xstrfmt(\"refs/heads/%s\", branch_name);\n> +\tif (check_refname_format(prefixed, 0))\n> +\t\tdie(_(\"invalid default branch name: '%s'\"), branch_name);\n> +\n> +\tfree(from_config);\n> +\treturn prefixed;\n> +}\n> +\n>  /*\n>   * *string and *len will only be substituted, and *string returned (for\n>   * later free()ing) if the string passed in is a magic short-hand form\n> diff --git a/refs.h b/refs.h\n> index a92d2c74c83..e8d4f6e2f13 100644\n> --- a/refs.h\n> +++ b/refs.h\n> @@ -154,6 +154,12 @@ int repo_dwim_log(struct repository *r, const char *str, int len, struct object_\n>  int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n>  int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n>  \n> +/*\n> + * Retrieves the name of the default branch. If `short_name` is non-zero, the\n> + * branch name will be prefixed with \"refs/heads/\".\n\nIsn't the other way around - the branch name is prefixed with\n\"refs/heads/\" if short is zero.\n\n> + */\n> +char *git_default_branch_name(int short_name);\n> +\n>  /*\n>   * A ref_transaction represents a collection of reference updates that\n>   * should succeed or fail together.\n> diff --git a/t/t0001-init.sh b/t/t0001-init.sh\n> index 1edd5aeb8f0..b144cd8f46b 100755\n> --- a/t/t0001-init.sh\n> +++ b/t/t0001-init.sh\n> @@ -464,4 +464,24 @@ test_expect_success MINGW 'redirect std handles' '\n>  \tgrep \"Needed a single revision\" output.txt\n>  '\n>  \n> +test_expect_success 'custom default branch name from config' '\n> +\tgit config --global core.defaultbranchname nmb &&\n\nIn tests we usually use 'test_config' rather than 'git config' as the\nformer automatically cleans up the config at the end of the test.\n\n> +\tGIT_TEST_DEFAULT_BRANCH_NAME= git init custom-config &&\n> +\tgit config --global --unset core.defaultbranchname &&\n> +\tgit -C custom-config symbolic-ref HEAD >actual &&\n> +\tgrep nmb actual\n> +'\n> +\n> +test_expect_success 'custom default branch name from env' '\n> +\tGIT_TEST_DEFAULT_BRANCH_NAME=nmb git init custom-env &&\n\nIt would be good to test that this overrides the config setting\n\nBest Wishes\n\nPhillip\n\n> +\tgit -C custom-env symbolic-ref HEAD >actual &&\n> +\tgrep nmb actual\n> +'\n> +\n> +test_expect_success 'invalid custom default branch name' '\n> +\ttest_must_fail env GIT_TEST_DEFAULT_BRANCH_NAME=\"with space\" \\\n> +\t\tgit init custom-invalid 2>err &&\n> +\ttest_i18ngrep \"invalid default branch name\" err\n> +'\n> +\n>  test_done\n> \n\n"},{"id":"399507","messageId":"08e46af3-ff52-8bce-b75a-db8c390c9641@gmail.com","threadId":"53651","inReplyTo":"90912e32da1192cfc3b39a18cb606caa46e85b1c.1591823971.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Alban Gruin","fromEmail":"alban.gruin@gmail.com","sentAt":"2020-06-11T10:23:51Z","receivedAt":"2020-06-11T10:24:06Z","isPatch":true,"sender":{"key":"alban.gruin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6310153?v=4"},"body":"Hi Don & Johannes,\n\nLe 10/06/2020 à 23:19, Don Goodman-Wilson via GitGitGadget a écrit :\n> From: Don Goodman-Wilson <don@goodman-wilson.com>\n> \n> There is a growing number of projects trying to avoid the non-inclusive\n> name `master` in their repositories. For existing repositories, this\n> requires manual work. For new repositories, the only way to do that\n> automatically is by copying all of Git's template directory, then\n> hard-coding the desired default branch name into the `.git/HEAD` file,\n> and then configuring `init.templateDir` to point to those copied\n> template files.\n> \n> To make this process much less cumbersome, let's introduce support for\n> `core.defaultBranchName`. That way, users won't need to keep their\n> copied template files up to date, and won't interfere with default hooks\n> installed by their administrators.\n> \n> While at it, also let users set the default branch name via the\n> environment variable `GIT_TEST_DEFAULT_BRANCH_NAME`, in preparation for\n> adjusting Git's test suite to a more inclusive default branch name. As\n> is common in Git, the `GIT_TEST_*` variable takes precedence over the\n> config setting.\n> \n\nWhy adding yet another environment variable instead of relying only on a\nconfig option?  I understand it's for the tests, but can't we add a\nshell function in test-lib.sh (and friends) that tries to read\n`GIT_TEST_DEFAULT_BRANCH_NAME', and, if it exists, sets\n`core.defaultBranchName'?\n\nCheers,\nAlban\n\n"},{"id":"399532","messageId":"nycvar.QRO.7.76.6.2006111533140.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqk10eecsg.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-11T13:44:11Z","receivedAt":"2020-06-11T13:44:26Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Wed, 10 Jun 2020, Junio C Hamano wrote:\n\n> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> > A growing number of open source projects aims to avoid the branch name\n> > master due to its negative connotation. See [1] for an existing discussion\n> > on this. The links [2], [3], and [4] describe community-driven ways for\n> > users to rename their default branches or use template edits to set a new\n> > default branch name.\n>\n> I scanned the series quickly and the patches seem to cover all the\n> places I was aware of that has the hard-coded knowledge of the\n> default branch name being 'master'.  Looking good.\n\nThanks!\n\n> > This series DOES NOT change the default automatically, but only\n> > provides an opt-in mechanism for interested users. It also presents a\n> > way forward for such a transition, if and when we decide to do so.\n> > Specifically, the new GIT_TEST_DEFAULT_BRANCH_NAME environment\n> > variable could be used to update test scripts on an individual basis\n> > instead of all-at-once.\n>\n> Yes.  I've been thinking about a way that does not hurt workflows\n> used in existing projects while allowing a \"git init\" that is run to\n> create a new repository by a new user who does not have any special\n> customization in ~/.gitconfig to use the branch name that replaces\n> the 'master' (I do not mind changing away from 'master', but I am\n> not yet convinced it should be 'main', by the way---the actual\n> choice of the final name does not matter at this point of the design\n> of backward compatibility plan).\n>\n> I think \"git init\" that is creating a new repository (iow, do not do\n> anything when reinitializing an existing repostiory) can\n>\n>  - look at config.defaultBranchName in /etc/gitconfig or\n>    ~/.gitconfig before initializing the per-repository config in\n>    $GIT_DIR/config it just created (or it is about to create).\n>\n>  - if there is no config.defaultBranchName configured, then set the\n>    per-repository configuration to 'main' in the per-repository\n>    configuration.  Otherwise do not do anything.\n>\n> And then we make sure Don's git_default_branch_name() works this\n> way:\n>\n>  (0) if there is config.defaultBranchName in relevant config file\n>      (i.e. /etc/gitconfig, ~/.gitconfig or per-repo config), use the\n>      specified name.\n>\n>  (1) otherwise use 'master' (not 'main').\n>\n> That way, an existing repository will keep using 'master' unless the\n> user shows the preference (and accepts responsibilities for possible\n> fallouts) in ~/.gitconfig or the repository's .git/config, while a\n> new repository created by a user who does not show any particular\n> preference will use 'main'.\n\nI read this (way too late) last night and slept over it. Together with\nyour comment on the `fmt-merge-msg` patch, I think you are really on to\nsomething: we need _two_ config settings, as there are two distinct\nconcepts at play here:\n\n- One setting to specify the default branch name for newly-initialized\n  repositories (such as `git init`, unless it re-initializes, and `git\n  clone` when the cloned repository does not yet contain any branches).\n\n  This should probably be called `init.defaultBranchName` (even if `git\n  clone` picks it up, too), and be overrideable by\n  `GIT_TEST_DEFAULT_BRANCH_NAME`.\n\n- And another one, to define the default branch name for the _current_\n  repository. This setting would be configured implicitly upon `git init`\n  and `git clone`. For repositories where it is not set, we would assume\n  `master` for backwards-compatibility.\n\n  Technically, this should probably not even be a config option because it\n  is _strictly_ per-repo. But maybe it is not _so_ much per-repo: if I\n  want to rename all my main branches in all of my local repositories, I\n  might opt to configure this in `~/.gitconfig`.\n\n  Maybe a good name for this would be `repo.mainBranch` (and it would\n  contain the full ref name, e.g. `refs/heads/main`, not just `main`).\n\nAnd then `git fmt-merge-msg` (and your proposed `git var` addition, which\nI like a lot, maybe `git var mainBranch`?) will pick up the latter.\n\nThat way, existing repositories would not be affected by\n`GIT_TEST_DEFAULT_BRANCH_NAME` or `init.defaultBranchName` at all. Only\nnew repositories would pick it up.\n\nDoes that sound like a plan?\n\nCiao,\nDscho\n"},{"id":"399534","messageId":"nycvar.QRO.7.76.6.2006111556090.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"CAOjrSZvm9QNUttUNVBEUMPJ8zgYEoAnSPN5_6N5uwpiM1sVrcQ@mail.gmail.com","subject":"Re: [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-11T13:57:17Z","receivedAt":"2020-06-11T13:57:32Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Matt,\n\nOn Wed, 10 Jun 2020, Matt Rogers wrote:\n\n> > -        * We also leave \"master\" as a special case, since it does not reveal\n> > -        * anything interesting.\n> > +        * We also leave the default branch name as a special case, since it\n> > +        * does not reveal anything interesting.\n> >          */\n> I feel this is a weird thing to do, since you're trying to anonymize the branch\n> name,and now the default branch is identifiable with your config file.  For\n> example, if the default branch contains the name of my project/repo then this\n> sounds like a recipe for accidentally sharing it. I feel a better\n> alternative would\n> be to exclude nothing from the anonymization or the proposed default default\n> branch name\n\nI don't think that the name of the main branch should be subject to\nanonymizing, whether it be `master` or anything else.\n\nCiao,\nDscho\n"},{"id":"399535","messageId":"nycvar.QRO.7.76.6.2006111559300.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqq3672cgw8.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-11T14:05:24Z","receivedAt":"2020-06-11T14:05:42Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 10 Jun 2020, Junio C Hamano wrote:\n\n> Matt Rogers <mattr94@gmail.com> writes:\n>\n> > I think that's not very convincing.  If branch names in general are identifying\n> > enough to warrant anonymization then shouldn't the default name be too?\n>\n> It is a good argument.  I also heard a rumor that often branch names\n> contain codewords given to pre-released hardware that are highly\n> confidential in certain circles, and heard that it is one of the\n> reasons why Gerrit has server side ACL that lets you hide some\n> branches from authenticated users that can access other branches.\n\nYes, branch names in general _can_ contain information users may prefer to\nkeep private.\n\nHowever, we're not talking about branch names in general. We are talking\nabout the default name of the main branch, to be picked in _all_ of your\nnew repositories.\n\n> Again, the original comment explains why 'master' without such a\n> configuration knob was not worth protecting, but what it does not\n> explain is why keeping it (and only that branch name) unmunged gives\n> a more useful result than munging everything.  From the point of\n> view of \"I want to debug the shape of the DAG, without the actual\n> user data\", munging 'master' to 'ref47' while other branches like\n> 'next' are munged to 'ref%d' does not make it harder to use or less\n> useful for the debugging than only 'master' is kept intact in the\n> output stream.\n\nYes. And you're unlikely to configure the default name to be used for all\nof your future `git init` operations to be something non-generic.\n\nI am still highly doubtful of Matt's suggestion that it would be worth\nprotecting the default name of the main branch to be used for _each_ and\n_any_ new repository.\n\nNow, if you suggest that `git fast-export --anonymize` should either not\nspecial-case the main branch, or at least have a configurable set of names\nit skips from protecting, then I will be much more in favor of those\nsuggestions. However, those suggestions are quite a bit orthogonal to the\npatch series at hand, so I would want to discuss them in their own code\ncontribution instead of here.\n\nCiao,\nDscho\n"},{"id":"399536","messageId":"nycvar.QRO.7.76.6.2006111607450.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"CAPig+cSnEvVB5vsffFXidG1-XNxDX10u2XhD9NqV3pwh8zyxxw@mail.gmail.com","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-11T14:09:30Z","receivedAt":"2020-06-11T14:09:40Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Eric,\n\nOn Wed, 10 Jun 2020, Eric Sunshine wrote:\n\n> On Wed, Jun 10, 2020 at 5:19 PM Don Goodman-Wilson via GitGitGadget\n> <gitgitgadget@gmail.com> wrote:\n> > [...]\n> > To make this process much less cumbersome, let's introduce support for\n> > `core.defaultBranchName`. That way, users won't need to keep their\n> > copied template files up to date, and won't interfere with default hooks\n> > installed by their administrators.\n> > [...]\n> > Signed-off-by: Don Goodman-Wilson <don@goodman-wilson.com>\n> > ---\n> > diff --git a/refs.c b/refs.c\n> > @@ -560,6 +560,40 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n> > +                       die(_(\"Could not retrieve `core.defaultBranchName`\"));\n>\n> Nit: here the error message is capitalized...\n\nI downcased it...\n\n> > +               if (from_config)\n> > +                       branch_name = from_config;\n> > +               else\n> > +                       branch_name = \"master\";\n>\n> Non-actionable nit: could be written:\n>\n>     branch_name = from_config ? from_config : \"master\";\n\nGood call.\n\n> > +       }\n> > +\n> > +       if (short_name)\n> > +               return from_config ? from_config : xstrdup(branch_name);\n>\n> The logic overall is a bit difficult to follow when trying to\n> understand when and when not to duplicate the string and when and when\n> not to free(), but seems to be correct.\n\nI agree that it is a bit hard to follow, but then, the function is really\nshort, so I hoped it is okay.\n\n> > +       /* prepend \"refs/heads/\" to the branch name */\n> > +       prefixed = xstrfmt(\"refs/heads/%s\", branch_name);\n> > +       if (check_refname_format(prefixed, 0))\n> > +               die(_(\"invalid default branch name: '%s'\"), branch_name);\n>\n> Here, the error message is not capitalized. It would be nice for both\n> messages to share a common capitalization scheme. These days, we tend\n> to favor _not_ capitalizing error messages, so perhaps remove\n> capitalization from the earlier one.\n>\n> > +/*\n> > + * Retrieves the name of the default branch. If `short_name` is non-zero, the\n> > + * branch name will be prefixed with \"refs/heads/\".\n> > + */\n> > +char *git_default_branch_name(int short_name);\n>\n> Overall, the internal logic regarding duplicating/freeing strings\n> would probably be easier to grok if there were two separate functions:\n>\n>     char *git_default_branch_name(void);\n>     char *git_default_ref_name(void);\n>\n> but that's subjective.\n\nFor such a tiny nuance, I'd rather keep it as one function...\n\nThank you,\nDscho\n"},{"id":"399538","messageId":"nycvar.QRO.7.76.6.2006111610000.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200611010720.GA21728@syl.local","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-11T14:33:37Z","receivedAt":"2020-06-11T14:33:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Taylor,\n\nOn Wed, 10 Jun 2020, Taylor Blau wrote:\n\n> On Wed, Jun 10, 2020 at 09:19:21PM +0000, Johannes Schindelin via GitGitGadget wrote:\n> > A growing number of open source projects aims to avoid the branch name\n> > master due to its negative connotation. See [1] for an existing discussion\n> > on this. The links [2], [3], and [4] describe community-driven ways for\n> > users to rename their default branches or use template edits to set a new\n> > default branch name.\n> >\n> > [1]\n> > https://lore.kernel.org/git/CAOAHyQwyXC1Z3v7BZAC+Bq6JBaM7FvBenA-1fcqeDV==apdWDg@mail.gmail.com/\n> >\n> > [2] https://twitter.com/mislav/status/1270388510684598272\n> >\n> > [3]\n> > https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx\n> >\n> > [4] https://github.com/ethomson/retarget_prs\n> >\n> > By necessity, existing repositories require a lot of manual work to move\n> > away from that branch name, but it should be much easier for new\n> > repositories.\n>\n> This is (somewhat) orthogonal to the topic here, but I wonder if we\n> could be doing anything to make this easier for users.\n>\n> Could servers remember that a branch has ``moved'' and alert users as\n> such when they pull? Even better, it would be nice if this alert from\n> the server could allow clients to automatically rename their refs\n> appropriately so that this transition is as easy as possible, even for\n> existing repositories.\n\nI would _love_ to have `git fetch origin master` work, spitting out a\nmessage `the main branch name changed to [...] please update your\nconfiguration`.\n\nAnd then maybe an easy way to update the configuration (`git remote\nset-main-branch <nick> <refname>` might make sense).\n\nAs you say, it is orthogonal to this here patch series, but definitely\nrelated in spirit because we _want_ to make it easier for users to move\naway from the current main branch name.\n\n> > This patch series allows overriding the branch name being used for new\n> > repositories' main branch. The main way to do this is the new\n> > core.defaultBranchName config option. This first patch was contributed by\n> > newcomer Dan Goodman-Wilson. Thanks for the contribution!\n>\n> Welcome, Dan! This is a fantastic first contribution, and I would be\n> honored to help and move this forward in anyway that I can.\n\nSorry, my typo: it's Don, not Dan ;-)\n\n> I should note that I am technically \"out of office\" (which normally\n> wouldn't mean much, but this time means that I am on a road-trip, and so\n> am only at my computer infrequently). I am catching up on just a few\n> emails here, but I'll be able to help out more (and would be honored to\n> do so) once I am really back next Monday.\n\nWell, go back enjoying your road trip! :-P See you on Monday.\n\n> > The other patches follow other places where \"master\" is hard-coded and use\n> > the new git_default_branch_name() method to consume the config option before\n> > falling back to \"master\".\n> >\n> > The last patch updates documentation only after the config option is ready\n> > to apply to all of these scenarios.\n> >\n> > This series DOES NOT change the default automatically, but only provides an\n> > opt-in mechanism for interested users. It also presents a way forward for\n> > such a transition, if and when we decide to do so. Specifically, the new\n> > GIT_TEST_DEFAULT_BRANCH_NAME environment variable could be used to update\n> > test scripts on an individual basis instead of all-at-once.\n>\n> Provided that the eventual plan is to seriously evaluate a name other\n> than \"master\", I think that this is a good way forward that clears the\n> way for us to make this change easily, without forcing us to come to a\n> conclusion on what name will replace \"master\" today.\n\nThat is exactly the intention of this patch series.\n\nI _do_ want to put my weight behind changing the default. Obviously, this\nwill take quite a bit of time (but maybe less than I originally thought,\nas we are only talking about changing the default for _new_ repositories).\n\nEven if this endeavor fails, though, this here patch series will be good\nto have.\n\n> For what it's worth, I am completely in favor of abandoning this term.\n> My colleagues at GitHub (as has been mentioned previously on the list)\n> are in favor of this as well, and it is my understanding that other\n> providers feel similarly.\n\nFrom what I read at https://gitlab.com/gitlab-org/gitlab/-/issues/221164,\nGitLab is on board, too.\n\n> I would be in favor of any non-offensive name that we can reach\n> consensus on. \"trunk\" sounds nice to me, but I think that it may cause\n> problems for non-native English speakers, so perhaps \"main\" or\n> \"default\" would suffice (maybe \"main\" is better, since it retains muscle\n> memory for the first two characters without being offensive--at least,\n> as far as I can tell. If I am wrong, please correct me and we should\n> consider something else).\n\nMy personal preference was \"default\" on Monday, and \"main\" ever since.\n\n> All of that said, I can't emphasize enough how little I care about\n> *what* name we replace \"master\" with, so long as it is (1) replaced with\n> a non-offensive term, (2) that that change is done uniformly throughout\n> the \"Git Ecosystem\" and (3) that the community can reach consensus on\n> the new term in a respectful, appropriate, and considerate way. I only\n> provided a few suggestions to get the conversation flowing, although I\n> suspect that my help isn't needed there.\n\nIndeed. I laid out the patch series in such a way that we should be able\nto pick a different default main branch name than \"main\", even if it is my\ncurrent working hypothesis that this will prevail.\n\nAs I said, my preference was \"default\", and that's how my big patch series\nlooked like, so I know how much work it is to change to a different name\n(because I changed it to \"main\"). It is quite a bit of work, but\nmanageable.\n\nCiao,\nDscho\n"},{"id":"399539","messageId":"xmqqtuzhbr1o.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006111533140.56@tvgsbejvaqbjf.bet","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-11T14:44:35Z","receivedAt":"2020-06-11T14:44: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> I read this (way too late) last night and slept over it. Together with\n> your comment on the `fmt-merge-msg` patch, I think you are really on to\n> something: we need _two_ config settings, as there are two distinct\n> concepts at play here:\n>\n> - One setting to specify the default branch name for newly-initialized\n>   repositories (such as `git init`, unless it re-initializes, and `git\n>   clone` when the cloned repository does not yet contain any branches).\n>\n>   This should probably be called `init.defaultBranchName` (even if `git\n>   clone` picks it up, too), and be overrideable by\n>   `GIT_TEST_DEFAULT_BRANCH_NAME`.\n\nYes.\n\n\n> - And another one, to define the default branch name for the _current_\n>   repository. This setting would be configured implicitly upon `git init`\n\nNit.  This is not the \"default\" branch name.  It is \"which branch is\nthe primary one in this repository?\"  There is no default.\n\n>   and `git clone`. For repositories where it is not set, we would assume\n>   `master` for backwards-compatibility.\n>\n>   Technically, this should probably not even be a config option because it\n>   is _strictly_ per-repo. But maybe it is not _so_ much per-repo: if I\n>   want to rename all my main branches in all of my local repositories, I\n>   might opt to configure this in `~/.gitconfig`.\n>\n>   Maybe a good name for this would be `repo.mainBranch` (and it would\n>   contain the full ref name, e.g. `refs/heads/main`, not just `main`).\n\nI think core.* namespace originally were supposed to be about \"this\"\nrepository, so instead of introducing \"repo.*\", I'd recommend just\nsticking it in \"core.*\", perhaps \"core.primaryBranchName\".\n\nAnd for help the scripts in t/, GIT_TEST_PRIMARY_BRANCH_NAME would\nbe a handy thing to have.\n\n> And then `git fmt-merge-msg` (and your proposed `git var` addition, which\n> I like a lot, maybe `git var mainBranch`?) will pick up the latter.\n\nYou may need \"git fast-export\" to know about it (I do not think you\nshould special case the primary branch but that is a topic of\nanother thread).\n\n> That way, existing repositories would not be affected by\n> `GIT_TEST_DEFAULT_BRANCH_NAME` or `init.defaultBranchName` at all. Only\n> new repositories would pick it up.\n>\n> Does that sound like a plan?\n\nSo the idea is that init.* one affects \"init\" and \"clone\" (and any\nother operation that creates a new repository and have to pick a\nbranch to point the HEAD at), lack of which defaults to 'main', and\nthe other one affects \"fmt-merge-msg\", \"fast-export\" (and any other\noperation that wants to know which branch is the primary one in the\nrepository), lack of which defaults to 'master'?  \n\nAnd an updated version of Git would record the latter in the\nrepository it just created, based on the former, so that things\nwon't get broken when the user sets the latter in ~/.gitconfig?\n\nI think such a two-variable configuration would also work.  \n\nI was aiming at not needing any configuration for new people and the\napproach I illustrated for you with just a single variable was an\noutcome from it.  One possible downside of the one-variable approach\nis that existing users with repositories whose primary branch needs\nto stay 'master' cannot set the core.defaultBrnachName in\n~/.gitconfig until they iterate over all the \"sticking to 'master'\"\nrepositories and set the core.defaultBrnachName variable in them,\nbut with the two variable approach, that particular downside is\neliminated, which I like.  I haven't thought things through to see\nif there are downside in the two variable approach, but just like\n\"If you have some repositories that want to stick to 'master', set\nthe config in them before you set the config globally to something\ndifferent from 'master'\" would be a semi-workable workaround for the\ndownside in the one variable approach, I suspect any downside in the\ntwo variable approach we will identify would have an easy\nworkaround, too.\n\nThanks.\n\n"},{"id":"399541","messageId":"xmqqpna5bq2l.fsf_-_@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006111559300.56@tvgsbejvaqbjf.bet","subject":"Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-11T15:05:38Z","receivedAt":"2020-06-11T15:05:46Z","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>> It is a good argument.  I also heard a rumor that often branch names\n>> contain codewords given to pre-released hardware that are highly\n>> confidential in certain circles, and heard that it is one of the\n>> reasons why Gerrit has server side ACL that lets you hide some\n>> branches from authenticated users that can access other branches.\n>\n> Yes, branch names in general _can_ contain information users may prefer to\n> keep private.\n>\n> However, we're not talking about branch names in general. We are talking\n> about the default name of the main branch, to be picked in _all_ of your\n> new repositories.\n\nNo, we are talking about the name of the branch, chosen to be the\nprimary one, in one particular repository whose contents are\nexported via fast-export with explicit request from the user to\nanonymize end-user data.\n\n> Yes. And you're unlikely to configure the default name to be used for all\n> of your future `git init` operations to be something non-generic.\n>\n> Now, if you suggest that `git fast-export --anonymize` should either not\n> special-case the main branch, or at least have a configurable set of names\n> it skips from protecting, then I will be much more in favor of those\n> suggestions. However, those suggestions are quite a bit orthogonal to the\n> patch series at hand, so I would want to discuss them in their own code\n> contribution instead of here.\n\n\nI think after writing the message about your \"two variable\"\napproach, you would retract the \"something non-generic\" part in the\nabove sentence.  The original \"we redact branch names but 'master'\nis used by and known by everybody so there is no need to redact\"\nwould have been a good argument.  Perhaps there is a value to keep\nthe primary branch identifiable even in an export stream that has\nall the refnames and payload anonymized, and leaving 'master' intact\nwould have been a viable approach for solving that issue.\n\nThat trick NO LONGER applies once you allow the name of the primary\nbranch customizable, and the end user has used a name that is not to\nbe exposed.  Yes, \"we want to ensure that readers of the export\nstream can identify which ref is the primary branch of the\nrepository\" is orthogonal from \"how do we make primary branch\nconfigurable in a live repository?\" and \"how do we make the default\nname used for the primary branch in repositories newly created?\".\nBut because the old solution would not work in the new world order\nthis topic created, a new solution needs to be found when you move\nthe world to the new order.\n\nAn easy solution would be to reserve \"ref0\" for the primary branch\nin the repository and anonymize other refs \"ref1\", \"ref2\", ...\n\nThat can be done as a preparatory step regardless of the \"'master'\nmay not be in the name of the primary branch in this repository\"\ntopic.\n\n-- >8 --\nSubject: [PATCH] fast-export: do anonymize the primary branch name\n\nIn a fast-export stream with --anonymize option, all the end-user\ndata including refnames are munged to prevent exposure, but the\n'master' branch is left intact.\n\nThere is a comment that explains why it is OK to leave 'master'\nunanonymized (because everybody calls the primary branch 'master'\nand it is no secret), but that does not justify why it is bad to\nanonymize 'master' and make it undistinguishable from other\nbranches.  Assuming there _is_ a need to allow the readers of the\noutput to tell where the tip of the primary branch is, let's keep\nthe special casing of 'master', but still anonymize it to \"ref0\".\nBecause all other branches will be given ref+N where N is a positive\ninteger, this will keep the primary branch identifiable in the\noutput stream, without exposing what the name of the primary branch\nis in the repository the export stream was taken from.\n\nThis is in preparation for introducing a mechanism to affect the\nname of the primary branch used in the repository.  Once the\nmechanism is in use, the name of the primary branch won't be\n'master', and may not be allowed to be exposed.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/fast-export.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 85868162ee..a306a60d25 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -497,7 +497,7 @@ static void *anonymize_ref_component(const void *old, size_t *len)\n {\n \tstatic int counter;\n \tstruct strbuf out = STRBUF_INIT;\n-\tstrbuf_addf(&out, \"ref%d\", counter++);\n+\tstrbuf_addf(&out, \"ref%d\", ++counter);\n \treturn strbuf_detach(&out, len);\n }\n \n@@ -522,7 +522,7 @@ static const char *anonymize_refname(const char *refname)\n \t * anything interesting.\n \t */\n \tif (!strcmp(refname, \"refs/heads/master\"))\n-\t\treturn refname;\n+\t\treturn \"ref0\";\n \n \tstrbuf_reset(&anon);\n \tfor (i = 0; i < ARRAY_SIZE(prefixes); i++) {\n"},{"id":"399548","messageId":"xmqqd065bp0x.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006111607450.56@tvgsbejvaqbjf.bet","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-11T15:28:14Z","receivedAt":"2020-06-11T15:28:20Z","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>> Overall, the internal logic regarding duplicating/freeing strings\n>> would probably be easier to grok if there were two separate functions:\n>>\n>>     char *git_default_branch_name(void);\n>>     char *git_default_ref_name(void);\n>>\n>> but that's subjective.\n>\n> For such a tiny nuance, I'd rather keep it as one function...\n\nAnd you'd need two functions, default and primary, possibly full and\nshort.  Splitting these into two here would mean you'd need four.\n"},{"id":"399551","messageId":"xmqqtuzha6xn.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"xmqqpna5bq2l.fsf_-_@gitster.c.googlers.com","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-11T16:44:20Z","receivedAt":"2020-06-11T16:44:25Z","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> But because the old solution would not work in the new world order\n> this topic created, a new solution needs to be found when you move\n> the world to the new order.\n>\n> An easy solution would be to reserve \"ref0\" for the primary branch\n> in the repository and anonymize other refs \"ref1\", \"ref2\", ...\n>\n> That can be done as a preparatory step regardless of the \"'master'\n> may not be in the name of the primary branch in this repository\"\n> topic.\n> ...\n> diff --git a/builtin/fast-export.c b/builtin/fast-export.c\n> index 85868162ee..a306a60d25 100644\n> --- a/builtin/fast-export.c\n> +++ b/builtin/fast-export.c\n> @@ -497,7 +497,7 @@ static void *anonymize_ref_component(const void *old, size_t *len)\n>  {\n>  \tstatic int counter;\n>  \tstruct strbuf out = STRBUF_INIT;\n> -\tstrbuf_addf(&out, \"ref%d\", counter++);\n> +\tstrbuf_addf(&out, \"ref%d\", ++counter);\n>  \treturn strbuf_detach(&out, len);\n>  }\n>  \n> @@ -522,7 +522,7 @@ static const char *anonymize_refname(const char *refname)\n>  \t * anything interesting.\n>  \t */\n>  \tif (!strcmp(refname, \"refs/heads/master\"))\n> -\t\treturn refname;\n> +\t\treturn \"ref0\";\n\nThis is obviously wrong.  It should return \"refs/heads/ref0\".\n\nBut another thing we could do, which is probably more backward\ncompatible, is to return \"refs/heads/master\" from here.  That way,\nconsumers of \"fast-export\" stream that expect 'master' to be the\nprimary branch would not get upset when the data source runs a newer\nversion of Git that allows the primary branch name to be customized.\n\nWhich means that, before such a change to allow the primary branch\nname to be customized happens, there is no need for such a\npreparatory patch, because the status quo is just fine.  So, I'm OK\nwith retracting the above.  \"ref0\" is not special, so there is no\nneed to have the first hunk above, either.\n\nHowever, when the customization being discussed is implemented via\nthe \"get_default_branch_name()\" and \"get_primary_branch_name()\"\nfunctions, we should update these lines like so:\n\n-\tif (!strcmp(refname, \"refs/heads/master\"))\n-\t\treturn \"refs/heads/master\";\n+\tif (!strcmp(refname, get_primary_branch_name(DO_NOT_ABBREV)))\n+\t\treturn get_default_branch_name(DO_NOT_ABBREV);\n\nThat is, the name of the \"primary\" branch used at the data source is\nreplaced by the more generic \"this is the default\" branch name used\nin a random \"git init\" repository.\n\nImagine that there is a project that has an integration branch per\neach device type, named after the confidential device name, owned by\na company.  An employee of the company works on one device type in\nhis own clone of the repository, and the primary branch in the\nrepository is set to that confidential device's name.\n\nThe employee can create an anonymized output, replacing the\nconfidential name with a generic \"default\" name that is not\nconfidential, like 'main' in the new world order or 'master' in the\nbackward compatible world order, with such an updated code.\n\nAfter having thought about it a bit longer, I actually do prefer to\nuse the \"ref0\" approach, as it is possible for the employee in the\nabove example to have the \"default\" branch name tied to the primary\nbranch for the hardware type the emploee works on in the ~/.gitconfig\nso the \"alternative\" I suggested in this message will reveal the\nconfidential name.\n\nSo, I guess we should just fix the patch I am responding to to\nreturn \"refs/heads/ref0\" instead of \"ref0\", and queue it as one of\nthe preparatory steps.\n\n"},{"id":"399560","messageId":"xmqqimfxjwk6.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"xmqqtuzha6xn.fsf@gitster.c.googlers.com","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-11T18:18:17Z","receivedAt":"2020-06-11T18:18:28Z","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>> diff --git a/builtin/fast-export.c b/builtin/fast-export.c\n>> index 85868162ee..a306a60d25 100644\n>> --- a/builtin/fast-export.c\n>> +++ b/builtin/fast-export.c\n>> @@ -497,7 +497,7 @@ static void *anonymize_ref_component(const void *old, size_t *len)\n>>  {\n>>  \tstatic int counter;\n>>  \tstruct strbuf out = STRBUF_INIT;\n>> -\tstrbuf_addf(&out, \"ref%d\", counter++);\n>> +\tstrbuf_addf(&out, \"ref%d\", ++counter);\n>>  \treturn strbuf_detach(&out, len);\n>>  }\n>>  \n>> @@ -522,7 +522,7 @@ static const char *anonymize_refname(const char *refname)\n>>  \t * anything interesting.\n>>  \t */\n>>  \tif (!strcmp(refname, \"refs/heads/master\"))\n>> -\t\treturn refname;\n>> +\t\treturn \"ref0\";\n>\n> This is obviously wrong.  It should return \"refs/heads/ref0\".\n> ...\n> So, I guess we should just fix the patch I am responding to to\n> return \"refs/heads/ref0\" instead of \"ref0\", and queue it as one of\n> the preparatory steps.\n\n... and the follow-up step to become part of the series you are\nworking on to allow customing what the primary branch is called\nwould turn the second hunk to\n\n\t-\tif (!strcmp(refname, \"refs/heads/master\"))\n\t+\tif (!strcmp(refname, get_primary_branch_name(0)))\n\t\t\treturn \"refs/heads/ref0\";\n\nBy the way, with your \"two variables\" approach to make both the\n\"default\" (for 'init' and 'clone') and the \"primary\" (for\n'fmt-merge-msg' and 'fast-export') configurable, we'd need accessor\nfunction(s) for the primary branch name for the given repository.\nThe get_primary_branch_name() helper function might want to take a\n\"struct repository *\" argument in addition to \"please give me an\nabbreviated refname\" boolean, given the recent push to pass the\nstruct to everybody.\n\n\n"},{"id":"399561","messageId":"xmqqeeqljwht.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006111556090.56@tvgsbejvaqbjf.bet","subject":"Re: [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-11T18:19:42Z","receivedAt":"2020-06-11T18:19:47Z","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> Hi Matt,\n>\n> On Wed, 10 Jun 2020, Matt Rogers wrote:\n>\n>> > -        * We also leave \"master\" as a special case, since it does not reveal\n>> > -        * anything interesting.\n>> > +        * We also leave the default branch name as a special case, since it\n>> > +        * does not reveal anything interesting.\n>> >          */\n>> I feel this is a weird thing to do, since you're trying to anonymize the branch\n>> name,and now the default branch is identifiable with your config file.  For\n>> example, if the default branch contains the name of my project/repo then this\n>> sounds like a recipe for accidentally sharing it. I feel a better\n>> alternative would\n>> be to exclude nothing from the anonymization or the proposed default default\n>> branch name\n>\n> I don't think that the name of the main branch should be subject to\n> anonymizing, whether it be `master` or anything else.\n\n\"Here is why\" is missing ;-)  I think you realized that it needs to\nbe, after you wrote the \"ah, we need two, the default for new ones\nand the name of the primary branch in a particular repository\", as\nwe are dealing with the latter here.\n\nThanks.\n"},{"id":"399568","messageId":"xmqqwo4di49l.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"08e46af3-ff52-8bce-b75a-db8c390c9641@gmail.com","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-11T23:14:46Z","receivedAt":"2020-06-11T23:14:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alban Gruin <alban.gruin@gmail.com> writes:\n\n> Why adding yet another environment variable instead of relying only on a\n> config option?  I understand it's for the tests, but can't we add a\n> shell function in test-lib.sh (and friends) that tries to read\n> `GIT_TEST_DEFAULT_BRANCH_NAME', and, if it exists, sets\n> `core.defaultBranchName'?\n\nCan you produce such a patch that does it cleanly?  My knee jerk\nreaction is that I would suspect that you end up having to touch\nmany places in the t/ scripts, but if you prove otherwise, that\nwould certainly be appreciated.\n\nAnd no, \n\n    git () { command git -c core.defaultBranchName=master \"$@\" }\n\nis not an acceptable solution.\n\n"},{"id":"399571","messageId":"20200611234611.GA6569@camp.crustytoothpaste.net","threadId":"53651","inReplyTo":"xmqqwo4di49l.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2020-06-11T23:46:11Z","receivedAt":"2020-06-11T23:46:21Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2020-06-11 at 23:14:46, Junio C Hamano wrote:\n> Alban Gruin <alban.gruin@gmail.com> writes:\n> \n> > Why adding yet another environment variable instead of relying only on a\n> > config option?  I understand it's for the tests, but can't we add a\n> > shell function in test-lib.sh (and friends) that tries to read\n> > `GIT_TEST_DEFAULT_BRANCH_NAME', and, if it exists, sets\n> > `core.defaultBranchName'?\n> \n> Can you produce such a patch that does it cleanly?  My knee jerk\n> reaction is that I would suspect that you end up having to touch\n> many places in the t/ scripts, but if you prove otherwise, that\n> would certainly be appreciated.\n> \n> And no, \n> \n>     git () { command git -c core.defaultBranchName=master \"$@\" }\n> \n> is not an acceptable solution.\n\nI would also be delighted to see such a solution, but my experience with\nthe SHA-256 work tells me there's unlikely to be one.  We do a lot of\n\"git init\" operations in random places in the test suite and as a\nconsequence it's very hard to make a change without touching a large\nnumber of tests.\n\nIf we were writing things today, perhaps we would use a function (e.g.,\ntest_init_repo or such) to wrap this case, but we unfortunately didn't\nthink about that and we're stuck with what we have now unless someone\nretrofits the test suite.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"399577","messageId":"nycvar.QRO.7.76.6.2006121308030.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"be09ffbb-4e38-5b67-54da-0b60d5e2d8c3@gmail.com","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-12T11:55:50Z","receivedAt":"2020-06-12T11:56:04Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Phillip,\n\nOn Thu, 11 Jun 2020, Phillip Wood wrote:\n\n> On 10/06/2020 22:19, Don Goodman-Wilson via GitGitGadget wrote:\n> > From: Don Goodman-Wilson <don@goodman-wilson.com>\n> >\n> > There is a growing number of projects trying to avoid the non-inclusive\n> > name `master` in their repositories.\n>\n> I think it would be helpful to explain why 'master' is no-inclusive even\n> if it originates from the concept of a master copy. i.e. it suggests\n> master/slave even if git is not based on that concept.\n\nUnfortunately, we do not even have that defense: the term `master` was\ncopied from BitKeeper, which firmly uses it in the `master/slave` context.\nSee e.g.\nhttps://mail.gnome.org/archives/desktop-devel-list/2019-May/msg00066.html\n\nI added a _brief_ extension to the context to the first commit's commit\nmessage. However, I do not want to go into details here because _this_\npatch series is only about empowering users to change their default main\nbranch name.\n\n> Have you got some examples of projects that have changed and the names\n> that they are using?\n\nYes, there are plenty examples, and I do not want to pick a tiny subset to\ndemonstrate that. A more useful resource is probably this post:\nhttps://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx\n\n> I think it would be helpful if we can agree on a replacement for master\n> - if every repository uses a different name for its main branch it adds\n> an extra complication for new contributors to those projects.\n\nSure, and that's what I thought we'd discuss, too, maybe at the meeting I\nproposed elsewhere (Emily started a new thread about it:\nhttps://lore.kernel.org/git/20200610222719.GE148632@google.com/).\n\n> >  For existing repositories, this\n> > requires manual work. For new repositories, the only way to do that\n> > automatically is by copying all of Git's template directory, then\n> > hard-coding the desired default branch name into the `.git/HEAD` file,\n> > and then configuring `init.templateDir` to point to those copied\n> > template files.\n> >\n> > To make this process much less cumbersome, let's introduce support for\n> > `core.defaultBranchName`. That way, users won't need to keep their\n> > copied template files up to date, and won't interfere with default hooks\n> > installed by their administrators.\n> >\n> > While at it, also let users set the default branch name via the\n> > environment variable `GIT_TEST_DEFAULT_BRANCH_NAME`,\n>\n> I'm not sure we usually promote the use of GIT_TEST_... environment\n> variables outside of the test suite.\n\nTrue. Together with Alban's suggestion to make this purely work in the\ntest suite (i.e. not even adjust the C code to respect that environment\nvariable), you convinced me to (re-)move that part of the commit.\n\n> > diff --git a/refs.c b/refs.c\n> > index 224ff66c7bb..8499b3865cb 100644\n> > --- a/refs.c\n> > +++ b/refs.c\n> > @@ -560,6 +560,40 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n> >  \t\targv_array_pushf(prefixes, *p, len, prefix);\n> >  }\n> >\n> > +char *git_default_branch_name(int short_name)\n> > +{\n> > +\tconst char *branch_name = getenv(\"GIT_TEST_DEFAULT_BRANCH_NAME\");\n> > +\tchar *from_config = NULL, *prefixed;\n> > +\n> > +\t/*\n> > +\t * If the default branch name was not specified via the environment\n> > +\t * variable GIT_TEST_DEFAULT_BRANCH_NAME, retrieve it from the config\n> > +\t * setting core.defaultBranchName. If neither are set, fall back to the\n> > +\t * hard-coded default.\n> > +\t */\n> > +\tif (!branch_name || !*branch_name) {\n> > +\t\tif (git_config_get_string(\"core.defaultbranchname\",\n> > +\t\t\t\t\t  &from_config) < 0)\n> > +\t\t\tdie(_(\"Could not retrieve `core.defaultBranchName`\"));\n> > +\n> > +\t\tif (from_config)\n> > +\t\t\tbranch_name = from_config;\n> > +\t\telse\n> > +\t\t\tbranch_name = \"master\";\n> > +\t}\n> > +\n> > +\tif (short_name)\n> > +\t\treturn from_config ? from_config : xstrdup(branch_name);\n>\n> If short_name is set we return without validating the name is that\n> intentional?\n\nNo, unintentional. Thank you for pointing this out. It will be fixed in v2\n(still working on it).\n\n> > +\n> > +\t/* prepend \"refs/heads/\" to the branch name */\n> > +\tprefixed = xstrfmt(\"refs/heads/%s\", branch_name);\n> > +\tif (check_refname_format(prefixed, 0))\n> > +\t\tdie(_(\"invalid default branch name: '%s'\"), branch_name);\n> > +\n> > +\tfree(from_config);\n> > +\treturn prefixed;\n> > +}\n> > +\n> >  /*\n> >   * *string and *len will only be substituted, and *string returned (for\n> >   * later free()ing) if the string passed in is a magic short-hand form\n> > diff --git a/refs.h b/refs.h\n> > index a92d2c74c83..e8d4f6e2f13 100644\n> > --- a/refs.h\n> > +++ b/refs.h\n> > @@ -154,6 +154,12 @@ int repo_dwim_log(struct repository *r, const char *str, int len, struct object_\n> >  int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n> >  int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n> >\n> > +/*\n> > + * Retrieves the name of the default branch. If `short_name` is non-zero, the\n> > + * branch name will be prefixed with \"refs/heads/\".\n>\n> Isn't the other way around - the branch name is prefixed with\n> \"refs/heads/\" if short is zero.\n\nAbsolutely. Thank you for your careful review, I read past this at least\nhalf a dozen times.\n\n> > + */\n> > +char *git_default_branch_name(int short_name);\n> > +\n> >  /*\n> >   * A ref_transaction represents a collection of reference updates that\n> >   * should succeed or fail together.\n> > diff --git a/t/t0001-init.sh b/t/t0001-init.sh\n> > index 1edd5aeb8f0..b144cd8f46b 100755\n> > --- a/t/t0001-init.sh\n> > +++ b/t/t0001-init.sh\n> > @@ -464,4 +464,24 @@ test_expect_success MINGW 'redirect std handles' '\n> >  \tgrep \"Needed a single revision\" output.txt\n> >  '\n> >\n> > +test_expect_success 'custom default branch name from config' '\n> > +\tgit config --global core.defaultbranchname nmb &&\n>\n> In tests we usually use 'test_config' rather than 'git config' as the\n> former automatically cleans up the config at the end of the test.\n\nRight, and in this instance it is `test_config_global`.\n\n> > +\tGIT_TEST_DEFAULT_BRANCH_NAME= git init custom-config &&\n> > +\tgit config --global --unset core.defaultbranchname &&\n> > +\tgit -C custom-config symbolic-ref HEAD >actual &&\n> > +\tgrep nmb actual\n> > +'\n> > +\n> > +test_expect_success 'custom default branch name from env' '\n> > +\tGIT_TEST_DEFAULT_BRANCH_NAME=nmb git init custom-env &&\n>\n> It would be good to test that this overrides the config setting\n\nExcept that we'll make this a thing that is internal to the test suite\nnow. So this test case can go.\n\nThank you for helping me improve the patch series!\nDscho\n"},{"id":"399578","messageId":"nycvar.QRO.7.76.6.2006121401420.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqpna5bq2l.fsf_-_@gitster.c.googlers.com","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-12T12:03:22Z","receivedAt":"2020-06-12T12:03:34Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Thu, 11 Jun 2020, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n>\n> >> It is a good argument.  I also heard a rumor that often branch names\n> >> contain codewords given to pre-released hardware that are highly\n> >> confidential in certain circles, and heard that it is one of the\n> >> reasons why Gerrit has server side ACL that lets you hide some\n> >> branches from authenticated users that can access other branches.\n> >\n> > Yes, branch names in general _can_ contain information users may prefer to\n> > keep private.\n> >\n> > However, we're not talking about branch names in general. We are talking\n> > about the default name of the main branch, to be picked in _all_ of your\n> > new repositories.\n>\n> No, we are talking about the name of the branch, chosen to be the\n> primary one, in one particular repository whose contents are\n> exported via fast-export with explicit request from the user to\n> anonymize end-user data.\n>\n> > Yes. And you're unlikely to configure the default name to be used for all\n> > of your future `git init` operations to be something non-generic.\n> >\n> > Now, if you suggest that `git fast-export --anonymize` should either not\n> > special-case the main branch, or at least have a configurable set of names\n> > it skips from protecting, then I will be much more in favor of those\n> > suggestions. However, those suggestions are quite a bit orthogonal to the\n> > patch series at hand, so I would want to discuss them in their own code\n> > contribution instead of here.\n>\n>\n> I think after writing the message about your \"two variable\"\n> approach, you would retract the \"something non-generic\" part in the\n> above sentence.\n\nYou are absolutely correct!\n\n> [...]\n> -- >8 --\n> Subject: [PATCH] fast-export: do anonymize the primary branch name\n\nI like this approach a lot. Do you want me to integrate it into this patch\nseries, or rather have it as a stand-alone patch?\n\nCiao,\nDscho\n"},{"id":"399579","messageId":"nycvar.QRO.7.76.6.2006121403340.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqimfxjwk6.fsf@gitster.c.googlers.com","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-12T12:07:01Z","receivedAt":"2020-06-12T12:07:18Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Thu, 11 Jun 2020, Junio C Hamano wrote:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n> >> diff --git a/builtin/fast-export.c b/builtin/fast-export.c\n> >> index 85868162ee..a306a60d25 100644\n> >> --- a/builtin/fast-export.c\n> >> +++ b/builtin/fast-export.c\n> >> @@ -497,7 +497,7 @@ static void *anonymize_ref_component(const void *old, size_t *len)\n> >>  {\n> >>  \tstatic int counter;\n> >>  \tstruct strbuf out = STRBUF_INIT;\n> >> -\tstrbuf_addf(&out, \"ref%d\", counter++);\n> >> +\tstrbuf_addf(&out, \"ref%d\", ++counter);\n> >>  \treturn strbuf_detach(&out, len);\n> >>  }\n> >>\n> >> @@ -522,7 +522,7 @@ static const char *anonymize_refname(const char *refname)\n> >>  \t * anything interesting.\n> >>  \t */\n> >>  \tif (!strcmp(refname, \"refs/heads/master\"))\n> >> -\t\treturn refname;\n> >> +\t\treturn \"ref0\";\n> >\n> > This is obviously wrong.  It should return \"refs/heads/ref0\".\n> > ...\n> > So, I guess we should just fix the patch I am responding to to\n> > return \"refs/heads/ref0\" instead of \"ref0\", and queue it as one of\n> > the preparatory steps.\n>\n> ... and the follow-up step to become part of the series you are\n> working on to allow customing what the primary branch is called\n> would turn the second hunk to\n>\n> \t-\tif (!strcmp(refname, \"refs/heads/master\"))\n> \t+\tif (!strcmp(refname, get_primary_branch_name(0)))\n> \t\t\treturn \"refs/heads/ref0\";\n\nRight.\n\n> By the way, with your \"two variables\" approach to make both the\n> \"default\" (for 'init' and 'clone') and the \"primary\" (for\n> 'fmt-merge-msg' and 'fast-export') configurable, we'd need accessor\n> function(s) for the primary branch name for the given repository.\n> The get_primary_branch_name() helper function might want to take a\n> \"struct repository *\" argument in addition to \"please give me an\n> abbreviated refname\" boolean, given the recent push to pass the\n> struct to everybody.\n\nMy current state defines a `repo_main_branch_name(flags)` function where\nthe flags can be `MAIN_BRANCH_SHORT_NAME` and `MAIN_BRANCH_FOR_INIT`.\n\nSo I think we're on the same page.\n\nBTW I heard from a couple sides that \"primary\" would imply that there is\nalso a \"secondary\" branch, and potentially an ordering of all branches,\nwhich is why I did not really consider \"primary\" as candidate. Besides, it\nis so much more awkward to type than \"main\" (especially when you're as\ntired as I am right now...).\n\nThat's why I try to stay with \"main\" for the moment.\n\nCiao,\nDscho\n"},{"id":"399580","messageId":"nycvar.QRO.7.76.6.2006121407310.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqeeqljwht.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-12T12:07:45Z","receivedAt":"2020-06-12T12:08:00Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Thu, 11 Jun 2020, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n>\n> > Hi Matt,\n> >\n> > On Wed, 10 Jun 2020, Matt Rogers wrote:\n> >\n> >> > -        * We also leave \"master\" as a special case, since it does not reveal\n> >> > -        * anything interesting.\n> >> > +        * We also leave the default branch name as a special case, since it\n> >> > +        * does not reveal anything interesting.\n> >> >          */\n> >> I feel this is a weird thing to do, since you're trying to anonymize the branch\n> >> name,and now the default branch is identifiable with your config file.  For\n> >> example, if the default branch contains the name of my project/repo then this\n> >> sounds like a recipe for accidentally sharing it. I feel a better\n> >> alternative would\n> >> be to exclude nothing from the anonymization or the proposed default default\n> >> branch name\n> >\n> > I don't think that the name of the main branch should be subject to\n> > anonymizing, whether it be `master` or anything else.\n>\n> \"Here is why\" is missing ;-)  I think you realized that it needs to\n> be, after you wrote the \"ah, we need two, the default for new ones\n> and the name of the primary branch in a particular repository\", as\n> we are dealing with the latter here.\n\nYep, absolutely.\n\nThanks,\nDscho\n"},{"id":"399581","messageId":"xmqqa7184g7o.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006121403340.56@tvgsbejvaqbjf.bet","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-12T12:32:43Z","receivedAt":"2020-06-12T12:32:51Z","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> BTW I heard from a couple sides that \"primary\" would imply that there is\n> also a \"secondary\" branch, and potentially an ordering of all branches,\n> which is why I did not really consider \"primary\" as candidate. Besides, it\n> is so much more awkward to type than \"main\" (especially when you're as\n> tired as I am right now...).\n>\n> That's why I try to stay with \"main\" for the moment.\n\nYou are reading too much into it.  I used \"primary\" because I needed\na word that clearly conveys the concept of being a special among\nothers, a word that is about the concept which is different from the\nconcept of \"default\", and that is clearly different from any of the\ncandidates floated as concrete words to replace 'master'.  Because I\nwanted to say things like:\n\n    In the context of fast-export, you'd want to special case the\n    \"primary\" branch name, because unlike the \"default\" branch name\n    (which we envision to be 'main' for most people in the new world\n    order, so it may be less worth anonymizing because of the same\n    reason the current code keeps 'master' as-is), its name can be\n    sensitive.\n\nwithout becoming unnecessarily ambiguous (replace 'primary' with\n'main' in the above).\n\nIt was not because I do not want us to pick 'main' as the\nreplacement word for 'master' as the default branch name.\n\nAnd a set of things, among which there is a concept of \"one thing\nthat is special and different from all the others\", does not\nnecessarily have to be a totally ordered set.  When cloning, we say\nthat the (often bare) repository at the other end indicates which\nbranch is the primary branch of the project by pointing at it with\nits HEAD (which is the reason why we try to fork it to our local\nbranch namespace and check it out after cloning).  There is no\n\"secondary\" in such a use case, and there is no need to have one.\n"},{"id":"399582","messageId":"nycvar.QRO.7.76.6.2006121431110.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200611234611.GA6569@camp.crustytoothpaste.net","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-12T12:45:50Z","receivedAt":"2020-06-12T12:46:03Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi brian,\n\nOn Thu, 11 Jun 2020, brian m. carlson wrote:\n\n> On 2020-06-11 at 23:14:46, Junio C Hamano wrote:\n> > Alban Gruin <alban.gruin@gmail.com> writes:\n> >\n> > > Why adding yet another environment variable instead of relying only on a\n> > > config option?  I understand it's for the tests, but can't we add a\n> > > shell function in test-lib.sh (and friends) that tries to read\n> > > `GIT_TEST_DEFAULT_BRANCH_NAME', and, if it exists, sets\n> > > `core.defaultBranchName'?\n> >\n> > Can you produce such a patch that does it cleanly?  My knee jerk\n> > reaction is that I would suspect that you end up having to touch\n> > many places in the t/ scripts, but if you prove otherwise, that\n> > would certainly be appreciated.\n> >\n> > And no,\n> >\n> >     git () { command git -c core.defaultBranchName=master \"$@\" }\n> >\n> > is not an acceptable solution.\n>\n> I would also be delighted to see such a solution, but my experience with\n> the SHA-256 work tells me there's unlikely to be one.  We do a lot of\n> \"git init\" operations in random places in the test suite and as a\n> consequence it's very hard to make a change without touching a large\n> number of tests.\n\nThat's a valid point, indeed.\n\n> If we were writing things today, perhaps we would use a function (e.g.,\n> test_init_repo or such) to wrap this case, but we unfortunately didn't\n> think about that and we're stuck with what we have now unless someone\n> retrofits the test suite.\n\nThere is actually `test_create_repo` (see\nhttps://github.com/git/git/blob/v2.27.0/t/test-lib-functions.sh#L1145-L1159):\n\n\t# Most tests can use the created repository, but some may need to create\n\t# more.\n\t# Usage: test_create_repo <directory>\n\ttest_create_repo () {\n\t\ttest \"$#\" = 1 ||\n\t\tBUG \"not 1 parameter to test-create-repo\"\n\t\trepo=\"$1\"\n\t\tmkdir -p \"$repo\"\n\t\t(\n\t\t\tcd \"$repo\" || error \"Cannot setup test environment\"\n\t\t\t\"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X\" init \\\n\t\t\t\t\"--template=$GIT_BUILD_DIR/templates/blt/\" >&3 2>&4 ||\n\t\t\terror \"cannot run git init -- have you built things yet?\"\n\t\t\tmv .git/hooks .git/hooks-disabled\n\t\t) || exit\n\t}\n\nBut I agree that few test scripts use it:\n\n\t$ git grep 'git init' v2.27.0 -- t/ | wc -l\n\t765\n\n\t$ git grep 'test_create_repo' v2.27.0 -- t/ | wc -l\n\t296\n\nCiao,\nDscho\n"},{"id":"399583","messageId":"xmqq36704fek.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006121401420.56@tvgsbejvaqbjf.bet","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-12T12:50:11Z","receivedAt":"2020-06-12T12:50:15Z","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>> Subject: [PATCH] fast-export: do anonymize the primary branch name\n>\n> I like this approach a lot. Do you want me to integrate it into this patch\n> series, or rather have it as a stand-alone patch?\n\nI do not see any need for an off-series preparation step.  Without\nconfigurable primary branch, keeping 'master' as 'master' used in\nthe current code is an OK way to anonymize refs and still keep the\nprimary line of development in the output identifyable.  The \"ref0\"\ntrick becomes necessary only when we introduce configurable primary;\neven though it would not hurt to switch to the \"ref0\" approach to\nanonymize-but-still-the-primary-is-identifiable early, it just is\nnot necessary to do so.\n\nI'd say that we should take <xmqqpna5bq2l.fsf_-_@gitster.c.googlers.com>\nwith two changes,\n\n - see if the \"refname\" matches the fully\n   spelled primary branch name by asking repo_main_branch_name(repo,\n   0), instead of comparing with \"refs/heads/master\", and\n\n - if matches return \"refs/heads/ref0\" instead of \"ref0\".\n\nand replace your [PATCH 8/9] (or whichever the counterpart patch is\nin the rerolled series) with it.\n\nThanks.\n"},{"id":"399584","messageId":"nycvar.QRO.7.76.6.2006121451100.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqpna5bq2l.fsf_-_@gitster.c.googlers.com","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-12T12:53:34Z","receivedAt":"2020-06-12T12:54:19Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Thu, 11 Jun 2020, Junio C Hamano wrote:\n\n> diff --git a/builtin/fast-export.c b/builtin/fast-export.c\n> index 85868162ee..a306a60d25 100644\n> --- a/builtin/fast-export.c\n> +++ b/builtin/fast-export.c\n> @@ -522,7 +522,7 @@ static const char *anonymize_refname(const char *refname)\n>  \t * anything interesting.\n>  \t */\n>  \tif (!strcmp(refname, \"refs/heads/master\"))\n> -\t\treturn refname;\n> +\t\treturn \"ref0\";\n\nI just realized that the comment above reads:\n\n        /*\n         * We also leave \"master\" as a special case, since it does not reveal\n         * anything interesting.\n         */\n\n\nObviously, we need to change that comment here because we do not leave the\nname unchanged. How about this?\n\n        /*\n         * We special-case the main branch, anonymizing it to `ref0`.\n         */\n\nCiao,\nDscho\n\n>\n>  \tstrbuf_reset(&anon);\n>  \tfor (i = 0; i < ARRAY_SIZE(prefixes); i++) {\n>\n"},{"id":"399585","messageId":"nycvar.QRO.7.76.6.2006121518160.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006121451100.56@tvgsbejvaqbjf.bet","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-12T13:18:57Z","receivedAt":"2020-06-12T13:19:13Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Fri, 12 Jun 2020, Johannes Schindelin wrote:\n\n> On Thu, 11 Jun 2020, Junio C Hamano wrote:\n>\n> > diff --git a/builtin/fast-export.c b/builtin/fast-export.c\n> > index 85868162ee..a306a60d25 100644\n> > --- a/builtin/fast-export.c\n> > +++ b/builtin/fast-export.c\n> > @@ -522,7 +522,7 @@ static const char *anonymize_refname(const char *refname)\n> >  \t * anything interesting.\n> >  \t */\n> >  \tif (!strcmp(refname, \"refs/heads/master\"))\n> > -\t\treturn refname;\n> > +\t\treturn \"ref0\";\n>\n> I just realized that the comment above reads:\n>\n>         /*\n>          * We also leave \"master\" as a special case, since it does not reveal\n>          * anything interesting.\n>          */\n>\n>\n> Obviously, we need to change that comment here because we do not leave the\n> name unchanged. How about this?\n>\n>         /*\n>          * We special-case the main branch, anonymizing it to `ref0`.\n>          */\n\nAlso, t9351 obviously needs to be adjusted. This one works for me:\n\n-- snipsnap --\nFrom: Junio C Hamano <gitster@pobox.com>\nDate: Thu, 11 Jun 2020 08:05:38 -0700\nSubject: [PATCH] fast-export: do anonymize the primary branch name\n\nIn a fast-export stream with --anonymize option, all the end-user\ndata including refnames are munged to prevent exposure, but the\n'master' branch is left intact.\n\nThere is a comment that explains why it is OK to leave 'master'\nunanonymized (because everybody calls the primary branch 'master'\nand it is no secret), but that does not justify why it is bad to\nanonymize 'master' and make it undistinguishable from other\nbranches.  Assuming there _is_ a need to allow the readers of the\noutput to tell where the tip of the primary branch is, let's keep\nthe special casing of 'master', but still anonymize it to \"ref0\".\nBecause all other branches will be given ref+N where N is a positive\ninteger, this will keep the primary branch identifiable in the\noutput stream, without exposing what the name of the primary branch\nis in the repository the export stream was taken from.\n\nThis is in preparation for introducing a mechanism to affect the\nname of the primary branch used in the repository.  Once the\nmechanism is in use, the name of the primary branch won't be\n'master', and may not be allowed to be exposed.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/fast-export.c            | 7 +++----\n t/t9351-fast-export-anonymize.sh | 9 +++++----\n 2 files changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 85868162eec..f10e3b35e5b 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -497,7 +497,7 @@ static void *anonymize_ref_component(const void *old, size_t *len)\n {\n \tstatic int counter;\n \tstruct strbuf out = STRBUF_INIT;\n-\tstrbuf_addf(&out, \"ref%d\", counter++);\n+\tstrbuf_addf(&out, \"ref%d\", ++counter);\n \treturn strbuf_detach(&out, len);\n }\n\n@@ -518,11 +518,10 @@ static const char *anonymize_refname(const char *refname)\n \tint i;\n\n \t/*\n-\t * We also leave \"master\" as a special case, since it does not reveal\n-\t * anything interesting.\n+\t * We special-case the main branch, anonymizing it to `ref0`.\n \t */\n \tif (!strcmp(refname, \"refs/heads/master\"))\n-\t\treturn refname;\n+\t\treturn \"refs/heads/ref0\";\n\n \tstrbuf_reset(&anon);\n \tfor (i = 0; i < ARRAY_SIZE(prefixes); i++) {\ndiff --git a/t/t9351-fast-export-anonymize.sh b/t/t9351-fast-export-anonymize.sh\nindex 897dc509075..2415f0ec213 100755\n--- a/t/t9351-fast-export-anonymize.sh\n+++ b/t/t9351-fast-export-anonymize.sh\n@@ -26,8 +26,9 @@ test_expect_success 'stream omits path names' '\n \t! grep xyzzy stream\n '\n\n-test_expect_success 'stream allows master as refname' '\n-\tgrep master stream\n+test_expect_success 'stream translates master to ref0' '\n+\tgrep refs/heads/ref0 stream &&\n+\t! grep master stream\n '\n\n test_expect_success 'stream omits other refnames' '\n@@ -57,7 +58,7 @@ test_expect_success 'import stream to new repository' '\n test_expect_success 'result has two branches' '\n \tgit for-each-ref --format=\"%(refname)\" refs/heads >branches &&\n \ttest_line_count = 2 branches &&\n-\tother_branch=$(grep -v refs/heads/master branches)\n+\tother_branch=$(grep -v refs/heads/ref0 branches)\n '\n\n test_expect_success 'repo has original shape and timestamps' '\n@@ -65,7 +66,7 @@ test_expect_success 'repo has original shape and timestamps' '\n \t\tgit log --format=\"%m %ct\" --left-right --boundary \"$@\"\n \t} &&\n \t(cd .. && shape master...other) >expect &&\n-\tshape master...$other_branch >actual &&\n+\tshape ref0...$other_branch >actual &&\n \ttest_cmp expect actual\n '\n\n--\n2.26.0.windows.1\n\n"},{"id":"399593","messageId":"xmqqy2os2u55.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006121451100.56@tvgsbejvaqbjf.bet","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-12T15:14:46Z","receivedAt":"2020-06-12T15:14:49Z","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 just realized that the comment above reads:\n>\n>         /*\n>          * We also leave \"master\" as a special case, since it does not reveal\n>          * anything interesting.\n>          */\n>\n>\n> Obviously, we need to change that comment here because we do not leave the\n> name unchanged. How about this?\n>\n>         /*\n>          * We special-case the main branch, anonymizing it to `ref0`.\n>          */\n\nIf you are going to update it, why not make it useful?\n\nI complained number of times during the discussion that the original\ncomment explains why leaving 'master' as-is does not reveal anything\nuseful to adversaries but does not justify what the code attempts to\nachieve by special casing 'master' in the first place.  \n\nIt is not an improvement to literally adjust that inadequate comment\nto the new world order to just parrot what the code already says\nwithout explaining why it does so.\n\n\t/*\n\t * Anonymize the name used for the primary branch in this\n\t * repository, but reserve `ref0` for it, so that it can\n\t * be identified among other refs in the output.\n\t */\n\nis the minimum I would expect before calling it an improvement.  We\ncould add\n\n\tIt is often `main` for new repositories (and `master` for\n\taged ones) and such well-known names may not need\n\tanonymizing, but it could be configured to use a secret word\n\tthat the user may not want to reveal.\n\nat the end to explain the motivation behind anonymizing even more,\nif we wanted to.\n\nNow, \"so that ...\" part is totally a fabrication based on my best\nguess.  I do not know what the original author was thinking when the\ndecision to leave the master as-is was made.\n\nThanks.\n"},{"id":"399594","messageId":"xmqqtuzg2twq.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006121518160.56@tvgsbejvaqbjf.bet","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-12T15:19:49Z","receivedAt":"2020-06-12T15:19:54Z","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> Also, t9351 obviously needs to be adjusted. This one works for me:\n>\n> -- snipsnap --\n> From: Junio C Hamano <gitster@pobox.com>\n> Date: Thu, 11 Jun 2020 08:05:38 -0700\n> Subject: [PATCH] fast-export: do anonymize the primary branch name\n>\n> In a fast-export stream with --anonymize option, all the end-user\n> data including refnames are munged to prevent exposure, but the\n> 'master' branch is left intact.\n> ...\n> This is in preparation for introducing a mechanism to affect the\n> name of the primary branch used in the repository.  Once the\n> mechanism is in use, the name of the primary branch won't be\n> 'master', and may not be allowed to be exposed.\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>  builtin/fast-export.c            | 7 +++----\n>  t/t9351-fast-export-anonymize.sh | 9 +++++----\n>  2 files changed, 8 insertions(+), 8 deletions(-)\n> ...\n>  \tif (!strcmp(refname, \"refs/heads/master\"))\n> -\t\treturn refname;\n> +\t\treturn \"refs/heads/ref0\";\n\nAs I said already, I personally do not think that this needs to be a\npreparatory patch to anonymize 'master' that cannot be configured to\nsomething else into 'ref0'.  This will become necessary when we make\nthe primary branch configurable, so I think it is easier to replace\nthe counterpart to your [PATCH 8/9] in the original series with it\nin the v2 series.\n\nRegarding the update to the comment before this \"special case\", I\nwould suggest to explain \"why\" not just \"what\".\n\nThanks.\n\n"},{"id":"399595","messageId":"xmqqpna42tt3.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"xmqqtuzg2twq.fsf@gitster.c.googlers.com","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-12T15:22:00Z","receivedAt":"2020-06-12T15:22:04Z","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> As I said already, I personally do not think that this needs to be a\n> preparatory patch to anonymize 'master' that cannot be configured to\n> something else into 'ref0'.  This will become necessary when we make\n> the primary branch configurable, so I think it is easier to replace\n> the counterpart to your [PATCH 8/9] in the original series with it\n> in the v2 series.\n\nAh, I forgot to say, if you think it is easier to manage the main\nset of patches for the topic to eject as much preparatory changes as\npossible, I do not at all mind treating this as one of the\npreparatory step and queue it separately, making the main series\ndepend on it.  I just wanted to say that it is not necessary, even\nthough it does not hurt.\n\n\n\n> Regarding the update to the comment before this \"special case\", I\n> would suggest to explain \"why\" not just \"what\".\n>\n> Thanks.\n"},{"id":"399607","messageId":"xmqqlfks2pod.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006121308030.56@tvgsbejvaqbjf.bet","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-12T16:51:14Z","receivedAt":"2020-06-12T16:51:20Z","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 added a _brief_ extension to the context to the first commit's commit\n> message. However, I do not want to go into details here because _this_\n> patch series is only about empowering users to change their default main\n> branch name.\n\nSensible.\n\nAnd I do not think the planned follow-up work to rename 'master' to\nsomething else needs to be defended with lengthy history lessons.\n\nSufficiently large part of the user population are unhappy with the\nuse of the word 'master' as the default name of the primary branch\nin a newly created repository, and the mere fact that we are aware\nof that is good enough justification to move _away_ from 'master'.\nIn other words, we do not have to explain why 'master' was bad, as\nit does not have to be bad for everybody to be replaced.\n\nBut you need to defend that the new word you picked is something\neverybody is happy with.  That is much harder ;-).\n"},{"id":"399641","messageId":"nycvar.QRO.7.76.6.2006130658330.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqpna42tt3.fsf@gitster.c.googlers.com","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-13T05:00:16Z","receivedAt":"2020-06-13T07:57:26Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Fri, 12 Jun 2020, Junio C Hamano wrote:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n> > As I said already, I personally do not think that this needs to be a\n> > preparatory patch to anonymize 'master' that cannot be configured to\n> > something else into 'ref0'.  This will become necessary when we make\n> > the primary branch configurable, so I think it is easier to replace\n> > the counterpart to your [PATCH 8/9] in the original series with it\n> > in the v2 series.\n>\n> Ah, I forgot to say, if you think it is easier to manage the main\n> set of patches for the topic to eject as much preparatory changes as\n> possible, I do not at all mind treating this as one of the\n> preparatory step and queue it separately, making the main series\n> depend on it.  I just wanted to say that it is not necessary, even\n> though it does not hurt.\n\nDue to the need to adjust t9351, I think it is clearer if it is a two-part\nchange: one to introduce the \"main branch -> ref0\" change, and another one\nto respect `core.mainBranch`. Those are separate concerns in my mind.\n\nI moved the first one to the beginning of the patch series so that you're\nstill at liberty to take it early vs keeping it within the topic branch.\n\nThanks,\nDscho\n"},{"id":"399647","messageId":"405521ec-aed7-ff76-5b48-70e9d11018e6@kdbg.org","threadId":"53651","inReplyTo":"xmqqy2os2u55.fsf@gitster.c.googlers.com","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2020-06-13T11:49:13Z","receivedAt":"2020-06-13T11:52:50Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 12.06.20 um 17:14 schrieb Junio C Hamano:\n> \t/*\n> \t * Anonymize the name used for the primary branch in this\n> \t * repository, but reserve `ref0` for it, so that it can\n> \t * be identified among other refs in the output.\n> \t */\n> \n> is the minimum I would expect before calling it an improvement.  We\n> could add\n> \n> \tIt is often `main` for new repositories (and `master` for\n> \taged ones) and such well-known names may not need\n> \tanonymizing, but it could be configured to use a secret word\n> \tthat the user may not want to reveal.\n> \n> at the end to explain the motivation behind anonymizing even more,\n> if we wanted to.\n\nIMO, making the primary branch identifiable is a reasonable\njustification to treat it specially. But then, why does it have to be\nrenamed to 'ref0'? Couldn't it just be renamed to Git's default primary\nbranch name, be it 'master' today or 'main' or whatever in the future?\nAfter the anonymization, nobody will know whether that was the real name\nof the primary branch or not. Leaving it at 'master'/'main' reduces the\nmental burden of the recipient of the anonymous repo.\n\n-- Hannes\n"},{"id":"399655","messageId":"xmqqv9jvylt7.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"405521ec-aed7-ff76-5b48-70e9d11018e6@kdbg.org","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-13T16:25:56Z","receivedAt":"2020-06-13T16:29:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j6t@kdbg.org> writes:\n\n> Am 12.06.20 um 17:14 schrieb Junio C Hamano:\n>> \t/*\n>> \t * Anonymize the name used for the primary branch in this\n>> \t * repository, but reserve `ref0` for it, so that it can\n>> \t * be identified among other refs in the output.\n>> \t */\n>> \n>> is the minimum I would expect before calling it an improvement.  We\n>> could add\n>> \n>> \tIt is often `main` for new repositories (and `master` for\n>> \taged ones) and such well-known names may not need\n>> \tanonymizing, but it could be configured to use a secret word\n>> \tthat the user may not want to reveal.\n>> \n>> at the end to explain the motivation behind anonymizing even more,\n>> if we wanted to.\n>\n> IMO, making the primary branch identifiable is a reasonable\n> justification to treat it specially. But then, why does it have to be\n> renamed to 'ref0'? Couldn't it just be renamed to Git's default primary\n> branch name, be it 'master' today or 'main' or whatever in the future?\n\nThat comes from https://lore.kernel.org/git/xmqqtuzha6xn.fsf@gitster.c.googlers.com/\n\nBut I agree with you 100% if you literally mean 'master' (or 'main')\nhardcoded without any end-user customization.  What I rejected and\nreplaced with the vanilla \"ref0\" was to return the configured name\nthat will be used for the primary branch in new repositories.  The\nabove proposal suggested a faulty:\n\n-\tif (!strcmp(refname, \"refs/heads/master\"))\n-\t\treturn refname;\n+\tif (!strcmp(refname, get_primary_branch_name(DO_NOT_ABBREV)))\n+\t\treturn get_default_branch_name(DO_NOT_ABBREV);\n\nA corrected code should return a hardwired constant 'main' (it\nprobably gets behind a C preprocessor macro, but the point is that\nwe do not want end-user customization) for the reason stated in that\nmessage.\n\nThanks.\n"},{"id":"399660","messageId":"nycvar.QRO.7.76.6.2006130703340.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqy2os2u55.fsf@gitster.c.googlers.com","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-13T14:44:24Z","receivedAt":"2020-06-13T17:32:20Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Fri, 12 Jun 2020, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n>\n> > I just realized that the comment above reads:\n> >\n> >         /*\n> >          * We also leave \"master\" as a special case, since it does not reveal\n> >          * anything interesting.\n> >          */\n> >\n> >\n> > Obviously, we need to change that comment here because we do not leave the\n> > name unchanged. How about this?\n> >\n> >         /*\n> >          * We special-case the main branch, anonymizing it to `ref0`.\n> >          */\n>\n> If you are going to update it, why not make it useful?\n>\n> I complained number of times during the discussion that the original\n> comment explains why leaving 'master' as-is does not reveal anything\n> useful to adversaries but does not justify what the code attempts to\n> achieve by special casing 'master' in the first place.\n\nTrue. Sorry about forgetting that when adjusting the code comment.\n\nIn my defense, I am/was much more worried about transmogrifying the patch\nseries to reflect the separation between `init.defaultBranch` and\n`core.mainBranch` and the associated fall-out (I highly doubt that the\nrange-diff between v1 and v2 will be useful...).\n\n> It is not an improvement to literally adjust that inadequate comment\n> to the new world order to just parrot what the code already says\n> without explaining why it does so.\n>\n> \t/*\n> \t * Anonymize the name used for the primary branch in this\n> \t * repository, but reserve `ref0` for it, so that it can\n> \t * be identified among other refs in the output.\n> \t */\n\nThat is indeed an improvement, thank you so much.\n\n> is the minimum I would expect before calling it an improvement.  We\n> could add\n>\n> \tIt is often `main` for new repositories (and `master` for\n> \taged ones) and such well-known names may not need\n> \tanonymizing, but it could be configured to use a secret word\n> \tthat the user may not want to reveal.\n>\n> at the end to explain the motivation behind anonymizing even more,\n> if we wanted to.\n\nMaybe we add that to the comment in the patch that teaches `fast-export`\nabout `core.mainBranch`? Yeah, I think I like that idea best.\n\n> Now, \"so that ...\" part is totally a fabrication based on my best\n> guess.  I do not know what the original author was thinking when the\n> decision to leave the master as-is was made.\n\nThis comment comes from a8722750985 (teach fast-export an --anonymize\noption, 2014-08-27), and I agree that there is no explicit explanation why\nthe main branch is special-cased.\n\nHowever, I think that your guess is a good one: it might be an interesting\naspect to identify the commits from the main branch, without necessarily\nneeding to know the actual name of said branch, e.g. to reproduce a\nreported issue.\n\nCiao,\nDscho\n"},{"id":"399661","messageId":"nycvar.QRO.7.76.6.2006131645380.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqv9jvylt7.fsf@gitster.c.googlers.com","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-13T14:47:59Z","receivedAt":"2020-06-13T17:35:52Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio & Hannes,\n\nOn Sat, 13 Jun 2020, Junio C Hamano wrote:\n\n> Johannes Sixt <j6t@kdbg.org> writes:\n>\n> > Am 12.06.20 um 17:14 schrieb Junio C Hamano:\n> >> \t/*\n> >> \t * Anonymize the name used for the primary branch in this\n> >> \t * repository, but reserve `ref0` for it, so that it can\n> >> \t * be identified among other refs in the output.\n> >> \t */\n> >>\n> >> is the minimum I would expect before calling it an improvement.  We\n> >> could add\n> >>\n> >> \tIt is often `main` for new repositories (and `master` for\n> >> \taged ones) and such well-known names may not need\n> >> \tanonymizing, but it could be configured to use a secret word\n> >> \tthat the user may not want to reveal.\n> >>\n> >> at the end to explain the motivation behind anonymizing even more,\n> >> if we wanted to.\n> >\n> > IMO, making the primary branch identifiable is a reasonable\n> > justification to treat it specially. But then, why does it have to be\n> > renamed to 'ref0'? Couldn't it just be renamed to Git's default primary\n> > branch name, be it 'master' today or 'main' or whatever in the future?\n>\n> That comes from https://lore.kernel.org/git/xmqqtuzha6xn.fsf@gitster.c.googlers.com/\n>\n> But I agree with you 100% if you literally mean 'master' (or 'main')\n> hardcoded without any end-user customization.  What I rejected and\n> replaced with the vanilla \"ref0\" was to return the configured name\n> that will be used for the primary branch in new repositories.  The\n> above proposal suggested a faulty:\n>\n> -\tif (!strcmp(refname, \"refs/heads/master\"))\n> -\t\treturn refname;\n> +\tif (!strcmp(refname, get_primary_branch_name(DO_NOT_ABBREV)))\n> +\t\treturn get_default_branch_name(DO_NOT_ABBREV);\n>\n> A corrected code should return a hardwired constant 'main' (it\n> probably gets behind a C preprocessor macro, but the point is that\n> we do not want end-user customization) for the reason stated in that\n> message.\n\nI like `ref0` better, for two reasons:\n\n- it is more consistent to just have all anonymized branches be named\n  `ref<N>`, and\n\n- using `main` both for an original `main` and an original `master` can be\n  a bit confusing, as the reader might assume that this branch name (as it\n  does not follow the `ref<N>` convention) was _not_ anonymized, when it\n  very well might have been.\n\nCiao,\nDscho\n"},{"id":"399663","messageId":"731205c8-7d4b-d87a-17d1-520fdec7375d@gmail.com","threadId":"53651","inReplyTo":"xmqqwo4di49l.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Alban Gruin","fromEmail":"alban.gruin@gmail.com","sentAt":"2020-06-13T18:01:02Z","receivedAt":"2020-06-13T18:01:08Z","isPatch":true,"sender":{"key":"alban.gruin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6310153?v=4"},"body":"Hi Junio,\n\nLe 12/06/2020 à 01:14, Junio C Hamano a écrit :\n> Alban Gruin <alban.gruin@gmail.com> writes:\n> \n>> Why adding yet another environment variable instead of relying only on a\n>> config option?  I understand it's for the tests, but can't we add a\n>> shell function in test-lib.sh (and friends) that tries to read\n>> `GIT_TEST_DEFAULT_BRANCH_NAME', and, if it exists, sets\n>> `core.defaultBranchName'?\n> \n> Can you produce such a patch that does it cleanly?  My knee jerk\n> reaction is that I would suspect that you end up having to touch\n> many places in the t/ scripts, but if you prove otherwise, that\n> would certainly be appreciated.\n> \n> And no, \n> \n>     git () { command git -c core.defaultBranchName=master \"$@\" }\n> \n> is not an acceptable solution.\n> \n\nI wanted to to do something like this:\n\n  if test -n \"$GIT_TEST_DEFAULT_BRANCH_NAME\";\n  then\n      git config core.defaultBranchName \"$GIT_TEST_DEFAULT_BRANCH_NAME\"\n  fi\n\nBut since we do not have a repository to store the config, it won't\nwork.  Sorry for the noise.\n\nAlban\n\n"},{"id":"399664","messageId":"xmqqeeqiztpq.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006131645380.56@tvgsbejvaqbjf.bet","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-13T18:49:53Z","receivedAt":"2020-06-13T18:50:04Z","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>> A corrected code should return a hardwired constant 'main' (it\n>> probably gets behind a C preprocessor macro, but the point is that\n>> we do not want end-user customization) for the reason stated in that\n>> message.\n>\n> I like `ref0` better, for two reasons:\n>\n> - it is more consistent to just have all anonymized branches be named\n>   `ref<N>`, and\n>\n> - using `main` both for an original `main` and an original `master` can be\n>   a bit confusing, as the reader might assume that this branch name (as it\n>   does not follow the `ref<N>` convention) was _not_ anonymized, when it\n>   very well might have been.\n\nA pro for keeping a hardcoded 'master' is that it is compatible with\nthe current world order, and flipping it to hardcoded 'main' upon\ntransition is just to use the moral equivalent, so we do not need to\nimmediately have to change anything.  The _new_ consistency across\nref<N> does feel attractive, but because it is new, there always is\na pushback not to \"fix\" what is not broken.\n\nI am personally OK either way.  \n\nBy the way, we'd need to devise a transition plan for switching the\ndefault branch name (i.e. the name used for the primary branch in a\nnewly created repository unless the user configures it to some other\nvalue) to 'main' (oh, I just found one reason why I will not want to\nuse that name in my project(s)---it is too close to 'maint').  \n\nIt might roughly go like:\n\n 1. We introduce core.defaultBranchName; when it is not set, its\n    value defaults to 'master' in the 1st phase of the transition.\n    \"git init\" and \"git clone\" however issue a warning that says\n    \"unless you configure core.defaultBranchName, we use 'master'\n    for now for backward compatibility but we will start using\n    'main' in three major releases of Git in the future\".  These\n    commands use the default branch name when creating a new\n    repository in the 1st phase, and set core.primaryBranchName to\n    that name in the resulting repository.\n\n    This is to encourage early adopters to set it to 'maint'^W'main'\n    (eek, see, I again made that typo), while allowing those who\n    have toolset that depends more heavily on the current default\n    branch name than other people to set it to 'master' for\n    stability.\n\n    In the 1st phase, a few commands that care about what the\n    primary branch is in a repository (i.e. fmt-merge-msg and\n    fast-export are the two we have identified so far) pay attention\n    to the core.primaryBranchName configuration, and default to\n    'master' if the configuration does not exist.  \n\n    These commands issue a warning that says \"unless you configure\n    core.primaryBranchName in the repository, we use 'master' for\n    now but we will start using 'main' in three major releases of\n    Git in the future\".\n\n    The above two warning messages will be squelched once the user\n    sets respective configuration variable.\n\n 2. We flip the default for the two variables from 'master' to\n    'main' in three major releases of Git (i.e. 24-30 weeks from the\n    1st phase).  The two warning messages added for the 1st phase\n    will be reworded for the updated default.  We no longer need to\n    say \"in three major releases\" in there.\n\n 3. After long time passes, remove the warning.\n\n"},{"id":"399728","messageId":"nycvar.QRO.7.76.6.2006141053170.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqeeqiztpq.fsf@gitster.c.googlers.com","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-14T08:55:29Z","receivedAt":"2020-06-14T21:29:03Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Sat, 13 Jun 2020, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n>\n> >> A corrected code should return a hardwired constant 'main' (it\n> >> probably gets behind a C preprocessor macro, but the point is that\n> >> we do not want end-user customization) for the reason stated in that\n> >> message.\n> >\n> > I like `ref0` better, for two reasons:\n> >\n> > - it is more consistent to just have all anonymized branches be named\n> >   `ref<N>`, and\n> >\n> > - using `main` both for an original `main` and an original `master` can be\n> >   a bit confusing, as the reader might assume that this branch name (as it\n> >   does not follow the `ref<N>` convention) was _not_ anonymized, when it\n> >   very well might have been.\n>\n> A pro for keeping a hardcoded 'master' is that it is compatible with\n> the current world order, and flipping it to hardcoded 'main' upon\n> transition is just to use the moral equivalent, so we do not need to\n> immediately have to change anything.  The _new_ consistency across\n> ref<N> does feel attractive, but because it is new, there always is\n> a pushback not to \"fix\" what is not broken.\n>\n> I am personally OK either way.\n>\n> By the way, we'd need to devise a transition plan for switching the\n> default branch name (i.e. the name used for the primary branch in a\n> newly created repository unless the user configures it to some other\n> value) to 'main' (oh, I just found one reason why I will not want to\n> use that name in my project(s)---it is too close to 'maint').\n\nYes, the trouble with `maint` did cross my mind, but I try not to\n\"overfit\" to git/git. :-)\n\n> It might roughly go like:\n>\n>  1. We introduce core.defaultBranchName; when it is not set, its\n>     value defaults to 'master' in the 1st phase of the transition.\n>     \"git init\" and \"git clone\" however issue a warning that says\n>     \"unless you configure core.defaultBranchName, we use 'master'\n>     for now for backward compatibility but we will start using\n>     'main' in three major releases of Git in the future\".  These\n>     commands use the default branch name when creating a new\n>     repository in the 1st phase, and set core.primaryBranchName to\n>     that name in the resulting repository.\n>\n>     This is to encourage early adopters to set it to 'maint'^W'main'\n>     (eek, see, I again made that typo), while allowing those who\n>     have toolset that depends more heavily on the current default\n>     branch name than other people to set it to 'master' for\n>     stability.\n>\n>     In the 1st phase, a few commands that care about what the\n>     primary branch is in a repository (i.e. fmt-merge-msg and\n>     fast-export are the two we have identified so far) pay attention\n>     to the core.primaryBranchName configuration, and default to\n>     'master' if the configuration does not exist.\n>\n>     These commands issue a warning that says \"unless you configure\n>     core.primaryBranchName in the repository, we use 'master' for\n>     now but we will start using 'main' in three major releases of\n>     Git in the future\".\n>\n>     The above two warning messages will be squelched once the user\n>     sets respective configuration variable.\n>\n>  2. We flip the default for the two variables from 'master' to\n>     'main' in three major releases of Git (i.e. 24-30 weeks from the\n>     1st phase).  The two warning messages added for the 1st phase\n>     will be reworded for the updated default.  We no longer need to\n>     say \"in three major releases\" in there.\n>\n>  3. After long time passes, remove the warning.\n\nYes, that's what I had in my mind, too (modulo the concrete part about the\nthree major versions, which is something I would have asked about at some\nstage, thank you for answering that question already!).\n\nThank you,\nDscho\n"},{"id":"399729","messageId":"nycvar.QRO.7.76.6.2006141055510.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"731205c8-7d4b-d87a-17d1-520fdec7375d@gmail.com","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-14T08:57:41Z","receivedAt":"2020-06-14T21:31:09Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Alban,\n\nOn Sat, 13 Jun 2020, Alban Gruin wrote:\n\n> Hi Junio,\n>\n> Le 12/06/2020 à 01:14, Junio C Hamano a écrit :\n> > Alban Gruin <alban.gruin@gmail.com> writes:\n> >\n> >> Why adding yet another environment variable instead of relying only on a\n> >> config option?  I understand it's for the tests, but can't we add a\n> >> shell function in test-lib.sh (and friends) that tries to read\n> >> `GIT_TEST_DEFAULT_BRANCH_NAME', and, if it exists, sets\n> >> `core.defaultBranchName'?\n> >\n> > Can you produce such a patch that does it cleanly?  My knee jerk\n> > reaction is that I would suspect that you end up having to touch\n> > many places in the t/ scripts, but if you prove otherwise, that\n> > would certainly be appreciated.\n> >\n> > And no,\n> >\n> >     git () { command git -c core.defaultBranchName=master \"$@\" }\n> >\n> > is not an acceptable solution.\n> >\n>\n> I wanted to to do something like this:\n>\n>   if test -n \"$GIT_TEST_DEFAULT_BRANCH_NAME\";\n>   then\n>       git config core.defaultBranchName \"$GIT_TEST_DEFAULT_BRANCH_NAME\"\n>   fi\n>\n> But since we do not have a repository to store the config, it won't\n> work.  Sorry for the noise.\n\nWe actually would have `~/.gitconfig` because `HOME` is set to `t/trash\ndirectory.<test-name>/`.\n\nHowever, that would cause all kinds of issues when test scripts expect the\ndirectory to be pristine, containing only `.git/` but not `.gitconfig`.\n\nIt was a good idea to bring up; I share brian's sentiment that it would\nhave been nice if it would have worked out.\n\nCiao,\nDscho\n"},{"id":"399745","messageId":"27936112-a29b-92d5-b506-3f88688cc5d3@gmail.com","threadId":"53651","inReplyTo":"xmqqlfks2pod.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2020-06-15T10:00:55Z","receivedAt":"2020-06-15T10:01:09Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 12/06/2020 17:51, Junio C Hamano wrote:\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n>> I added a _brief_ extension to the context to the first commit's commit\n>> message. However, I do not want to go into details here because _this_\n>> patch series is only about empowering users to change their default main\n>> branch name.\n> \n> [...]\n> \n> Sufficiently large part of the user population are unhappy with the\n> use of the word 'master' as the default name of the primary branch\n> in a newly created repository, and the mere fact that we are aware\n> of that is good enough justification to move _away_ from 'master'.\n> In other words, we do not have to explain why 'master' was bad, as\n> it does not have to be bad for everybody to be replaced.\n\nThis expresses what I was trying to get at with my comments much more\nclearly than I managed - Thank you\n\n> \n> But you need to defend that the new word you picked is something\n> everybody is happy with.  That is much harder ;-).\n\nIndeed, though I am more optimistic about that having seen a couple of\npeople have indicated that they don't mind too much what we choose so\nlong as it unlikely to cause future problems.\n\nBest Wishes\n\nPhillip\n\n\n"},{"id":"399746","messageId":"20200615100327.3mwft27oj7h2bixg@yadavpratyush.com","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Pratyush Yadav","fromEmail":"me@yadavpratyush.com","sentAt":"2020-06-15T10:03:27Z","receivedAt":"2020-06-15T10:03:36Z","isPatch":true,"sender":{"key":"me@yadavpratyush.com","avatar":"https://avatars.githubusercontent.com/u/8817931?v=4"},"body":"Hi,\n\nOn 10/06/20 09:19PM, Johannes Schindelin via GitGitGadget wrote:\n> A growing number of open source projects aims to avoid the branch name \n> master due to its negative connotation. See [1] for an existing discussion\n> on this. The links [2], [3], and [4] describe community-driven ways for\n> users to rename their default branches or use template edits to set a new\n> default branch name.\n> \n> [1] \n> https://lore.kernel.org/git/CAOAHyQwyXC1Z3v7BZAC+Bq6JBaM7FvBenA-1fcqeDV==apdWDg@mail.gmail.com/\n> \n> [2] https://twitter.com/mislav/status/1270388510684598272\n> \n> [3] \n> https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx\n> \n> [4] https://github.com/ethomson/retarget_prs\n> \n> By necessity, existing repositories require a lot of manual work to move\n> away from that branch name, but it should be much easier for new\n> repositories.\n> \n> This patch series allows overriding the branch name being used for new\n> repositories' main branch. The main way to do this is the new \n> core.defaultBranchName config option. This first patch was contributed by\n> newcomer Dan Goodman-Wilson. Thanks for the contribution!\n> \n> The other patches follow other places where \"master\" is hard-coded and use\n> the new git_default_branch_name() method to consume the config option before\n> falling back to \"master\".\n> \n> The last patch updates documentation only after the config option is ready\n> to apply to all of these scenarios.\n> \n> This series DOES NOT change the default automatically, but only provides an\n> opt-in mechanism for interested users. It also presents a way forward for\n> such a transition, if and when we decide to do so. Specifically, the new\n> GIT_TEST_DEFAULT_BRANCH_NAME environment variable could be used to update\n> test scripts on an individual basis instead of all-at-once.\n\nMany people have expressed reservations against this change. Some on the \nlist here, others in private conversation. I personally don't have a \nstrong opinion on either side. So I'll refrain from saying too much on \nthe issue. Reading through the list, I sense that the Git maintainer has \nalready decided it is something good for the project. And so I think \nthis change has a high chance of making it in a near future Git release.  \n\nOne argument from those in favor of this change is that it doesn't \naffect you if you don't care about the default branch name. You can just \ngo on using 'master' for all _your_ repos. I'd like to highlight the \n\"your\" here. Sure, I can keep on using 'master' if I so prefer, but I \ndon't just use my repos. I also pull repos from other people, and I have \nno control over what they call their main/primary/master branch (I'll \nuse \"main\" for the rest of the email). The cost here is that people now \nneed to update their scripts and workflow to account for other people's \nnaming preferences.\n\nFor example, my vim plugins are submodules in the '~/.vim/bundle' \ndirectory. When I want to update them, I run:\n\n  git submodule foreach 'git remote update && git reset --hard origin/master'\n\nWith this change hitting a Git release, more and more people would call \ntheir main branch different names they like. So what is the recommended \nway to do something like this now? How do I checkout the tip of the main \nbranch? How do I push to the main branch? How do I pull from the main \nbranch? And so on...\n\n-- \nRegards,\nPratyush Yadav\n"},{"id":"399748","messageId":"nycvar.QRO.7.76.6.2006142350580.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqlfks2pod.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-14T22:00:24Z","receivedAt":"2020-06-15T10:34:04Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Fri, 12 Jun 2020, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n>\n> > I added a _brief_ extension to the context to the first commit's commit\n> > message. However, I do not want to go into details here because _this_\n> > patch series is only about empowering users to change their default main\n> > branch name.\n>\n> Sensible.\n>\n> And I do not think the planned follow-up work to rename 'master' to\n> something else needs to be defended with lengthy history lessons.\n\nYes, I agree. It is probably sufficient to just point at a couple\nhigh-profile projects that already made the switch to `main`.\n\n> Sufficiently large part of the user population are unhappy with the\n> use of the word 'master' as the default name of the primary branch\n> in a newly created repository, and the mere fact that we are aware\n> of that is good enough justification to move _away_ from 'master'.\n\nYes, even Pasky says he regrets the choice of term (see\nhttps://twitter.com/xpasky/status/1271477451756056577):\n\n\tI picked the names \"master\" (and \"origin\") in the early Git tooling\n\tback in 2005.\n\n\t(this probably means you shouldn't give much weight to my name\n\tpreferences :) )\n\n\tI have wished many times I would have named them \"main\" (and\n\t\"upstream\") instead.\n\n> In other words, we do not have to explain why 'master' was bad, as\n> it does not have to be bad for everybody to be replaced.\n>\n> But you need to defend that the new word you picked is something\n> everybody is happy with.  That is much harder ;-).\n\nTo be honest, I stopped looking for got arguments in favor of one\nname after a couple days, and instead focused on the consensus I\nsaw: Chrome [*1*] and node.js [*2*] apparently stated publicly that\nthey want to change their main branches to `main`, and GitLab [*3*]\nand GitHub [*4*] seem to intend to change the default for new\nrepositories accordingly.\n\nIt is not like we have to decide for the community (as we did back\nin 2005). I am actually quite relieved about that.\n\nCiao,\nDscho\n\nURL *1*: https://twitter.com/Una/status/1271180494944829441\nURL *2*: https://github.com/nodejs/node/issues/33864\nURL *3*: https://gitlab.com/gitlab-org/gitlab/-/issues/221164\nURL *4*: https://twitter.com/natfriedman/status/1271253144442253312\n(this is not really a public announcement, I agree, but it is a\npublic Tweet by the CEO)\n"},{"id":"399749","messageId":"20200615104641.GA54462@generichostname","threadId":"53651","inReplyTo":"06ef42052d534a668bf5227e79f1ca3b5c6aa2c1.1591823971.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 5/9] submodule: use the (possibly overridden) default branch name","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-06-15T10:46:41Z","receivedAt":"2020-06-15T10:46:48Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"On Wed, Jun 10, 2020 at 09:19:26PM +0000, Johannes Schindelin via GitGitGadget wrote:\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> \n> To allow for overriding the default branch name, we have introduced a\n> config setting. With this patch, the `git submodule` command learns\n> about this, too.\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nOne thing to consider: in the future, if we move away from \"master\"\nor even allow the value to be configurable, we're gonna end up breaking\na lot of repositories this way.\n\nIf a developer regularly pulls in submodule updates via\n`git submodule update --remote`, when the default branch name changes,\nthis will suddenly stop working. This will require developers who use\nsubmodules to \"fix\" their .gitmodules file.\n\nIf it's configurable, this problem might be even worse. It could lead to\nscenarios where one developer might go \"works for me\" while another\ndeveloper (who may set the configuration and forget about it) would be\nconfused about why it's not working for them.\n\nJust a couple thoughts I had while looking at this patch.\n"},{"id":"399756","messageId":"nycvar.QRO.7.76.6.2006150011360.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200615100327.3mwft27oj7h2bixg@yadavpratyush.com","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-14T22:26:03Z","receivedAt":"2020-06-15T10:59:31Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Pratyush,\n\nOn Mon, 15 Jun 2020, Pratyush Yadav wrote:\n\n> On 10/06/20 09:19PM, Johannes Schindelin via GitGitGadget wrote:\n>\n> > This series DOES NOT change the default automatically, but only provides an\n> > opt-in mechanism for interested users. It also presents a way forward for\n> > such a transition, if and when we decide to do so. Specifically, the new\n> > GIT_TEST_DEFAULT_BRANCH_NAME environment variable could be used to update\n> > test scripts on an individual basis instead of all-at-once.\n>\n> Many people have expressed reservations against this change.\n\nFrom what you wrote below, I take it that you are not talking about this\npatch series, nor the follow-up one(s) to change the default main branch\nname for new repositories.\n\n> One argument from those in favor of this change is that it doesn't\n> affect you if you don't care about the default branch name. You can just\n> go on using 'master' for all _your_ repos. I'd like to highlight the\n> \"your\" here. Sure, I can keep on using 'master' if I so prefer, but I\n> don't just use my repos. I also pull repos from other people, and I have\n> no control over what they call their main/primary/master branch (I'll\n> use \"main\" for the rest of the email). The cost here is that people now\n> need to update their scripts and workflow to account for other people's\n> naming preferences.\n\nThis talks about the scenario where a project you use decides to change\ntheir main branch name.\n\nWhile this is a scenario that my patch series tries to support (by\nintroducing the concept of `core.mainBranch`), it is not something my\npatch series _causes_.\n\nAll _this_ patch series does is to _allow_ changing the main branch name\n(manually) in an existing repository, and to change the default main\nbranch name to use in new repositories.\n\nEven the follow-up patch series I plan on contributing that changes the\nhard-coded default for the default main branch name to use in new\nrepositories won't affect any existing repository.\n\nSo I think this example...\n\n> For example, my vim plugins are submodules in the '~/.vim/bundle'\n> directory. When I want to update them, I run:\n>\n>   git submodule foreach 'git remote update && git reset --hard origin/master'\n>\n> With this change hitting a Git release, more and more people would call\n> their main branch different names they like. So what is the recommended\n> way to do something like this now? How do I checkout the tip of the main\n> branch? How do I push to the main branch? How do I pull from the main\n> branch? And so on...\n\n... has less to do with a new Git release, but more with the decision of\nan existing project to change their main branch name.\n\nThat's something users already had to deal with, of course. For example,\nprojects switching to the Git Flow model will start to use the main branch\nname `development`.\n\nGitHub Desktop changed their main branch name to `development`, and it did\nnot require any new Git release.\n\nGitHub CLI changed their main branch name to `trunk`.\n\nChrome and node.js stated their intention to change their main branch name\nto `main`.\n\nAnd https://github.com/microsoft/git uses `vfs-<version>` where\n`<version>` corresponds to the Git (for Windows) version on which it is\nbased, therefore the main branch name changes whenever there is a new Git\nversion.\n\nThese challenges have existed for every project that chooses to change\ntheir main branch name, for whatever reason.\n\nIn other words, I think you are talking about a challenge that is\northogonal (if related, on a high level) to the subject this patch series\ntries to address.\n\nCiao,\nJohannes\n"},{"id":"399767","messageId":"ebd10f73cd73a8fca84d1862e5a4b7b62a549bcd.1592225416.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v2.git.1592225416.gitgitgadget@gmail.com","subject":"[PATCH v2 01/12] fast-export: do anonymize the primary branch name","fromName":"Junio C Hamano via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T12:50:05Z","receivedAt":"2020-06-15T12:50:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Junio C Hamano <gitster@pobox.com>\n\nIn a fast-export stream with --anonymize option, all the end-user\ndata including refnames are munged to prevent exposure, but the\n'master' branch is left intact.\n\nThere is a comment that explains why it is OK to leave 'master'\nunanonymized (because everybody calls the primary branch 'master'\nand it is no secret), but that does not justify why it is bad to\nanonymize 'master' and make it indistinguishable from other\nbranches.  Assuming there _is_ a need to allow the readers of the\noutput to tell where the tip of the primary branch is, let's keep\nthe special casing of 'master', but still anonymize it to \"ref0\".\nBecause all other branches will be given ref+N where N is a positive\ninteger, this will keep the primary branch identifiable in the\noutput stream, without exposing what the name of the primary branch\nis in the repository the export stream was taken from.\n\nThis is in preparation for introducing a mechanism to affect the\nname of the primary branch used in the repository.  Once the\nmechanism is in use, the name of the primary branch won't be\n'master', and may not be allowed to be exposed.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/fast-export.c            | 9 +++++----\n t/t9351-fast-export-anonymize.sh | 9 +++++----\n 2 files changed, 10 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 85868162eec..1072bbf041f 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -497,7 +497,7 @@ static void *anonymize_ref_component(const void *old, size_t *len)\n {\n \tstatic int counter;\n \tstruct strbuf out = STRBUF_INIT;\n-\tstrbuf_addf(&out, \"ref%d\", counter++);\n+\tstrbuf_addf(&out, \"ref%d\", ++counter);\n \treturn strbuf_detach(&out, len);\n }\n \n@@ -518,11 +518,12 @@ static const char *anonymize_refname(const char *refname)\n \tint i;\n \n \t/*\n-\t * We also leave \"master\" as a special case, since it does not reveal\n-\t * anything interesting.\n+\t * In certain circumstances, it might be interesting to be able to\n+\t * identify the main branch. For that reason, let's force its name to\n+\t * be anonymized to `ref0`.\n \t */\n \tif (!strcmp(refname, \"refs/heads/master\"))\n-\t\treturn refname;\n+\t\treturn \"refs/heads/ref0\";\n \n \tstrbuf_reset(&anon);\n \tfor (i = 0; i < ARRAY_SIZE(prefixes); i++) {\ndiff --git a/t/t9351-fast-export-anonymize.sh b/t/t9351-fast-export-anonymize.sh\nindex 897dc509075..2415f0ec213 100755\n--- a/t/t9351-fast-export-anonymize.sh\n+++ b/t/t9351-fast-export-anonymize.sh\n@@ -26,8 +26,9 @@ test_expect_success 'stream omits path names' '\n \t! grep xyzzy stream\n '\n \n-test_expect_success 'stream allows master as refname' '\n-\tgrep master stream\n+test_expect_success 'stream translates master to ref0' '\n+\tgrep refs/heads/ref0 stream &&\n+\t! grep master stream\n '\n \n test_expect_success 'stream omits other refnames' '\n@@ -57,7 +58,7 @@ test_expect_success 'import stream to new repository' '\n test_expect_success 'result has two branches' '\n \tgit for-each-ref --format=\"%(refname)\" refs/heads >branches &&\n \ttest_line_count = 2 branches &&\n-\tother_branch=$(grep -v refs/heads/master branches)\n+\tother_branch=$(grep -v refs/heads/ref0 branches)\n '\n \n test_expect_success 'repo has original shape and timestamps' '\n@@ -65,7 +66,7 @@ test_expect_success 'repo has original shape and timestamps' '\n \t\tgit log --format=\"%m %ct\" --left-right --boundary \"$@\"\n \t} &&\n \t(cd .. && shape master...other) >expect &&\n-\tshape master...$other_branch >actual &&\n+\tshape ref0...$other_branch >actual &&\n \ttest_cmp expect actual\n '\n \n-- \ngitgitgadget\n\n"},{"id":"399768","messageId":"f4d547391537e5c3b0b4a07adb41b6aa56541fc3.1592225416.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v2.git.1592225416.gitgitgadget@gmail.com","subject":"[PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main branch name","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T12:50:06Z","receivedAt":"2020-06-15T12:50:30Z","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\nThere is a growing number of projects and companies desiring to change\nthe main branch name of their repositories (see e.g.\nhttps://twitter.com/mislav/status/1270388510684598272 for background on\nthis).\n\nHowever, there are a couple of hard-coded spots in Git's source code\nthat make this endeavor harder than necessary. For example, when\nformatting the commit message for merge commits, Git appends \"into\n<branch-name>\" unless the current branch is the `master` branch.\n\nClearly, this is not what one wants when already having gone through all\nthe steps to manually rename the main branch (and taking care of all the\nfall-out such as re-targeting existing Pull Requests).\n\nLet's introduce a way to override Git's hard-coded default:\n`core.mainBranch`.\n\nWe will start supporting this config option in the `git fmt-merge-msg`\ncommand and successively adjust all other places where the main branch\nname is hard-coded.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/config/core.txt |  5 +++++\n fmt-merge-msg.c               |  6 ++++--\n refs.c                        | 27 +++++++++++++++++++++++++++\n refs.h                        |  7 +++++++\n t/t6200-fmt-merge-msg.sh      |  7 +++++++\n 5 files changed, 50 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/config/core.txt b/Documentation/config/core.txt\nindex 74619a9c03b..32bb5368ebb 100644\n--- a/Documentation/config/core.txt\n+++ b/Documentation/config/core.txt\n@@ -626,3 +626,8 @@ core.abbrev::\n \tin your repository, which hopefully is enough for\n \tabbreviated object names to stay unique for some time.\n \tThe minimum length is 4.\n+\n+core.mainBranch::\n+\tThe name of the main (or: primary) branch in the current repository.\n+\tFor historical reasons, `master` is used as the fall-back for this\n+\tsetting.\ndiff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\nindex 72d32bd73b1..43f4f829242 100644\n--- a/fmt-merge-msg.c\n+++ b/fmt-merge-msg.c\n@@ -407,7 +407,7 @@ static void fmt_merge_msg_title(struct strbuf *out,\n \t\t\t\tconst char *current_branch)\n {\n \tint i = 0;\n-\tchar *sep = \"\";\n+\tchar *sep = \"\", *main_branch;\n \n \tstrbuf_addstr(out, \"Merge \");\n \tfor (i = 0; i < srcs.nr; i++) {\n@@ -451,10 +451,12 @@ static void fmt_merge_msg_title(struct strbuf *out,\n \t\t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n \t}\n \n-\tif (!strcmp(\"master\", current_branch))\n+\tmain_branch = git_main_branch_name();\n+\tif (!strcmp(main_branch, current_branch))\n \t\tstrbuf_addch(out, '\\n');\n \telse\n \t\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n+\tfree(main_branch);\n }\n \n static void fmt_tag_signature(struct strbuf *tagbuf,\ndiff --git a/refs.c b/refs.c\nindex 224ff66c7bb..f1854cffa2f 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -560,6 +560,33 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n \t\targv_array_pushf(prefixes, *p, len, prefix);\n }\n \n+char *repo_main_branch_name(struct repository *r)\n+{\n+\tconst char *config_key = \"core.mainbranch\";\n+\tconst char *config_display_key = \"core.mainBranch\";\n+\tconst char *fall_back = \"master\";\n+\tchar *name = NULL, *ret;\n+\n+\tif (repo_config_get_string(r, config_key, &name) < 0)\n+\t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n+\n+\tret = name ? name : xstrdup(fall_back);\n+\n+\tif (check_refname_format(ret, REFNAME_ALLOW_ONELEVEL))\n+\t\tdie(_(\"invalid branch name: %s = %s\"),\n+\t\t    config_display_key, name);\n+\n+\tif (name != ret)\n+\t\tfree(name);\n+\n+\treturn ret;\n+}\n+\n+char *git_main_branch_name(void)\n+{\n+\treturn repo_main_branch_name(the_repository);\n+}\n+\n /*\n  * *string and *len will only be substituted, and *string returned (for\n  * later free()ing) if the string passed in is a magic short-hand form\ndiff --git a/refs.h b/refs.h\nindex a92d2c74c83..a207ef01348 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -154,6 +154,13 @@ int repo_dwim_log(struct repository *r, const char *str, int len, struct object_\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \n+/*\n+ * Retrieves the name of the main (or: primary) branch of the given\n+ * repository.\n+ */\n+char *git_main_branch_name(void);\n+char *repo_main_branch_name(struct repository *r);\n+\n /*\n  * A ref_transaction represents a collection of reference updates that\n  * should succeed or fail together.\ndiff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh\nindex e4c2a6eca43..7a873f4a05c 100755\n--- a/t/t6200-fmt-merge-msg.sh\n+++ b/t/t6200-fmt-merge-msg.sh\n@@ -158,6 +158,13 @@ test_expect_success 'setup FETCH_HEAD' '\n \tgit fetch . left\n '\n \n+test_expect_success 'with overridden default branch name' '\n+\ttest_when_finished \"git switch master\" &&\n+\tgit switch -c default &&\n+\tgit -c core.mainBranch=default fmt-merge-msg <.git/FETCH_HEAD >actual &&\n+\t! grep \"into default\" actual\n+'\n+\n test_expect_success 'merge.log=3 limits shortlog length' '\n \tcat >expected <<-EOF &&\n \tMerge branch ${apos}left${apos}\n-- \ngitgitgadget\n\n"},{"id":"399769","messageId":"a3be4f39aa240e614a2e12756e1ea864c35137a2.1592225416.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v2.git.1592225416.gitgitgadget@gmail.com","subject":"[PATCH v2 05/12] fast-export: handle overridden main branch names correctly","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T12:50:09Z","receivedAt":"2020-06-15T12:50:30Z","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\nWhen anonymizing commit history, we are careful to translate the main\nbranch name to `ref0`.\n\nWhen the main branch name is overridden via the config, we will want\n`git fast-export` to use that overridden name instead.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/fast-export.c            | 11 ++++++++++-\n t/t9351-fast-export-anonymize.sh |  6 ++++++\n 2 files changed, 16 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 1072bbf041f..deeb01b6937 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -515,14 +515,23 @@ static const char *anonymize_refname(const char *refname)\n \t};\n \tstatic struct hashmap refs;\n \tstatic struct strbuf anon = STRBUF_INIT;\n+\tstatic char *main_branch;\n \tint i;\n \n \t/*\n \t * In certain circumstances, it might be interesting to be able to\n \t * identify the main branch. For that reason, let's force its name to\n \t * be anonymized to `ref0`.\n+\t *\n+\t * While the main branch name might often be `main` for new\n+\t * repositories (and `master` for aged ones), and such well-known names\n+\t * may not necessarily need anonymizing, it could be configured to use\n+\t * a secret word that the user may not want to reveal.\n \t */\n-\tif (!strcmp(refname, \"refs/heads/master\"))\n+\tif (!main_branch)\n+\t\tmain_branch = git_main_branch_name(MAIN_BRANCH_FULL_NAME);\n+\n+\tif (!strcmp(refname, main_branch))\n \t\treturn \"refs/heads/ref0\";\n \n \tstrbuf_reset(&anon);\ndiff --git a/t/t9351-fast-export-anonymize.sh b/t/t9351-fast-export-anonymize.sh\nindex 2415f0ec213..f42be635c2f 100755\n--- a/t/t9351-fast-export-anonymize.sh\n+++ b/t/t9351-fast-export-anonymize.sh\n@@ -31,6 +31,12 @@ test_expect_success 'stream translates master to ref0' '\n \t! grep master stream\n '\n \n+test_expect_success 'respects configured main branch' '\n+\tgit -c core.mainBranch=does-not-exist \\\n+\t\tfast-export --anonymize --all >stream-without-ref0 &&\n+\t! grep ref0 stream-without-ref0\n+'\n+\n test_expect_success 'stream omits other refnames' '\n \t! grep other stream &&\n \t! grep mytag stream\n-- \ngitgitgadget\n\n"},{"id":"399773","messageId":"ca1c63c3e012edde26b4f0c67175ca53f4d29e08.1592225416.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v2.git.1592225416.gitgitgadget@gmail.com","subject":"[PATCH v2 04/12] git_main_branch_name(): optionally report the full ref name","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T12:50:08Z","receivedAt":"2020-06-15T12:50:32Z","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 the first caller of that function (`git\nfast-export`) that wants a full ref name instead of the short branch\nname.\n\nTo make this change easier to review, let's refactor the function\naccordingly without mixing in the actual first call using the new flag.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n fmt-merge-msg.c    |  2 +-\n refs.c             | 12 ++++++++----\n refs.h             |  8 ++++++--\n send-pack.c        |  2 +-\n transport-helper.c |  2 +-\n 5 files changed, 17 insertions(+), 9 deletions(-)\n\ndiff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\nindex 43f4f829242..03dba905643 100644\n--- a/fmt-merge-msg.c\n+++ b/fmt-merge-msg.c\n@@ -451,7 +451,7 @@ static void fmt_merge_msg_title(struct strbuf *out,\n \t\t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n \t}\n \n-\tmain_branch = git_main_branch_name();\n+\tmain_branch = git_main_branch_name(0);\n \tif (!strcmp(main_branch, current_branch))\n \t\tstrbuf_addch(out, '\\n');\n \telse\ndiff --git a/refs.c b/refs.c\nindex f1854cffa2f..7da3ac178c4 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -560,8 +560,9 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n \t\targv_array_pushf(prefixes, *p, len, prefix);\n }\n \n-char *repo_main_branch_name(struct repository *r)\n+char *repo_main_branch_name(struct repository *r, int flags)\n {\n+\tint full_name = flags & MAIN_BRANCH_FULL_NAME;\n \tconst char *config_key = \"core.mainbranch\";\n \tconst char *config_display_key = \"core.mainBranch\";\n \tconst char *fall_back = \"master\";\n@@ -570,7 +571,10 @@ char *repo_main_branch_name(struct repository *r)\n \tif (repo_config_get_string(r, config_key, &name) < 0)\n \t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n \n-\tret = name ? name : xstrdup(fall_back);\n+\tif (full_name)\n+\t\tret = xstrfmt(\"refs/heads/%s\", name ? name : fall_back);\n+\telse\n+\t\tret = name ? name : xstrdup(fall_back);\n \n \tif (check_refname_format(ret, REFNAME_ALLOW_ONELEVEL))\n \t\tdie(_(\"invalid branch name: %s = %s\"),\n@@ -582,9 +586,9 @@ char *repo_main_branch_name(struct repository *r)\n \treturn ret;\n }\n \n-char *git_main_branch_name(void)\n+char *git_main_branch_name(int flags)\n {\n-\treturn repo_main_branch_name(the_repository);\n+\treturn repo_main_branch_name(the_repository, flags);\n }\n \n /*\ndiff --git a/refs.h b/refs.h\nindex a207ef01348..96472f9a9f5 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -157,9 +157,13 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n /*\n  * Retrieves the name of the main (or: primary) branch of the given\n  * repository.\n+ *\n+ * The result is an allocated string. Unless the flags ask for a short name, it\n+ * will be prefixed with \"refs/heads/\".\n  */\n-char *git_main_branch_name(void);\n-char *repo_main_branch_name(struct repository *r);\n+#define MAIN_BRANCH_FULL_NAME (1<<0)\n+char *git_main_branch_name(int flags);\n+char *repo_main_branch_name(struct repository *r, int flags);\n \n /*\n  * A ref_transaction represents a collection of reference updates that\ndiff --git a/send-pack.c b/send-pack.c\nindex 2532864c812..898720511d0 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -405,7 +405,7 @@ int send_pack(struct send_pack_args *args,\n \t}\n \n \tif (!remote_refs) {\n-\t\tchar *branch_name = git_main_branch_name();\n+\t\tchar *branch_name = git_main_branch_name(0);\n \n \t\tfprintf(stderr, \"No refs in common and none specified; doing nothing.\\n\"\n \t\t\t\"Perhaps you should specify a branch such as '%s'.\\n\",\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 8c8f40e322d..7a54e5b2fb2 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -1044,7 +1044,7 @@ static int push_refs(struct transport *transport,\n \t}\n \n \tif (!remote_refs) {\n-\t\tchar *branch_name = git_main_branch_name();\n+\t\tchar *branch_name = git_main_branch_name(0);\n \n \t\tfprintf(stderr,\n \t\t\t_(\"No refs in common and none specified; doing nothing.\\n\"\n-- \ngitgitgadget\n\n"},{"id":"399770","messageId":"bd8af3755ad2a1e2cfe84fed939c9e23585b8c7f.1592225416.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v2.git.1592225416.gitgitgadget@gmail.com","subject":"[PATCH v2 03/12] send-pack/transport-helper: respect `core.mainBranch`","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T12:50:07Z","receivedAt":"2020-06-15T12:50:33Z","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\nWhen mentioning the main branch name in an error message, we want to go\nwith the preference specified by the user, only falling back to Git's\nown, hard-coded default when none was configured explicitly.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n send-pack.c             | 6 +++++-\n t/t5528-push-default.sh | 7 +++++++\n transport-helper.c      | 6 +++++-\n 3 files changed, 17 insertions(+), 2 deletions(-)\n\ndiff --git a/send-pack.c b/send-pack.c\nindex 0abee22283d..2532864c812 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -405,8 +405,12 @@ int send_pack(struct send_pack_args *args,\n \t}\n \n \tif (!remote_refs) {\n+\t\tchar *branch_name = git_main_branch_name();\n+\n \t\tfprintf(stderr, \"No refs in common and none specified; doing nothing.\\n\"\n-\t\t\t\"Perhaps you should specify a branch such as 'master'.\\n\");\n+\t\t\t\"Perhaps you should specify a branch such as '%s'.\\n\",\n+\t\t\tbranch_name);\n+\t\tfree(branch_name);\n \t\treturn 0;\n \t}\n \tif (args->atomic && !atomic_supported)\ndiff --git a/t/t5528-push-default.sh b/t/t5528-push-default.sh\nindex 4d1e0c363ea..f7583b20f87 100755\n--- a/t/t5528-push-default.sh\n+++ b/t/t5528-push-default.sh\n@@ -98,6 +98,13 @@ test_expect_success 'push from/to new branch with upstream, matching and simple'\n \ttest_push_failure upstream\n '\n \n+test_expect_success '\"matching\" fails if none match' '\n+\tgit init --bare empty &&\n+\ttest_must_fail git -c core.mainBranch=unmatch push empty : 2>actual &&\n+\tneedle=\"Perhaps you should specify a branch such as '\\''unmatch'\\''\" &&\n+\ttest_i18ngrep \"$needle\" actual\n+'\n+\n test_expect_success 'push ambiguously named branch with upstream, matching and simple' '\n \tgit checkout -b ambiguous &&\n \ttest_config branch.ambiguous.remote parent1 &&\ndiff --git a/transport-helper.c b/transport-helper.c\nindex a46afcb69db..8c8f40e322d 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -1044,9 +1044,13 @@ static int push_refs(struct transport *transport,\n \t}\n \n \tif (!remote_refs) {\n+\t\tchar *branch_name = git_main_branch_name();\n+\n \t\tfprintf(stderr,\n \t\t\t_(\"No refs in common and none specified; doing nothing.\\n\"\n-\t\t\t  \"Perhaps you should specify a branch such as 'master'.\\n\"));\n+\t\t\t  \"Perhaps you should specify a branch such as '%s'.\\n\"),\n+\t\t\tbranch_name);\n+\t\tfree(branch_name);\n \t\treturn 0;\n \t}\n \n-- \ngitgitgadget\n\n"},{"id":"399771","messageId":"933e314813df34aafca1a47bfc1fcba389dd5364.1592225416.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v2.git.1592225416.gitgitgadget@gmail.com","subject":"[PATCH v2 06/12] branch -m: adjust `core.mainBranch` if necessary","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T12:50:10Z","receivedAt":"2020-06-15T12:50: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\nWhen renaming the main branch (as possibly identified by the\n`core.mainBranch` setting), we will want to record that the main branch\nnow has a different name.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/branch.c  | 9 +++++++++\n t/t3200-branch.sh | 9 +++++++++\n 2 files changed, 18 insertions(+)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex accb61b1aae..62f8db5fb05 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -556,6 +556,15 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \t    replace_each_worktree_head_symref(oldref.buf, newref.buf, logmsg.buf))\n \t\tdie(_(\"Branch renamed to %s, but HEAD is not updated!\"), newname);\n \n+\tif (!copy) {\n+\t\tchar *main_branch = git_main_branch_name(0);\n+\n+\t\tif (!strcmp(interpreted_oldname, main_branch))\n+\t\t    git_config_set(\"core.mainbranch\", interpreted_newname);\n+\n+\t\tfree(main_branch);\n+\t}\n+\n \tstrbuf_release(&logmsg);\n \n \tstrbuf_addf(&oldsection, \"branch.%s\", interpreted_oldname);\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex 411a70b0ce9..328544f2736 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -467,6 +467,15 @@ EOF\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'renaming the main branch modifies core.mainBranch' '\n+\tgit init rename-main &&\n+\ttest_commit -C rename-main initial &&\n+\tgit -C rename-main branch -m trunk &&\n+\tgit -C rename-main config core.mainBranch >actual &&\n+\techo trunk >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'git branch -c dumps usage' '\n \ttest_expect_code 128 git branch -c 2>err &&\n \ttest_i18ngrep \"branch name required\" err\n-- \ngitgitgadget\n\n"},{"id":"399772","messageId":"e09f857f06857fedc46b91bc918486f34dde8b02.1592225416.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v2.git.1592225416.gitgitgadget@gmail.com","subject":"[PATCH v2 12/12] testsvn: respect `init.defaultBranch`","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T12:50:16Z","receivedAt":"2020-06-15T12:50:36Z","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\nThe default name of the main branch in new repositories can now be\nconfigured. The `testsvn` remote helper translates the remote Subversion\nrepository's branch name `trunk` to the hard-coded name `master`.\nClearly, the intention was to make the name align with Git's detaults.\n\nSo while we are not talking about a newly-created repository in the\n`testsvn` context, it _still_ makes sense to use the overridden default\nname for the main branch whenever users configured it.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n remote-testsvn.c      | 12 +++++++++---\n t/t9020-remote-svn.sh |  6 ++++++\n 2 files changed, 15 insertions(+), 3 deletions(-)\n\ndiff --git a/remote-testsvn.c b/remote-testsvn.c\nindex 3af708c5b67..6ec300bf6c3 100644\n--- a/remote-testsvn.c\n+++ b/remote-testsvn.c\n@@ -13,7 +13,7 @@\n static const char *url;\n static int dump_from_file;\n static const char *private_ref;\n-static const char *remote_ref = \"refs/heads/master\";\n+static char *remote_ref;\n static const char *marksfilename, *notes_ref;\n struct rev_note { unsigned int rev_nr; };\n \n@@ -286,7 +286,7 @@ int cmd_main(int argc, const char **argv)\n \t\t\tprivate_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT,\n \t\t\tnotes_ref_sb = STRBUF_INIT;\n \tstatic struct remote *remote;\n-\tconst char *url_in;\n+\tconst char *url_in, *remote_ref_short;\n \n \tsetup_git_directory();\n \tif (argc < 2 || argc > 3) {\n@@ -294,6 +294,11 @@ int cmd_main(int argc, const char **argv)\n \t\treturn 1;\n \t}\n \n+\tremote_ref = git_main_branch_name(MAIN_BRANCH_FULL_NAME |\n+\t\t\t\t\t  MAIN_BRANCH_FOR_INIT);\n+\tif (!skip_prefix(remote_ref, \"refs/heads/\", &remote_ref_short))\n+\t\tBUG(\"unexpected remote_ref '%s'\", remote_ref);\n+\n \tremote = remote_get(argv[1]);\n \turl_in = (argc == 3) ? argv[2] : remote->url[0];\n \n@@ -306,7 +311,8 @@ int cmd_main(int argc, const char **argv)\n \t\turl = url_sb.buf;\n \t}\n \n-\tstrbuf_addf(&private_ref_sb, \"refs/svn/%s/master\", remote->name);\n+\tstrbuf_addf(&private_ref_sb, \"refs/svn/%s/%s\",\n+\t\t    remote->name, remote_ref_short);\n \tprivate_ref = private_ref_sb.buf;\n \n \tstrbuf_addf(&notes_ref_sb, \"refs/notes/%s/revs\", remote->name);\ndiff --git a/t/t9020-remote-svn.sh b/t/t9020-remote-svn.sh\nindex 6fca08e5e35..c931193f013 100755\n--- a/t/t9020-remote-svn.sh\n+++ b/t/t9020-remote-svn.sh\n@@ -84,6 +84,12 @@ test_expect_success REMOTE_SVN 'incremental imports must lead to the same head'\n \ttest_cmp master.good .git/refs/remotes/svnsim/master\n '\n \n+test_expect_success REMOTE_SVN 'respects configured default main branch' '\n+\tgit -c init.defaultBranch=trunk remote add -f trunk \\\n+\t\t\"testsvn::file://$TEST_DIRECTORY/t9154/svn.dump\" &&\n+\tgit rev-parse --verify refs/remotes/trunk/trunk\n+'\n+\n test_debug 'git branch -a'\n \n test_done\n-- \ngitgitgadget\n"},{"id":"399774","messageId":"59b8f4cfbb278b1bcb9c189e5c57e37d98db3fbe.1592225416.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v2.git.1592225416.gitgitgadget@gmail.com","subject":"[PATCH v2 10/12] remote: learn about the possibly-overridden default main branch name","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T12:50:14Z","receivedAt":"2020-06-15T12:50:37Z","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\nWhen guessing the default branch name of a remote, and there are no refs\nto guess from, we want to go with the preference specified by the user\nfor the fall-back, i.e. the default name to be used for the main branch\nof new repositories (because as far as the user is concerned, a remote\nthat has no branches yet is a new repository).\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n remote.c                 | 15 ++++++++++-----\n t/t5606-clone-options.sh | 11 ++++++++++-\n 2 files changed, 20 insertions(+), 6 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex 534c6426f1e..2dcf4ac6d15 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -256,7 +256,7 @@ static void read_remotes_file(struct remote *remote)\n \n static void read_branches_file(struct remote *remote)\n {\n-\tchar *frag;\n+\tchar *frag, *main_branch = NULL;\n \tstruct strbuf buf = STRBUF_INIT;\n \tFILE *f = fopen_or_warn(git_path(\"branches/%s\", remote->name), \"r\");\n \n@@ -276,7 +276,7 @@ static void read_branches_file(struct remote *remote)\n \n \t/*\n \t * The branches file would have URL and optionally\n-\t * #branch specified.  The \"master\" (or specified) branch is\n+\t * #branch specified.  The main (or specified) branch is\n \t * fetched and stored in the local branch matching the\n \t * remote name.\n \t */\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 = \"master\";\n+\t\tfrag = main_branch = git_main_branch_name(MAIN_BRANCH_FOR_INIT);\n \n \tadd_url_alias(remote, strbuf_detach(&buf, NULL));\n \tstrbuf_addf(&buf, \"refs/heads/%s:refs/heads/%s\",\n@@ -299,6 +299,7 @@ static void read_branches_file(struct remote *remote)\n \tstrbuf_addf(&buf, \"HEAD:refs/heads/%s\", frag);\n \trefspec_append(&remote->push, buf.buf);\n \tremote->fetch_tags = 1; /* always auto-follow */\n+\tfree(main_branch);\n \tstrbuf_release(&buf);\n }\n \n@@ -2097,9 +2098,13 @@ struct ref *guess_remote_head(const struct ref *head,\n \tif (head->symref)\n \t\treturn copy_ref(find_ref_by_name(refs, head->symref));\n \n-\t/* If refs/heads/master could be right, it is. */\n+\t/* If a remote branch exists with the main branch name, let's use it. */\n \tif (!all) {\n-\t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n+\t\tchar *name = git_main_branch_name(MAIN_BRANCH_FULL_NAME |\n+\t\t\t\t\t\t  MAIN_BRANCH_FOR_INIT);\n+\n+\t\tr = find_ref_by_name(refs, name);\n+\t\tfree(name);\n \t\tif (r && oideq(&r->old_oid, &head->old_oid))\n \t\t\treturn copy_ref(r);\n \t}\ndiff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh\nindex 98b2d8527f6..61ce9c09920 100755\n--- a/t/t5606-clone-options.sh\n+++ b/t/t5606-clone-options.sh\n@@ -49,7 +49,16 @@ test_expect_success 'guesses main branch name correctly' '\n \tgit -C main-branch branch abc guess &&\n \tgit clone main-branch is-it &&\n \ttest guess = $(git -C is-it config core.mainBranch) &&\n-\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD)\n+\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD) &&\n+\n+\tgit -c init.defaultBranch=none init --bare no-head &&\n+\tgit -C main-branch push ../no-head guess abc &&\n+\tgit clone no-head is-it2 &&\n+\ttest_must_fail git -C is-it2 symbolic-ref refs/remotes/origin/HEAD &&\n+\tgit -C no-head update-ref --no-deref HEAD refs/heads/guess &&\n+\tgit -c init.defaultBranch=guess clone no-head is-it3 &&\n+\ttest refs/remotes/origin/guess = \\\n+\t\t$(git -C is-it3 symbolic-ref refs/remotes/origin/HEAD)\n '\n \n test_done\n-- \ngitgitgadget\n\n"},{"id":"399775","messageId":"59d6267f099f30f830836a2422289bc83f5c35e5.1592225416.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v2.git.1592225416.gitgitgadget@gmail.com","subject":"[PATCH v2 11/12] submodule: use the correct default for the main branch name","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T12:50:15Z","receivedAt":"2020-06-15T12:50:39Z","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 allow for overriding the default branch name, we have introduced a\nconfig setting. With this patch, the `git submodule` command learns\nabout this, too.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/submodule--helper.c | 10 ++++++++--\n t/t7406-submodule-update.sh |  7 +++++++\n 2 files changed, 15 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 46c03d2a126..48d73e8d9cb 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1980,8 +1980,14 @@ static const char *remote_submodule_branch(const char *path)\n \t\tbranch = sub->branch;\n \tfree(key);\n \n-\tif (!branch)\n-\t\treturn \"master\";\n+\tif (!branch) {\n+\t\tstatic char *fall_back;\n+\n+\t\tif (!fall_back)\n+\t\t\tfall_back = git_main_branch_name(MAIN_BRANCH_FOR_INIT);\n+\n+\t\treturn fall_back;\n+\t}\n \n \tif (!strcmp(branch, \".\")) {\n \t\tconst char *refname = resolve_ref_unsafe(\"HEAD\", 0, NULL, NULL);\ndiff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\nindex 4fb447a143e..641113afef4 100755\n--- a/t/t7406-submodule-update.sh\n+++ b/t/t7406-submodule-update.sh\n@@ -70,6 +70,13 @@ test_expect_success 'setup a submodule tree' '\n \t)\n '\n \n+test_expect_success 'update --remote uses configured default main branch' '\n+\tgit clone super main-branch &&\n+\ttest_must_fail git -C main-branch -c init.defaultBranch=hello \\\n+\t\tsubmodule update --init --remote submodule 2>err &&\n+\ttest_i18ngrep origin/hello err\n+'\n+\n test_expect_success 'submodule update detaching the HEAD ' '\n \t(cd super/submodule &&\n \t git reset --hard HEAD~1\n-- \ngitgitgadget\n\n"},{"id":"399777","messageId":"0e59b6181699abe17eb46fe3ca5a48ce71889780.1592225416.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v2.git.1592225416.gitgitgadget@gmail.com","subject":"[PATCH v2 09/12] clone: handle overridden main branch names","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T12:50:13Z","receivedAt":"2020-06-15T12:50:40Z","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\nWhen cloning a repository without any branches, Git chooses a default\nbranch name for the as-yet unborn branch.\n\nAs part of the implicit initialization of the local repository, Git\njust learned to respect `init.defaultBranch` to choose a different main\nbranch name. We now really want that branch name to be used as a\nfall-back.\n\nAt the same time, we also want to make sure that `core.mainBranch` is\nset correctly, reflecting the name of the main branch. In case we detect\na main branch, we do have to do that explicitly, otherwise `init_db()`\nwill already have done that for us.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/config/init.txt |  4 ++--\n builtin/clone.c               | 16 +++++++++++++---\n t/t5606-clone-options.sh      | 17 +++++++++++++++++\n 3 files changed, 32 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/config/init.txt b/Documentation/config/init.txt\nindex 6ae4a38416e..dc77f8c8446 100644\n--- a/Documentation/config/init.txt\n+++ b/Documentation/config/init.txt\n@@ -3,5 +3,5 @@ init.templateDir::\n \t(See the \"TEMPLATE DIRECTORY\" section of linkgit:git-init[1].)\n \n init.defaultBranch::\n-\tAllows overriding the default branch name when initializing\n-\ta new repository.\n+\tAllows overriding the default branch name e.g. when initializing\n+\ta new repository or when cloning an empty repository.\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 487b0a42d75..755fcaeb0ba 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -718,6 +718,7 @@ static void update_head(const struct ref *our, const struct ref *remote,\n \t\t/* Local default branch link */\n \t\tif (create_symref(\"HEAD\", our->name, NULL) < 0)\n \t\t\tdie(_(\"unable to update HEAD\"));\n+\t\tgit_config_set(\"core.mainbranch\", head);\n \t\tif (!option_bare) {\n \t\t\tupdate_ref(msg, \"HEAD\", &our->old_oid, NULL, 0,\n \t\t\t\t   UPDATE_REFS_DIE_ON_ERR);\n@@ -1264,9 +1265,18 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\tremote_head_points_at = NULL;\n \t\tremote_head = NULL;\n \t\toption_no_checkout = 1;\n-\t\tif (!option_bare)\n-\t\t\tinstall_branch_config(0, \"master\", option_origin,\n-\t\t\t\t\t      \"refs/heads/master\");\n+\t\tif (!option_bare) {\n+\t\t\tchar *main_branch =\n+\t\t\t\tgit_main_branch_name(MAIN_BRANCH_FULL_NAME);\n+\t\t\tconst char *nick;\n+\n+\t\t\tif (!skip_prefix(main_branch, \"refs/heads/\", &nick))\n+\t\t\t\tBUG(\"unexpected default branch '%s'\",\n+\t\t\t\t    main_branch);\n+\t\t\tinstall_branch_config(0, nick, option_origin,\n+\t\t\t\t\t      main_branch);\n+\t\t\tfree(main_branch);\n+\t\t}\n \t}\n \n \twrite_refspec_config(src_ref_prefix, our_head_points_at,\ndiff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh\nindex 9e24ec88e67..98b2d8527f6 100755\n--- a/t/t5606-clone-options.sh\n+++ b/t/t5606-clone-options.sh\n@@ -35,4 +35,21 @@ test_expect_success 'redirected clone -v does show progress' '\n \n '\n \n+test_expect_success 'chooses correct default main branch name' '\n+\tgit init --bare empty &&\n+\tgit -c init.defaultBranch=up clone empty whats-up &&\n+\ttest refs/heads/up = $(git -C whats-up symbolic-ref HEAD) &&\n+\ttest up = $(git -C whats-up config core.mainBranch) &&\n+\ttest refs/heads/up = $(git -C whats-up config branch.up.merge)\n+'\n+\n+test_expect_success 'guesses main branch name correctly' '\n+\tgit init --main-branch=guess main-branch &&\n+\ttest_commit -C main-branch no-spoilers &&\n+\tgit -C main-branch branch abc guess &&\n+\tgit clone main-branch is-it &&\n+\ttest guess = $(git -C is-it config core.mainBranch) &&\n+\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD)\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"399776","messageId":"c711eba7e760b4f80ab8ef69ed1d69d9710d85c7.1592225416.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v2.git.1592225416.gitgitgadget@gmail.com","subject":"[PATCH v2 08/12] init: allow overriding the default main branch name via the config","fromName":"Don Goodman-Wilson via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T12:50:12Z","receivedAt":"2020-06-15T12:50:42Z","isPatch":true,"sender":{"key":"don@goodman-wilson.com","avatar":"https://gravatar.com/avatar/9819ec326d55ea4c398b8ff018dcf63b4e9603b00db9cc019c725bffc9c05d17?d=mp&s=160"},"body":"From: Don Goodman-Wilson <don@goodman-wilson.com>\n\nWe just introduced the command-line option `--main-branch=<branch-name>`\nto allow initializing a new repository with a different initial branch\nthan the hard-coded one.\n\nTo allow users to override the default main branch name more permanently\n(i.e. without having to specify the name manually for each and every\n`git init` invocation), let's introduce the `init.defaultBranch` config\nsetting.\n\nHelped-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nHelped-by: Derrick Stolee <dstolee@microsoft.com>\nSigned-off-by: Don Goodman-Wilson <don@goodman-wilson.com>\n---\n Documentation/config/init.txt |  4 ++++\n builtin/init-db.c             |  6 ++++--\n refs.c                        |  7 +++++--\n refs.h                        |  4 ++++\n t/t0001-init.sh               | 16 ++++++++++++++++\n 5 files changed, 33 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/config/init.txt b/Documentation/config/init.txt\nindex 46fa8c6a082..6ae4a38416e 100644\n--- a/Documentation/config/init.txt\n+++ b/Documentation/config/init.txt\n@@ -1,3 +1,7 @@\n init.templateDir::\n \tSpecify the directory from which templates will be copied.\n \t(See the \"TEMPLATE DIRECTORY\" section of linkgit:git-init[1].)\n+\n+init.defaultBranch::\n+\tAllows overriding the default branch name when initializing\n+\ta new repository.\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 287cdafaab1..d09c9dc7845 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -266,10 +266,11 @@ static int create_default_files(const char *template_path,\n \treinit = (!access(path, R_OK)\n \t\t  || readlink(path, junk, sizeof(junk)-1) != -1);\n \tif (!reinit) {\n-\t\tchar *ref;\n+\t\tchar *ref, *fall_back = NULL;\n \n \t\tif (!main_branch)\n-\t\t\tmain_branch = \"master\";\n+\t\t\tmain_branch = fall_back =\n+\t\t\t\tgit_main_branch_name(MAIN_BRANCH_FOR_INIT);\n \n \t\tref = xstrfmt(\"refs/heads/%s\", main_branch);\n \t\tif (check_refname_format(ref, 0) < 0)\n@@ -280,6 +281,7 @@ static int create_default_files(const char *template_path,\n \t\tfree(ref);\n \n \t\tgit_config_set(\"core.mainbranch\", main_branch);\n+\t\tfree(fall_back);\n \t} else if (main_branch)\n \t\twarning(_(\"re-init: ignoring --main-branch=%s\"), main_branch);\n \ndiff --git a/refs.c b/refs.c\nindex 7da3ac178c4..4b0e5b14062 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -563,8 +563,11 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n char *repo_main_branch_name(struct repository *r, int flags)\n {\n \tint full_name = flags & MAIN_BRANCH_FULL_NAME;\n-\tconst char *config_key = \"core.mainbranch\";\n-\tconst char *config_display_key = \"core.mainBranch\";\n+\tint for_init = flags & MAIN_BRANCH_FOR_INIT;\n+\tconst char *config_key = for_init ?\n+\t\t \"init.defaultbranch\" : \"core.mainbranch\";\n+\tconst char *config_display_key = for_init ?\n+\t\t \"init.defaultBranch\" : \"core.mainBranch\";\n \tconst char *fall_back = \"master\";\n \tchar *name = NULL, *ret;\n \ndiff --git a/refs.h b/refs.h\nindex 96472f9a9f5..c801d08490c 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -158,10 +158,14 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n  * Retrieves the name of the main (or: primary) branch of the given\n  * repository.\n  *\n+ * To obtain the default for newly-initialized repositories, pass the flag\n+ * `MAIN_BRANCH_FOR_INIT`.\n+ *\n  * The result is an allocated string. Unless the flags ask for a short name, it\n  * will be prefixed with \"refs/heads/\".\n  */\n #define MAIN_BRANCH_FULL_NAME (1<<0)\n+#define MAIN_BRANCH_FOR_INIT   (1<<1)\n char *git_main_branch_name(int flags);\n char *repo_main_branch_name(struct repository *r, int flags);\n \ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 5d8e321a703..fbf02066940 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -479,4 +479,20 @@ test_expect_success '--main-branch' '\n \tgrep hello actual\n '\n \n+test_expect_success 'overridden default main branch name (config)' '\n+\ttest_config_global init.defaultBranch nmb &&\n+\tgit init main-branch-config &&\n+\tgit -C main-branch-config symbolic-ref HEAD >actual &&\n+\tgrep nmb actual &&\n+\tgit -C main-branch-config config core.mainBranch >actual &&\n+\techo nmb >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'invalid default branch name' '\n+\ttest_config_global init.defaultBranch \"with space\" &&\n+\ttest_must_fail git init main-branch-invalid 2>err &&\n+\ttest_i18ngrep \"invalid branch name\" err\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"399779","messageId":"pull.656.v2.git.1592225416.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"[PATCH v2 00/12] Allow overriding the default name of the default branch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T12:50:04Z","receivedAt":"2020-06-15T12:50:44Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"A growing number of open source projects aims to avoid the branch name \nmaster due to its negative connotation. See [1] for an existing discussion\non this. The links [2], [3], and [4] describe community-driven ways for\nusers to rename their default branches or use template edits to set a new\ndefault branch name.\n\n[1] \nhttps://lore.kernel.org/git/CAOAHyQwyXC1Z3v7BZAC+Bq6JBaM7FvBenA-1fcqeDV==apdWDg@mail.gmail.com/\n\n[2] https://twitter.com/mislav/status/1270388510684598272\n\n[3] \nhttps://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx\n\n[4] https://github.com/ethomson/retarget_prs\n\nBy necessity, existing repositories require a lot of manual work to move\naway from that branch name, but it should be much easier for new\nrepositories.\n\nThis patch series allows overriding the branch name being used for new\nrepositories' main branch, as well as telling Git about a renamed main\nbranch in an already-existing repository. The former would be configured via \ninit.defaultBranch and the latter via core.mainBranch (which is now\nautomatically configured in git init).\n\nShell scripts can find out what the current repository's main branch name is\ncalled via\n\nmain_branch=$(git config core.mainBranch || echo master)\n\nThis is even future proof because all future git init invocations will\nconfigure that setting.\n\nThe initial patch was started by newcomer Don Goodman-Wilson, as well as the\nbigger change that morphed into #655, where we demonstrate how to change\nGit's hard-coded default main branch name to main based on this here patch\nseries, verifying the approach. Thanks for the contribution!\n\nThis series DOES NOT change the default automatically, but only provides an\nopt-in mechanism for interested users. The plan for that is to convert the\ntest scripts incrementally (by introducing GIT_TEST_DEFAULT_MAIN_BRANCH_NAME\n, which overrides init.defaultBranch, and then converting the tricky test\nscripts first, one by one, using that environment variable).\n\nChanges since v1:\n\n * The modifications to respect GIT_TEST_DEFAULT_BRANCH_NAME have been\n   backed out from this patch series, as they are only relevant once we\n   start converting the test suite to accommodate for a new default main\n   branch name.\n   \n   \n * An error message that started with an upper-case letter was downcased.\n   \n   \n * git_default_branch_name()'s logic was simplified by replacing an if ...\n   else ... by a ternary assignment.\n   \n   \n * The git_default_branch_name() function was renamed to \n   git_main_branch_name() and a corresponding repo_main_branch_name() was\n   introduced.\n   \n   \n * The \"init\" commit message's first paragraph now elaborates a little bit\n   on the reasoning why projects want to move away from the current default\n   branch name.\n   \n   \n * The \"init\" commit was split into two.\n   \n   \n * There are now two config settings: init.defaultBranch (defining the\n   branch name to use when initializing new repositories) and \n   core.mainBranch (which is now configured by init_db(), declaring what the\n   name of the main branch is in this repository).\n   \n   \n * The commits were re-ordered to introduce the concept of core.mainBranch \n   first because technically, this is something that we could do even\n   without changing git init at all.\n   \n   \n * git fast-export --anonymize now always uses the ref name ref0 for the\n   main branch, no matter whether it was overridden or whether the fall-back\n   is in effect.\n   \n   \n * The code comment regarding anonymizing the main branch to ref0 in git\n   fast-export --anonymize was enhanced.\n   \n   \n * A new patch was added to rename core.mainBranch if the main branch is\n   renamed via git branch -m.\n   \n   \n * Added a patch that introduces support for git init\n   --main-branch=<branch-name>.\n   \n   \n * Where possible, I added tests (although I did not try to extend test\n   coverage to all changes: the send-pack.c/transport-helper.c patch only\n   adds a test for the send-pack.c adjustment, for example).\n\nDon Goodman-Wilson (1):\n  init: allow overriding the default main branch name via the config\n\nJohannes Schindelin (10):\n  fmt-merge-msg: introduce a way to override the main branch name\n  send-pack/transport-helper: respect `core.mainBranch`\n  git_main_branch_name(): optionally report the full ref name\n  fast-export: handle overridden main branch names correctly\n  branch -m: adjust `core.mainBranch` if necessary\n  init: allow specifying the main branch name for the new repository\n  clone: handle overridden main branch names\n  remote: learn about the possibly-overridden default main branch name\n  submodule: use the correct default for the main branch name\n  testsvn: respect `init.defaultBranch`\n\nJunio C Hamano (1):\n  fast-export: do anonymize the primary branch name\n\n Documentation/config/core.txt    |  5 +++++\n Documentation/config/init.txt    |  4 ++++\n Documentation/git-init.txt       |  7 +++++++\n builtin/branch.c                 |  9 ++++++++\n builtin/clone.c                  | 19 +++++++++++++----\n builtin/fast-export.c            | 20 +++++++++++++-----\n builtin/init-db.c                | 36 +++++++++++++++++++++++++-------\n builtin/submodule--helper.c      | 10 +++++++--\n cache.h                          |  2 +-\n fmt-merge-msg.c                  |  6 ++++--\n refs.c                           | 34 ++++++++++++++++++++++++++++++\n refs.h                           | 15 +++++++++++++\n remote-testsvn.c                 | 12 ++++++++---\n remote.c                         | 15 ++++++++-----\n send-pack.c                      |  6 +++++-\n t/t0001-init.sh                  | 31 +++++++++++++++++++++++++++\n t/t3200-branch.sh                |  9 ++++++++\n t/t5528-push-default.sh          |  7 +++++++\n t/t5606-clone-options.sh         | 26 +++++++++++++++++++++++\n t/t6200-fmt-merge-msg.sh         |  7 +++++++\n t/t7406-submodule-update.sh      |  7 +++++++\n t/t9020-remote-svn.sh            |  6 ++++++\n t/t9351-fast-export-anonymize.sh | 15 +++++++++----\n transport-helper.c               |  6 +++++-\n 24 files changed, 279 insertions(+), 35 deletions(-)\n\n\nbase-commit: 0313f36c6ebecb3bffe6f15cf25a4883100f0214\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-656%2Fdscho%2Fdefault-branch-name-option-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-656/dscho/default-branch-name-option-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/656\n\nRange-diff vs v1:\n\n  -:  ----------- >  1:  ebd10f73cd7 fast-export: do anonymize the primary branch name\n  7:  e849def4a8c !  2:  f4d54739153 fmt-merge-msg: learn about the possibly-configured default branch name\n     @@ Metadata\n      Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n      \n       ## Commit message ##\n     -    fmt-merge-msg: learn about the possibly-configured default branch name\n     +    fmt-merge-msg: introduce a way to override the main branch name\n      \n     -    When formatting the commit message for merge commits, Git appends \"into\n     -    <branch-name>\" unless the current branch is the default branch.\n     +    There is a growing number of projects and companies desiring to change\n     +    the main branch name of their repositories (see e.g.\n     +    https://twitter.com/mislav/status/1270388510684598272 for background on\n     +    this).\n      \n     -    Now that we can configure what the default branch name should be, we\n     -    will want to respect that setting in that scenario rather than using the\n     -    compiled-in default branch name.\n     +    However, there are a couple of hard-coded spots in Git's source code\n     +    that make this endeavor harder than necessary. For example, when\n     +    formatting the commit message for merge commits, Git appends \"into\n     +    <branch-name>\" unless the current branch is the `master` branch.\n     +\n     +    Clearly, this is not what one wants when already having gone through all\n     +    the steps to manually rename the main branch (and taking care of all the\n     +    fall-out such as re-targeting existing Pull Requests).\n     +\n     +    Let's introduce a way to override Git's hard-coded default:\n     +    `core.mainBranch`.\n     +\n     +    We will start supporting this config option in the `git fmt-merge-msg`\n     +    command and successively adjust all other places where the main branch\n     +    name is hard-coded.\n      \n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n     + ## Documentation/config/core.txt ##\n     +@@ Documentation/config/core.txt: core.abbrev::\n     + \tin your repository, which hopefully is enough for\n     + \tabbreviated object names to stay unique for some time.\n     + \tThe minimum length is 4.\n     ++\n     ++core.mainBranch::\n     ++\tThe name of the main (or: primary) branch in the current repository.\n     ++\tFor historical reasons, `master` is used as the fall-back for this\n     ++\tsetting.\n     +\n       ## fmt-merge-msg.c ##\n      @@ fmt-merge-msg.c: static void fmt_merge_msg_title(struct strbuf *out,\n       \t\t\t\tconst char *current_branch)\n       {\n       \tint i = 0;\n      -\tchar *sep = \"\";\n     -+\tchar *sep = \"\", *default_branch_name;\n     ++\tchar *sep = \"\", *main_branch;\n       \n       \tstrbuf_addstr(out, \"Merge \");\n       \tfor (i = 0; i < srcs.nr; i++) {\n     @@ fmt-merge-msg.c: static void fmt_merge_msg_title(struct strbuf *out,\n       \t}\n       \n      -\tif (!strcmp(\"master\", current_branch))\n     -+\tdefault_branch_name = git_default_branch_name(1);\n     -+\tif (!strcmp(default_branch_name, current_branch))\n     ++\tmain_branch = git_main_branch_name();\n     ++\tif (!strcmp(main_branch, current_branch))\n       \t\tstrbuf_addch(out, '\\n');\n       \telse\n       \t\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n     -+\tfree(default_branch_name);\n     ++\tfree(main_branch);\n       }\n       \n       static void fmt_tag_signature(struct strbuf *tagbuf,\n      \n     + ## refs.c ##\n     +@@ refs.c: void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n     + \t\targv_array_pushf(prefixes, *p, len, prefix);\n     + }\n     + \n     ++char *repo_main_branch_name(struct repository *r)\n     ++{\n     ++\tconst char *config_key = \"core.mainbranch\";\n     ++\tconst char *config_display_key = \"core.mainBranch\";\n     ++\tconst char *fall_back = \"master\";\n     ++\tchar *name = NULL, *ret;\n     ++\n     ++\tif (repo_config_get_string(r, config_key, &name) < 0)\n     ++\t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n     ++\n     ++\tret = name ? name : xstrdup(fall_back);\n     ++\n     ++\tif (check_refname_format(ret, REFNAME_ALLOW_ONELEVEL))\n     ++\t\tdie(_(\"invalid branch name: %s = %s\"),\n     ++\t\t    config_display_key, name);\n     ++\n     ++\tif (name != ret)\n     ++\t\tfree(name);\n     ++\n     ++\treturn ret;\n     ++}\n     ++\n     ++char *git_main_branch_name(void)\n     ++{\n     ++\treturn repo_main_branch_name(the_repository);\n     ++}\n     ++\n     + /*\n     +  * *string and *len will only be substituted, and *string returned (for\n     +  * later free()ing) if the string passed in is a magic short-hand form\n     +\n     + ## refs.h ##\n     +@@ refs.h: int repo_dwim_log(struct repository *r, const char *str, int len, struct object_\n     + int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n     + int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n     + \n     ++/*\n     ++ * Retrieves the name of the main (or: primary) branch of the given\n     ++ * repository.\n     ++ */\n     ++char *git_main_branch_name(void);\n     ++char *repo_main_branch_name(struct repository *r);\n     ++\n     + /*\n     +  * A ref_transaction represents a collection of reference updates that\n     +  * should succeed or fail together.\n     +\n       ## t/t6200-fmt-merge-msg.sh ##\n      @@ t/t6200-fmt-merge-msg.sh: test_expect_success 'setup FETCH_HEAD' '\n       \tgit fetch . left\n       '\n       \n      +test_expect_success 'with overridden default branch name' '\n     -+\ttest_config core.defaultBranchName default &&\n      +\ttest_when_finished \"git switch master\" &&\n      +\tgit switch -c default &&\n     -+\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n     ++\tgit -c core.mainBranch=default fmt-merge-msg <.git/FETCH_HEAD >actual &&\n      +\t! grep \"into default\" actual\n      +'\n      +\n  3:  c9c9c81068e !  3:  bd8af3755ad send-pack/transport-helper: respect `core.defaultBranchName`\n     @@ Metadata\n      Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n      \n       ## Commit message ##\n     -    send-pack/transport-helper: respect `core.defaultBranchName`\n     +    send-pack/transport-helper: respect `core.mainBranch`\n      \n     -    When mentioning the default branch name in an error message, we want to\n     -    go with the preference specified by the user.\n     +    When mentioning the main branch name in an error message, we want to go\n     +    with the preference specified by the user, only falling back to Git's\n     +    own, hard-coded default when none was configured explicitly.\n      \n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n     @@ send-pack.c: int send_pack(struct send_pack_args *args,\n       \t}\n       \n       \tif (!remote_refs) {\n     -+\t\tchar *branch_name = git_default_branch_name(1);\n     ++\t\tchar *branch_name = git_main_branch_name();\n      +\n       \t\tfprintf(stderr, \"No refs in common and none specified; doing nothing.\\n\"\n      -\t\t\t\"Perhaps you should specify a branch such as 'master'.\\n\");\n     @@ send-pack.c: int send_pack(struct send_pack_args *args,\n       \t}\n       \tif (args->atomic && !atomic_supported)\n      \n     + ## t/t5528-push-default.sh ##\n     +@@ t/t5528-push-default.sh: test_expect_success 'push from/to new branch with upstream, matching and simple'\n     + \ttest_push_failure upstream\n     + '\n     + \n     ++test_expect_success '\"matching\" fails if none match' '\n     ++\tgit init --bare empty &&\n     ++\ttest_must_fail git -c core.mainBranch=unmatch push empty : 2>actual &&\n     ++\tneedle=\"Perhaps you should specify a branch such as '\\''unmatch'\\''\" &&\n     ++\ttest_i18ngrep \"$needle\" actual\n     ++'\n     ++\n     + test_expect_success 'push ambiguously named branch with upstream, matching and simple' '\n     + \tgit checkout -b ambiguous &&\n     + \ttest_config branch.ambiguous.remote parent1 &&\n     +\n       ## transport-helper.c ##\n      @@ transport-helper.c: static int push_refs(struct transport *transport,\n       \t}\n       \n       \tif (!remote_refs) {\n     -+\t\tchar *branch_name = git_default_branch_name(1);\n     ++\t\tchar *branch_name = git_main_branch_name();\n      +\n       \t\tfprintf(stderr,\n       \t\t\t_(\"No refs in common and none specified; doing nothing.\\n\"\n  -:  ----------- >  4:  ca1c63c3e01 git_main_branch_name(): optionally report the full ref name\n  8:  1efe848f2b0 !  5:  a3be4f39aa2 fast-export: respect the possibly-overridden default branch name\n     @@ Metadata\n      Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n      \n       ## Commit message ##\n     -    fast-export: respect the possibly-overridden default branch name\n     +    fast-export: handle overridden main branch names correctly\n      \n     -    When anonymizing commit history, we are careful to leave the branch name\n     -    of the default branch alone.\n     +    When anonymizing commit history, we are careful to translate the main\n     +    branch name to `ref0`.\n      \n     -    When the default branch name is overridden via the config or via the\n     -    environment variable, we will want `git fast-export` to use that\n     -    overridden name instead.\n     +    When the main branch name is overridden via the config, we will want\n     +    `git fast-export` to use that overridden name instead.\n      \n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n     @@ builtin/fast-export.c: static const char *anonymize_refname(const char *refname)\n       \t};\n       \tstatic struct hashmap refs;\n       \tstatic struct strbuf anon = STRBUF_INIT;\n     -+\tstatic char *default_branch_name;\n     ++\tstatic char *main_branch;\n       \tint i;\n       \n       \t/*\n     --\t * We also leave \"master\" as a special case, since it does not reveal\n     --\t * anything interesting.\n     -+\t * We also leave the default branch name as a special case, since it\n     -+\t * does not reveal anything interesting.\n     + \t * In certain circumstances, it might be interesting to be able to\n     + \t * identify the main branch. For that reason, let's force its name to\n     + \t * be anonymized to `ref0`.\n     ++\t *\n     ++\t * While the main branch name might often be `main` for new\n     ++\t * repositories (and `master` for aged ones), and such well-known names\n     ++\t * may not necessarily need anonymizing, it could be configured to use\n     ++\t * a secret word that the user may not want to reveal.\n       \t */\n      -\tif (!strcmp(refname, \"refs/heads/master\"))\n     -+\tif (!default_branch_name)\n     -+\t\tdefault_branch_name = git_default_branch_name(0);\n     ++\tif (!main_branch)\n     ++\t\tmain_branch = git_main_branch_name(MAIN_BRANCH_FULL_NAME);\n      +\n     -+\tif (!strcmp(refname, default_branch_name))\n     - \t\treturn refname;\n     ++\tif (!strcmp(refname, main_branch))\n     + \t\treturn \"refs/heads/ref0\";\n       \n       \tstrbuf_reset(&anon);\n     +\n     + ## t/t9351-fast-export-anonymize.sh ##\n     +@@ t/t9351-fast-export-anonymize.sh: test_expect_success 'stream translates master to ref0' '\n     + \t! grep master stream\n     + '\n     + \n     ++test_expect_success 'respects configured main branch' '\n     ++\tgit -c core.mainBranch=does-not-exist \\\n     ++\t\tfast-export --anonymize --all >stream-without-ref0 &&\n     ++\t! grep ref0 stream-without-ref0\n     ++'\n     ++\n     + test_expect_success 'stream omits other refnames' '\n     + \t! grep other stream &&\n     + \t! grep mytag stream\n  -:  ----------- >  6:  933e314813d branch -m: adjust `core.mainBranch` if necessary\n  1:  90912e32da1 !  7:  0ec04b2086e init: allow overriding the default branch name for new repositories\n     @@\n       ## Metadata ##\n     -Author: Don Goodman-Wilson <don@goodman-wilson.com>\n     +Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n      \n       ## Commit message ##\n     -    init: allow overriding the default branch name for new repositories\n     +    init: allow specifying the main branch name for the new repository\n      \n          There is a growing number of projects trying to avoid the non-inclusive\n     -    name `master` in their repositories. For existing repositories, this\n     -    requires manual work. For new repositories, the only way to do that\n     -    automatically is by copying all of Git's template directory, then\n     -    hard-coding the desired default branch name into the `.git/HEAD` file,\n     -    and then configuring `init.templateDir` to point to those copied\n     +    name `master` in their repositories: The `master`/`slave` terminology is\n     +    insensitive and perpetuates injustice. This `master`/`slave` idea is\n     +    actually where Git's naming comes from, as it was inherited from\n     +    BitKeeper which uses the term in exactly this way, see\n     +    https://mail.gnome.org/archives/desktop-devel-list/2019-May/msg00066.html\n     +\n     +    To change that branch name for new repositories, currently the only way\n     +    to do that automatically is by copying all of Git's template directory,\n     +    then hard-coding the desired default branch name into the `.git/HEAD`\n     +    file, and then configuring `init.templateDir` to point to those copied\n          template files.\n      \n     -    To make this process much less cumbersome, let's introduce support for\n     -    `core.defaultBranchName`. That way, users won't need to keep their\n     -    copied template files up to date, and won't interfere with default hooks\n     -    installed by their administrators.\n     +    To make this process much less cumbersome, let's introduce a new option:\n     +    `--main-branch=<branch-name>`.\n      \n     -    While at it, also let users set the default branch name via the\n     -    environment variable `GIT_TEST_DEFAULT_BRANCH_NAME`, in preparation for\n     -    adjusting Git's test suite to a more inclusive default branch name. As\n     -    is common in Git, the `GIT_TEST_*` variable takes precedence over the\n     -    config setting.\n     +    This will not only initialize the repository with the specified initial\n     +    branch; It will also record that branch name in `core.mainBranch`.\n      \n     -    Note: we use the prefix `core.` instead of `init.` because we want to\n     -    adjust also `git clone`, `git fmt-merge-msg` and other commands over the\n     -    course of the next commits to respect this setting.\n     +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n     -    Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n     -    Helped-by: Derrick Stolee <dstolee@microsoft.com>\n     -    Signed-off-by: Don Goodman-Wilson <don@goodman-wilson.com>\n     + ## Documentation/git-init.txt ##\n     +@@ Documentation/git-init.txt: SYNOPSIS\n     + [verse]\n     + 'git init' [-q | --quiet] [--bare] [--template=<template_directory>]\n     + \t  [--separate-git-dir <git dir>] [--object-format=<format]\n     ++\t  [-b <branch-name> | --main-branch=<branch-name>]\n     + \t  [--shared[=<permissions>]] [directory]\n     + \n     + \n     +@@ Documentation/git-init.txt: repository.\n     + +\n     + If this is reinitialization, the repository will be moved to the specified path.\n     + \n     ++-b <branch-name::\n     ++--main-branch=<branch-name>::\n     ++\n     ++Use the specified name for the main (or: initial) branch in the newly created\n     ++repository. If not specified, fall back to the default name: `master`.\n     ++\n     + --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::\n     + \n     + Specify that the Git repository is to be shared amongst several users.  This\n     +\n     + ## builtin/clone.c ##\n     +@@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)\n     + \t\t}\n     + \t}\n     + \n     +-\tinit_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, INIT_DB_QUIET);\n     ++\tinit_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,\n     ++\t\tINIT_DB_QUIET);\n     + \n     + \tif (real_git_dir)\n     + \t\tgit_dir = real_git_dir;\n      \n       ## builtin/init-db.c ##\n     +@@ builtin/init-db.c: void initialize_repository_version(int hash_algo)\n     + \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 *main_branch,\n     + \t\t\t\tconst struct repository_format *fmt)\n     + {\n     + \tstruct stat st1;\n      @@ builtin/init-db.c: static int create_default_files(const char *template_path,\n       \t\tdie(\"failed to set up refs db: %s\", err.buf);\n       \n     @@ builtin/init-db.c: static int create_default_files(const char *template_path,\n       \t\t  || readlink(path, junk, sizeof(junk)-1) != -1);\n       \tif (!reinit) {\n      -\t\tif (create_symref(\"HEAD\", \"refs/heads/master\", NULL) < 0)\n     -+\t\tchar *default_ref = git_default_branch_name(0);\n     -+\t\tif (create_symref(\"HEAD\", default_ref, NULL) < 0)\n     ++\t\tchar *ref;\n     ++\n     ++\t\tif (!main_branch)\n     ++\t\t\tmain_branch = \"master\";\n     ++\n     ++\t\tref = xstrfmt(\"refs/heads/%s\", main_branch);\n     ++\t\tif (check_refname_format(ref, 0) < 0)\n     ++\t\t\tdie(_(\"invalid main branch name: '%s'\"), main_branch);\n     ++\n     ++\t\tif (create_symref(\"HEAD\", ref, NULL) < 0)\n       \t\t\texit(1);\n     -+\t\tfree(default_ref);\n     - \t}\n     +-\t}\n     ++\t\tfree(ref);\n     ++\n     ++\t\tgit_config_set(\"core.mainbranch\", main_branch);\n     ++\t} else if (main_branch)\n     ++\t\twarning(_(\"re-init: ignoring --main-branch=%s\"), main_branch);\n       \n       \tinitialize_repository_version(fmt->hash_algo);\n     -\n     - ## refs.c ##\n     -@@ refs.c: void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n     - \t\targv_array_pushf(prefixes, *p, len, prefix);\n     + \n     +@@ builtin/init-db.c: static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash\n       }\n       \n     -+char *git_default_branch_name(int short_name)\n     -+{\n     -+\tconst char *branch_name = getenv(\"GIT_TEST_DEFAULT_BRANCH_NAME\");\n     -+\tchar *from_config = NULL, *prefixed;\n     -+\n     -+\t/*\n     -+\t * If the default branch name was not specified via the environment\n     -+\t * variable GIT_TEST_DEFAULT_BRANCH_NAME, retrieve it from the config\n     -+\t * setting core.defaultBranchName. If neither are set, fall back to the\n     -+\t * hard-coded default.\n     -+\t */\n     -+\tif (!branch_name || !*branch_name) {\n     -+\t\tif (git_config_get_string(\"core.defaultbranchname\",\n     -+\t\t\t\t\t  &from_config) < 0)\n     -+\t\t\tdie(_(\"Could not retrieve `core.defaultBranchName`\"));\n     -+\n     -+\t\tif (from_config)\n     -+\t\t\tbranch_name = from_config;\n     -+\t\telse\n     -+\t\t\tbranch_name = \"master\";\n     -+\t}\n     -+\n     -+\tif (short_name)\n     -+\t\treturn from_config ? from_config : xstrdup(branch_name);\n     -+\n     -+\t/* prepend \"refs/heads/\" to the branch name */\n     -+\tprefixed = xstrfmt(\"refs/heads/%s\", branch_name);\n     -+\tif (check_refname_format(prefixed, 0))\n     -+\t\tdie(_(\"invalid default branch name: '%s'\"), branch_name);\n     -+\n     -+\tfree(from_config);\n     -+\treturn prefixed;\n     -+}\n     -+\n     - /*\n     -  * *string and *len will only be substituted, and *string returned (for\n     -  * later free()ing) if the string passed in is a magic short-hand form\n     + int init_db(const char *git_dir, const char *real_git_dir,\n     +-\t    const char *template_dir, int hash, unsigned int flags)\n     ++\t    const char *template_dir, int hash, const char *main_branch,\n     ++\t    unsigned int flags)\n     + {\n     + \tint reinit;\n     + \tint exist_ok = flags & INIT_DB_EXIST_OK;\n     +@@ builtin/init-db.c: int init_db(const char *git_dir, const char *real_git_dir,\n     + \n     + \tvalidate_hash_algorithm(&repo_fmt, hash);\n     + \n     +-\treinit = create_default_files(template_dir, original_git_dir, &repo_fmt);\n     ++\treinit = create_default_files(template_dir, original_git_dir,\n     ++\t\t\t\t      main_branch, &repo_fmt);\n     + \n     + \tcreate_object_directory();\n     + \n     +@@ builtin/init-db.c: int cmd_init_db(int argc, const char **argv, const char *prefix)\n     + \tconst char *template_dir = NULL;\n     + \tunsigned int flags = 0;\n     + \tconst char *object_format = NULL;\n     ++\tconst char *main_branch = NULL;\n     + \tint hash_algo = GIT_HASH_UNKNOWN;\n     + \tconst struct option init_db_options[] = {\n     + \t\tOPT_STRING(0, \"template\", &template_dir, N_(\"template-directory\"),\n     +@@ builtin/init-db.c: int cmd_init_db(int argc, const char **argv, const char *prefix)\n     + \t\tOPT_BIT('q', \"quiet\", &flags, N_(\"be quiet\"), INIT_DB_QUIET),\n     + \t\tOPT_STRING(0, \"separate-git-dir\", &real_git_dir, N_(\"gitdir\"),\n     + \t\t\t   N_(\"separate git dir from working tree\")),\n     ++\t\tOPT_STRING('b', \"main-branch\", &main_branch, N_(\"name\"),\n     ++\t\t\t   N_(\"override the name of the main branch\")),\n     + \t\tOPT_STRING(0, \"object-format\", &object_format, N_(\"hash\"),\n     + \t\t\t   N_(\"specify the hash algorithm to use\")),\n     + \t\tOPT_END()\n     +@@ builtin/init-db.c: int cmd_init_db(int argc, const char **argv, const char *prefix)\n     + \tUNLEAK(work_tree);\n     + \n     + \tflags |= INIT_DB_EXIST_OK;\n     +-\treturn init_db(git_dir, real_git_dir, template_dir, hash_algo, flags);\n     ++\treturn init_db(git_dir, real_git_dir, template_dir, hash_algo,\n     ++\t\t       main_branch, flags);\n     + }\n      \n     - ## refs.h ##\n     -@@ refs.h: int repo_dwim_log(struct repository *r, const char *str, int len, struct object_\n     - int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n     - int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n     - \n     -+/*\n     -+ * Retrieves the name of the default branch. If `short_name` is non-zero, the\n     -+ * branch name will be prefixed with \"refs/heads/\".\n     -+ */\n     -+char *git_default_branch_name(int short_name);\n     -+\n     - /*\n     -  * A ref_transaction represents a collection of reference updates that\n     -  * should succeed or fail together.\n     + ## cache.h ##\n     +@@ cache.h: int path_inside_repo(const char *prefix, const char *path);\n     + \n     + int init_db(const char *git_dir, const char *real_git_dir,\n     + \t    const char *template_dir, int hash_algo,\n     +-\t    unsigned int flags);\n     ++\t    const char *main_branch, unsigned int flags);\n     + void initialize_repository_version(int hash_algo);\n     + \n     + void sanitize_stdfds(void);\n      \n       ## t/t0001-init.sh ##\n      @@ t/t0001-init.sh: test_expect_success MINGW 'redirect std handles' '\n       \tgrep \"Needed a single revision\" output.txt\n       '\n       \n     -+test_expect_success 'custom default branch name from config' '\n     -+\tgit config --global core.defaultbranchname nmb &&\n     -+\tGIT_TEST_DEFAULT_BRANCH_NAME= git init custom-config &&\n     -+\tgit config --global --unset core.defaultbranchname &&\n     -+\tgit -C custom-config symbolic-ref HEAD >actual &&\n     -+\tgrep nmb actual\n     -+'\n     -+\n     -+test_expect_success 'custom default branch name from env' '\n     -+\tGIT_TEST_DEFAULT_BRANCH_NAME=nmb git init custom-env &&\n     -+\tgit -C custom-env symbolic-ref HEAD >actual &&\n     -+\tgrep nmb actual\n     -+'\n     ++test_expect_success '--main-branch' '\n     ++\tgit init --main-branch=hello main-branch-option &&\n     ++\tgit -C main-branch-option symbolic-ref HEAD >actual &&\n     ++\techo refs/heads/hello >expect &&\n     ++\ttest_cmp expect actual &&\n      +\n     -+test_expect_success 'invalid custom default branch name' '\n     -+\ttest_must_fail env GIT_TEST_DEFAULT_BRANCH_NAME=\"with space\" \\\n     -+\t\tgit init custom-invalid 2>err &&\n     -+\ttest_i18ngrep \"invalid default branch name\" err\n     ++\t: re-initializing should not change the main branch name &&\n     ++\tgit init --main-branch=ignore main-branch-option 2>err &&\n     ++\ttest_i18ngrep \"ignoring --main-branch\" err &&\n     ++\tgit -C main-branch-option symbolic-ref HEAD >actual &&\n     ++\tgrep hello actual &&\n     ++\tgit -C main-branch-option config core.mainBranch >actual &&\n     ++\tgrep hello actual\n      +'\n      +\n       test_done\n  -:  ----------- >  8:  c711eba7e76 init: allow overriding the default main branch name via the config\n  6:  cce86c06bbf !  9:  0e59b618169 clone: learn about the possibly-configured default branch name\n     @@ Metadata\n      Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n      \n       ## Commit message ##\n     -    clone: learn about the possibly-configured default branch name\n     +    clone: handle overridden main branch names\n      \n          When cloning a repository without any branches, Git chooses a default\n          branch name for the as-yet unborn branch.\n      \n     -    Now that we can configure what the default branch name should be, we\n     -    will want `git clone` to respect that setting.\n     +    As part of the implicit initialization of the local repository, Git\n     +    just learned to respect `init.defaultBranch` to choose a different main\n     +    branch name. We now really want that branch name to be used as a\n     +    fall-back.\n     +\n     +    At the same time, we also want to make sure that `core.mainBranch` is\n     +    set correctly, reflecting the name of the main branch. In case we detect\n     +    a main branch, we do have to do that explicitly, otherwise `init_db()`\n     +    will already have done that for us.\n      \n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n     + ## Documentation/config/init.txt ##\n     +@@ Documentation/config/init.txt: init.templateDir::\n     + \t(See the \"TEMPLATE DIRECTORY\" section of linkgit:git-init[1].)\n     + \n     + init.defaultBranch::\n     +-\tAllows overriding the default branch name when initializing\n     +-\ta new repository.\n     ++\tAllows overriding the default branch name e.g. when initializing\n     ++\ta new repository or when cloning an empty repository.\n     +\n       ## builtin/clone.c ##\n     +@@ builtin/clone.c: static void update_head(const struct ref *our, const struct ref *remote,\n     + \t\t/* Local default branch link */\n     + \t\tif (create_symref(\"HEAD\", our->name, NULL) < 0)\n     + \t\t\tdie(_(\"unable to update HEAD\"));\n     ++\t\tgit_config_set(\"core.mainbranch\", head);\n     + \t\tif (!option_bare) {\n     + \t\t\tupdate_ref(msg, \"HEAD\", &our->old_oid, NULL, 0,\n     + \t\t\t\t   UPDATE_REFS_DIE_ON_ERR);\n      @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)\n       \t\tremote_head_points_at = NULL;\n       \t\tremote_head = NULL;\n     @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)\n      -\t\t\tinstall_branch_config(0, \"master\", option_origin,\n      -\t\t\t\t\t      \"refs/heads/master\");\n      +\t\tif (!option_bare) {\n     -+\t\t\tchar *default_branch = git_default_branch_name(0);\n     ++\t\t\tchar *main_branch =\n     ++\t\t\t\tgit_main_branch_name(MAIN_BRANCH_FULL_NAME);\n      +\t\t\tconst char *nick;\n      +\n     -+\t\t\tif (!skip_prefix(default_branch, \"refs/heads/\", &nick))\n     ++\t\t\tif (!skip_prefix(main_branch, \"refs/heads/\", &nick))\n      +\t\t\t\tBUG(\"unexpected default branch '%s'\",\n     -+\t\t\t\t    default_branch);\n     ++\t\t\t\t    main_branch);\n      +\t\t\tinstall_branch_config(0, nick, option_origin,\n     -+\t\t\t\t\t      default_branch);\n     -+\t\t\tfree(default_branch);\n     ++\t\t\t\t\t      main_branch);\n     ++\t\t\tfree(main_branch);\n      +\t\t}\n       \t}\n       \n       \twrite_refspec_config(src_ref_prefix, our_head_points_at,\n      \n     - ## t/t5609-clone-branch.sh ##\n     -@@ t/t5609-clone-branch.sh: test_expect_success 'clone -b not allowed with empty repos' '\n     - \ttest_must_fail git clone -b branch empty clone-branch-empty\n     + ## t/t5606-clone-options.sh ##\n     +@@ t/t5606-clone-options.sh: test_expect_success 'redirected clone -v does show progress' '\n     + \n       '\n       \n     -+test_expect_success 'chooses correct default branch name' '\n     -+\tGIT_TEST_DEFAULT_BRANCH_NAME= \\\n     -+\t\tgit -c core.defaultBranchName=up clone empty whats-up &&\n     -+\ttest_write_lines refs/heads/up refs/heads/up >expect &&\n     -+\tgit -C whats-up symbolic-ref HEAD >actual &&\n     -+\tgit -C whats-up config branch.up.merge >>actual &&\n     -+\ttest_cmp expect actual\n     ++test_expect_success 'chooses correct default main branch name' '\n     ++\tgit init --bare empty &&\n     ++\tgit -c init.defaultBranch=up clone empty whats-up &&\n     ++\ttest refs/heads/up = $(git -C whats-up symbolic-ref HEAD) &&\n     ++\ttest up = $(git -C whats-up config core.mainBranch) &&\n     ++\ttest refs/heads/up = $(git -C whats-up config branch.up.merge)\n     ++'\n     ++\n     ++test_expect_success 'guesses main branch name correctly' '\n     ++\tgit init --main-branch=guess main-branch &&\n     ++\ttest_commit -C main-branch no-spoilers &&\n     ++\tgit -C main-branch branch abc guess &&\n     ++\tgit clone main-branch is-it &&\n     ++\ttest guess = $(git -C is-it config core.mainBranch) &&\n     ++\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD)\n      +'\n      +\n       test_done\n  2:  06a2cea051c ! 10:  59b8f4cfbb2 remote: respect `core.defaultBranchName`\n     @@ Metadata\n      Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n      \n       ## Commit message ##\n     -    remote: respect `core.defaultBranchName`\n     +    remote: learn about the possibly-overridden default main branch name\n      \n          When guessing the default branch name of a remote, and there are no refs\n          to guess from, we want to go with the preference specified by the user\n     -    for the fall-back.\n     +    for the fall-back, i.e. the default name to be used for the main branch\n     +    of new repositories (because as far as the user is concerned, a remote\n     +    that has no branches yet is a new repository).\n      \n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n     @@ remote.c: static void read_remotes_file(struct remote *remote)\n       static void read_branches_file(struct remote *remote)\n       {\n      -\tchar *frag;\n     -+\tchar *frag, *default_branch_name = NULL;\n     ++\tchar *frag, *main_branch = NULL;\n       \tstruct strbuf buf = STRBUF_INIT;\n       \tFILE *f = fopen_or_warn(git_path(\"branches/%s\", remote->name), \"r\");\n       \n     @@ remote.c: static void read_branches_file(struct remote *remote)\n       \t/*\n       \t * The branches file would have URL and optionally\n      -\t * #branch specified.  The \"master\" (or specified) branch is\n     -+\t * #branch specified.  The default (or specified) branch is\n     ++\t * #branch specified.  The main (or specified) branch is\n       \t * fetched and stored in the local branch matching the\n       \t * remote name.\n       \t */\n     @@ remote.c: static void read_branches_file(struct remote *remote)\n       \t\t*(frag++) = '\\0';\n       \telse\n      -\t\tfrag = \"master\";\n     -+\t\tfrag = default_branch_name = git_default_branch_name(1);\n     ++\t\tfrag = main_branch = git_main_branch_name(MAIN_BRANCH_FOR_INIT);\n       \n       \tadd_url_alias(remote, strbuf_detach(&buf, NULL));\n       \tstrbuf_addf(&buf, \"refs/heads/%s:refs/heads/%s\",\n     @@ remote.c: static void read_branches_file(struct remote *remote)\n       \tstrbuf_addf(&buf, \"HEAD:refs/heads/%s\", frag);\n       \trefspec_append(&remote->push, buf.buf);\n       \tremote->fetch_tags = 1; /* always auto-follow */\n     -+\tfree(default_branch_name);\n     ++\tfree(main_branch);\n       \tstrbuf_release(&buf);\n       }\n       \n      @@ remote.c: struct ref *guess_remote_head(const struct ref *head,\n     + \tif (head->symref)\n     + \t\treturn copy_ref(find_ref_by_name(refs, head->symref));\n       \n     - \t/* If refs/heads/master could be right, it is. */\n     +-\t/* If refs/heads/master could be right, it is. */\n     ++\t/* If a remote branch exists with the main branch name, let's use it. */\n       \tif (!all) {\n      -\t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n     -+\t\tchar *name = git_default_branch_name(0);\n     ++\t\tchar *name = git_main_branch_name(MAIN_BRANCH_FULL_NAME |\n     ++\t\t\t\t\t\t  MAIN_BRANCH_FOR_INIT);\n      +\n      +\t\tr = find_ref_by_name(refs, name);\n      +\t\tfree(name);\n       \t\tif (r && oideq(&r->old_oid, &head->old_oid))\n       \t\t\treturn copy_ref(r);\n       \t}\n     +\n     + ## t/t5606-clone-options.sh ##\n     +@@ t/t5606-clone-options.sh: test_expect_success 'guesses main branch name correctly' '\n     + \tgit -C main-branch branch abc guess &&\n     + \tgit clone main-branch is-it &&\n     + \ttest guess = $(git -C is-it config core.mainBranch) &&\n     +-\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD)\n     ++\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD) &&\n     ++\n     ++\tgit -c init.defaultBranch=none init --bare no-head &&\n     ++\tgit -C main-branch push ../no-head guess abc &&\n     ++\tgit clone no-head is-it2 &&\n     ++\ttest_must_fail git -C is-it2 symbolic-ref refs/remotes/origin/HEAD &&\n     ++\tgit -C no-head update-ref --no-deref HEAD refs/heads/guess &&\n     ++\tgit -c init.defaultBranch=guess clone no-head is-it3 &&\n     ++\ttest refs/remotes/origin/guess = \\\n     ++\t\t$(git -C is-it3 symbolic-ref refs/remotes/origin/HEAD)\n     + '\n     + \n     + test_done\n  5:  06ef42052d5 ! 11:  59d6267f099 submodule: use the (possibly overridden) default branch name\n     @@ Metadata\n      Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n      \n       ## Commit message ##\n     -    submodule: use the (possibly overridden) default branch name\n     +    submodule: use the correct default for the main branch name\n      \n          To allow for overriding the default branch name, we have introduced a\n          config setting. With this patch, the `git submodule` command learns\n     @@ builtin/submodule--helper.c: static const char *remote_submodule_branch(const ch\n      -\tif (!branch)\n      -\t\treturn \"master\";\n      +\tif (!branch) {\n     -+\t\tstatic char *default_branch;\n     ++\t\tstatic char *fall_back;\n      +\n     -+\t\tif (!default_branch)\n     -+\t\t\tdefault_branch = git_default_branch_name(1);\n     ++\t\tif (!fall_back)\n     ++\t\t\tfall_back = git_main_branch_name(MAIN_BRANCH_FOR_INIT);\n      +\n     -+\t\treturn default_branch;\n     ++\t\treturn fall_back;\n      +\t}\n       \n       \tif (!strcmp(branch, \".\")) {\n       \t\tconst char *refname = resolve_ref_unsafe(\"HEAD\", 0, NULL, NULL);\n     +\n     + ## t/t7406-submodule-update.sh ##\n     +@@ t/t7406-submodule-update.sh: test_expect_success 'setup a submodule tree' '\n     + \t)\n     + '\n     + \n     ++test_expect_success 'update --remote uses configured default main branch' '\n     ++\tgit clone super main-branch &&\n     ++\ttest_must_fail git -C main-branch -c init.defaultBranch=hello \\\n     ++\t\tsubmodule update --init --remote submodule 2>err &&\n     ++\ttest_i18ngrep origin/hello err\n     ++'\n     ++\n     + test_expect_success 'submodule update detaching the HEAD ' '\n     + \t(cd super/submodule &&\n     + \t git reset --hard HEAD~1\n  4:  73cb567cd33 ! 12:  e09f857f068 testsvn: respect `core.defaultBranchName`\n     @@ Metadata\n      Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n      \n       ## Commit message ##\n     -    testsvn: respect `core.defaultBranchName`\n     +    testsvn: respect `init.defaultBranch`\n      \n     -    Since the default branch name can now be configured, the `testsvn`\n     -    remote helper needs to be told about it.\n     +    The default name of the main branch in new repositories can now be\n     +    configured. The `testsvn` remote helper translates the remote Subversion\n     +    repository's branch name `trunk` to the hard-coded name `master`.\n     +    Clearly, the intention was to make the name align with Git's detaults.\n     +\n     +    So while we are not talking about a newly-created repository in the\n     +    `testsvn` context, it _still_ makes sense to use the overridden default\n     +    name for the main branch whenever users configured it.\n      \n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n     @@ remote-testsvn.c: int cmd_main(int argc, const char **argv)\n       \t\t\tnotes_ref_sb = STRBUF_INIT;\n       \tstatic struct remote *remote;\n      -\tconst char *url_in;\n     -+\tconst char *url_in, *default_branch;\n     ++\tconst char *url_in, *remote_ref_short;\n       \n       \tsetup_git_directory();\n       \tif (argc < 2 || argc > 3) {\n     @@ remote-testsvn.c: int cmd_main(int argc, const char **argv)\n       \t\treturn 1;\n       \t}\n       \n     -+\tremote_ref = git_default_branch_name(0);\n     -+\tif (!skip_prefix(remote_ref, \"refs/heads/\", &default_branch))\n     ++\tremote_ref = git_main_branch_name(MAIN_BRANCH_FULL_NAME |\n     ++\t\t\t\t\t  MAIN_BRANCH_FOR_INIT);\n     ++\tif (!skip_prefix(remote_ref, \"refs/heads/\", &remote_ref_short))\n      +\t\tBUG(\"unexpected remote_ref '%s'\", remote_ref);\n      +\n       \tremote = remote_get(argv[1]);\n     @@ remote-testsvn.c: int cmd_main(int argc, const char **argv)\n       \n      -\tstrbuf_addf(&private_ref_sb, \"refs/svn/%s/master\", remote->name);\n      +\tstrbuf_addf(&private_ref_sb, \"refs/svn/%s/%s\",\n     -+\t\t    remote->name, default_branch);\n     ++\t\t    remote->name, remote_ref_short);\n       \tprivate_ref = private_ref_sb.buf;\n       \n       \tstrbuf_addf(&notes_ref_sb, \"refs/notes/%s/revs\", remote->name);\n     +\n     + ## t/t9020-remote-svn.sh ##\n     +@@ t/t9020-remote-svn.sh: test_expect_success REMOTE_SVN 'incremental imports must lead to the same head'\n     + \ttest_cmp master.good .git/refs/remotes/svnsim/master\n     + '\n     + \n     ++test_expect_success REMOTE_SVN 'respects configured default main branch' '\n     ++\tgit -c init.defaultBranch=trunk remote add -f trunk \\\n     ++\t\t\"testsvn::file://$TEST_DIRECTORY/t9154/svn.dump\" &&\n     ++\tgit rev-parse --verify refs/remotes/trunk/trunk\n     ++'\n     ++\n     + test_debug 'git branch -a'\n     + \n     + test_done\n  9:  f680e66dd6d <  -:  ----------- Document how the default branch name can be overridden\n\n-- \ngitgitgadget\n"},{"id":"399778","messageId":"0ec04b2086ee72f71a0328553752ea031e14ec44.1592225416.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v2.git.1592225416.gitgitgadget@gmail.com","subject":"[PATCH v2 07/12] init: allow specifying the main branch name for the new repository","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-15T12:50:11Z","receivedAt":"2020-06-15T12:50:51Z","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\nThere is a growing number of projects trying to avoid the non-inclusive\nname `master` in their repositories: The `master`/`slave` terminology is\ninsensitive and perpetuates injustice. This `master`/`slave` idea is\nactually where Git's naming comes from, as it was inherited from\nBitKeeper which uses the term in exactly this way, see\nhttps://mail.gnome.org/archives/desktop-devel-list/2019-May/msg00066.html\n\nTo change that branch name for new repositories, currently the only way\nto do that automatically is by copying all of Git's template directory,\nthen hard-coding the desired default branch name into the `.git/HEAD`\nfile, and then configuring `init.templateDir` to point to those copied\ntemplate files.\n\nTo make this process much less cumbersome, let's introduce a new option:\n`--main-branch=<branch-name>`.\n\nThis will not only initialize the repository with the specified initial\nbranch; It will also record that branch name in `core.mainBranch`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/git-init.txt |  7 +++++++\n builtin/clone.c            |  3 ++-\n builtin/init-db.c          | 34 +++++++++++++++++++++++++++-------\n cache.h                    |  2 +-\n t/t0001-init.sh            | 15 +++++++++++++++\n 5 files changed, 52 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\nindex adc6adfd380..011a7ff4d76 100644\n--- a/Documentation/git-init.txt\n+++ b/Documentation/git-init.txt\n@@ -11,6 +11,7 @@ SYNOPSIS\n [verse]\n 'git init' [-q | --quiet] [--bare] [--template=<template_directory>]\n \t  [--separate-git-dir <git dir>] [--object-format=<format]\n+\t  [-b <branch-name> | --main-branch=<branch-name>]\n \t  [--shared[=<permissions>]] [directory]\n \n \n@@ -67,6 +68,12 @@ repository.\n +\n If this is reinitialization, the repository will be moved to the specified path.\n \n+-b <branch-name::\n+--main-branch=<branch-name>::\n+\n+Use the specified name for the main (or: initial) branch in the newly created\n+repository. If not specified, fall back to the default name: `master`.\n+\n --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::\n \n Specify that the Git repository is to be shared amongst several users.  This\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex cb48a291caf..487b0a42d75 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -1108,7 +1108,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \n-\tinit_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, INIT_DB_QUIET);\n+\tinit_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,\n+\t\tINIT_DB_QUIET);\n \n \tif (real_git_dir)\n \t\tgit_dir = real_git_dir;\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 0b7222e7188..287cdafaab1 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -203,6 +203,7 @@ void initialize_repository_version(int hash_algo)\n \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 *main_branch,\n \t\t\t\tconst struct repository_format *fmt)\n {\n \tstruct stat st1;\n@@ -258,16 +259,29 @@ static int create_default_files(const char *template_path,\n \t\tdie(\"failed to set up refs db: %s\", err.buf);\n \n \t/*\n-\t * Create the default symlink from \".git/HEAD\" to the \"master\"\n-\t * branch, if it does not exist yet.\n+\t * Create the default symlink from \".git/HEAD\" to the default\n+\t * branch name, if it does not exist yet.\n \t */\n \tpath = git_path_buf(&buf, \"HEAD\");\n \treinit = (!access(path, R_OK)\n \t\t  || readlink(path, junk, sizeof(junk)-1) != -1);\n \tif (!reinit) {\n-\t\tif (create_symref(\"HEAD\", \"refs/heads/master\", NULL) < 0)\n+\t\tchar *ref;\n+\n+\t\tif (!main_branch)\n+\t\t\tmain_branch = \"master\";\n+\n+\t\tref = xstrfmt(\"refs/heads/%s\", main_branch);\n+\t\tif (check_refname_format(ref, 0) < 0)\n+\t\t\tdie(_(\"invalid main branch name: '%s'\"), main_branch);\n+\n+\t\tif (create_symref(\"HEAD\", ref, NULL) < 0)\n \t\t\texit(1);\n-\t}\n+\t\tfree(ref);\n+\n+\t\tgit_config_set(\"core.mainbranch\", main_branch);\n+\t} else if (main_branch)\n+\t\twarning(_(\"re-init: ignoring --main-branch=%s\"), main_branch);\n \n \tinitialize_repository_version(fmt->hash_algo);\n \n@@ -383,7 +397,8 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash\n }\n \n int init_db(const char *git_dir, const char *real_git_dir,\n-\t    const char *template_dir, int hash, unsigned int flags)\n+\t    const char *template_dir, int hash, const char *main_branch,\n+\t    unsigned int flags)\n {\n \tint reinit;\n \tint exist_ok = flags & INIT_DB_EXIST_OK;\n@@ -425,7 +440,8 @@ int init_db(const char *git_dir, const char *real_git_dir,\n \n \tvalidate_hash_algorithm(&repo_fmt, hash);\n \n-\treinit = create_default_files(template_dir, original_git_dir, &repo_fmt);\n+\treinit = create_default_files(template_dir, original_git_dir,\n+\t\t\t\t      main_branch, &repo_fmt);\n \n \tcreate_object_directory();\n \n@@ -528,6 +544,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \tconst char *template_dir = NULL;\n \tunsigned int flags = 0;\n \tconst char *object_format = NULL;\n+\tconst char *main_branch = NULL;\n \tint hash_algo = GIT_HASH_UNKNOWN;\n \tconst struct option init_db_options[] = {\n \t\tOPT_STRING(0, \"template\", &template_dir, N_(\"template-directory\"),\n@@ -541,6 +558,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \t\tOPT_BIT('q', \"quiet\", &flags, N_(\"be quiet\"), INIT_DB_QUIET),\n \t\tOPT_STRING(0, \"separate-git-dir\", &real_git_dir, N_(\"gitdir\"),\n \t\t\t   N_(\"separate git dir from working tree\")),\n+\t\tOPT_STRING('b', \"main-branch\", &main_branch, N_(\"name\"),\n+\t\t\t   N_(\"override the name of the main branch\")),\n \t\tOPT_STRING(0, \"object-format\", &object_format, N_(\"hash\"),\n \t\t\t   N_(\"specify the hash algorithm to use\")),\n \t\tOPT_END()\n@@ -652,5 +671,6 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \tUNLEAK(work_tree);\n \n \tflags |= INIT_DB_EXIST_OK;\n-\treturn init_db(git_dir, real_git_dir, template_dir, hash_algo, flags);\n+\treturn init_db(git_dir, real_git_dir, template_dir, hash_algo,\n+\t\t       main_branch, flags);\n }\ndiff --git a/cache.h b/cache.h\nindex 0f0485ecfe2..afd5ad3121f 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -628,7 +628,7 @@ int path_inside_repo(const char *prefix, const char *path);\n \n int init_db(const char *git_dir, const char *real_git_dir,\n \t    const char *template_dir, int hash_algo,\n-\t    unsigned int flags);\n+\t    const char *main_branch, unsigned int flags);\n void initialize_repository_version(int hash_algo);\n \n void sanitize_stdfds(void);\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 1edd5aeb8f0..5d8e321a703 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -464,4 +464,19 @@ test_expect_success MINGW 'redirect std handles' '\n \tgrep \"Needed a single revision\" output.txt\n '\n \n+test_expect_success '--main-branch' '\n+\tgit init --main-branch=hello main-branch-option &&\n+\tgit -C main-branch-option symbolic-ref HEAD >actual &&\n+\techo refs/heads/hello >expect &&\n+\ttest_cmp expect actual &&\n+\n+\t: re-initializing should not change the main branch name &&\n+\tgit init --main-branch=ignore main-branch-option 2>err &&\n+\ttest_i18ngrep \"ignoring --main-branch\" err &&\n+\tgit -C main-branch-option symbolic-ref HEAD >actual &&\n+\tgrep hello actual &&\n+\tgit -C main-branch-option config core.mainBranch >actual &&\n+\tgrep hello actual\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"399787","messageId":"b530fe66-9cf6-ea63-e9e6-123448e2d978@gmail.com","threadId":"53651","inReplyTo":"f4d547391537e5c3b0b4a07adb41b6aa56541fc3.1592225416.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main branch name","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2020-06-15T15:00:02Z","receivedAt":"2020-06-15T15:00:13Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi dscho\n\nOn 15/06/2020 13:50, Johannes Schindelin via GitGitGadget wrote:\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> \n> There is a growing number of projects and companies desiring to change\n> the main branch name of their repositories (see e.g.\n> https://twitter.com/mislav/status/1270388510684598272 for background on\n> this).\n\nI think this is a good way of phrasing the rationale for the change\n\n> However, there are a couple of hard-coded spots in Git's source code\n> that make this endeavor harder than necessary. For example, when\n> formatting the commit message for merge commits, Git appends \"into\n> <branch-name>\" unless the current branch is the `master` branch.\n> \n> Clearly, this is not what one wants when already having gone through all\n> the steps to manually rename the main branch\n\nThis didn't quite scan for me maybe s/already having/one has already/ ?\n\n> (and taking care of all the\n> fall-out such as re-targeting existing Pull Requests).\n> \n> Let's introduce a way to override Git's hard-coded default:\n> `core.mainBranch`.\n> \n> We will start supporting this config option in the `git fmt-merge-msg`\n> command and successively adjust all other places where the main branch\n> name is hard-coded.\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>   Documentation/config/core.txt |  5 +++++\n>   fmt-merge-msg.c               |  6 ++++--\n>   refs.c                        | 27 +++++++++++++++++++++++++++\n>   refs.h                        |  7 +++++++\n>   t/t6200-fmt-merge-msg.sh      |  7 +++++++\n>   5 files changed, 50 insertions(+), 2 deletions(-)\n> \n> diff --git a/Documentation/config/core.txt b/Documentation/config/core.txt\n> index 74619a9c03b..32bb5368ebb 100644\n> --- a/Documentation/config/core.txt\n> +++ b/Documentation/config/core.txt\n> @@ -626,3 +626,8 @@ core.abbrev::\n>   \tin your repository, which hopefully is enough for\n>   \tabbreviated object names to stay unique for some time.\n>   \tThe minimum length is 4.\n> +\n> +core.mainBranch::\n> +\tThe name of the main (or: primary) branch in the current repository.\n> +\tFor historical reasons, `master` is used as the fall-back for this\n> +\tsetting.\n> diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\n> index 72d32bd73b1..43f4f829242 100644\n> --- a/fmt-merge-msg.c\n> +++ b/fmt-merge-msg.c\n> @@ -407,7 +407,7 @@ static void fmt_merge_msg_title(struct strbuf *out,\n>   \t\t\t\tconst char *current_branch)\n>   {\n>   \tint i = 0;\n> -\tchar *sep = \"\";\n> +\tchar *sep = \"\", *main_branch;\n>   \n>   \tstrbuf_addstr(out, \"Merge \");\n>   \tfor (i = 0; i < srcs.nr; i++) {\n> @@ -451,10 +451,12 @@ static void fmt_merge_msg_title(struct strbuf *out,\n>   \t\t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n>   \t}\n>   \n> -\tif (!strcmp(\"master\", current_branch))\n> +\tmain_branch = git_main_branch_name();\n> +\tif (!strcmp(main_branch, current_branch))\n>   \t\tstrbuf_addch(out, '\\n');\n>   \telse\n>   \t\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n> +\tfree(main_branch);\n>   }\n>   \n>   static void fmt_tag_signature(struct strbuf *tagbuf,\n> diff --git a/refs.c b/refs.c\n> index 224ff66c7bb..f1854cffa2f 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -560,6 +560,33 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n>   \t\targv_array_pushf(prefixes, *p, len, prefix);\n>   }\n>   \n> +char *repo_main_branch_name(struct repository *r)\n> +{\n> +\tconst char *config_key = \"core.mainbranch\";\n> +\tconst char *config_display_key = \"core.mainBranch\";\n> +\tconst char *fall_back = \"master\";\n> +\tchar *name = NULL, *ret;\n> +\n> +\tif (repo_config_get_string(r, config_key, &name) < 0)\n> +\t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n> +\n> +\tret = name ? name : xstrdup(fall_back);\n> +\n> +\tif (check_refname_format(ret, REFNAME_ALLOW_ONELEVEL))\n> +\t\tdie(_(\"invalid branch name: %s = %s\"),\n> +\t\t    config_display_key, name);\n> +\n> +\tif (name != ret)\n> +\t\tfree(name);\n\nI'm struggling to come up with a scenario where name != NULL && name != \nret here, however once we get to patch 4 that scenario definitely does \nexist.\n\n> +\n> +\treturn ret;\n> +}\n> +\n> +char *git_main_branch_name(void)\n> +{\n> +\treturn repo_main_branch_name(the_repository);\n> +}\n> +\n>   /*\n>    * *string and *len will only be substituted, and *string returned (for\n>    * later free()ing) if the string passed in is a magic short-hand form\n> diff --git a/refs.h b/refs.h\n> index a92d2c74c83..a207ef01348 100644\n> --- a/refs.h\n> +++ b/refs.h\n> @@ -154,6 +154,13 @@ int repo_dwim_log(struct repository *r, const char *str, int len, struct object_\n>   int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n>   int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n>   \n> +/*\n> + * Retrieves the name of the main (or: primary) branch of the given\n\nnit pick, I'm confused by the ':'\n\nBest Wishes\n\nPhillip\n\n> + * repository.\n> + */\n> +char *git_main_branch_name(void);\n> +char *repo_main_branch_name(struct repository *r);\n> +\n>   /*\n>    * A ref_transaction represents a collection of reference updates that\n>    * should succeed or fail together.\n> diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh\n> index e4c2a6eca43..7a873f4a05c 100755\n> --- a/t/t6200-fmt-merge-msg.sh\n> +++ b/t/t6200-fmt-merge-msg.sh\n> @@ -158,6 +158,13 @@ test_expect_success 'setup FETCH_HEAD' '\n>   \tgit fetch . left\n>   '\n>   \n> +test_expect_success 'with overridden default branch name' '\n> +\ttest_when_finished \"git switch master\" &&\n> +\tgit switch -c default &&\n> +\tgit -c core.mainBranch=default fmt-merge-msg <.git/FETCH_HEAD >actual &&\n> +\t! grep \"into default\" actual\n> +'\n> +\n>   test_expect_success 'merge.log=3 limits shortlog length' '\n>   \tcat >expected <<-EOF &&\n>   \tMerge branch ${apos}left${apos}\n> \n"},{"id":"399788","messageId":"e8ed76e8-bdd5-ae58-56ea-0513a21ac5d6@gmail.com","threadId":"53651","inReplyTo":"ca1c63c3e012edde26b4f0c67175ca53f4d29e08.1592225416.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 04/12] git_main_branch_name(): optionally report the full ref name","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2020-06-15T15:04:06Z","receivedAt":"2020-06-15T15:04:15Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi dscho\n\nOn 15/06/2020 13:50, Johannes Schindelin via GitGitGadget wrote:\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> \n> We are about to introduce the first caller of that function (`git\n> fast-export`) that wants a full ref name instead of the short branch\n> name.\n> \n> To make this change easier to review, let's refactor the function\n> accordingly without mixing in the actual first call using the new flag.\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>   fmt-merge-msg.c    |  2 +-\n>   refs.c             | 12 ++++++++----\n>   refs.h             |  8 ++++++--\n>   send-pack.c        |  2 +-\n>   transport-helper.c |  2 +-\n>   5 files changed, 17 insertions(+), 9 deletions(-)\n> \n> diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\n> index 43f4f829242..03dba905643 100644\n> --- a/fmt-merge-msg.c\n> +++ b/fmt-merge-msg.c\n> @@ -451,7 +451,7 @@ static void fmt_merge_msg_title(struct strbuf *out,\n>   \t\t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n>   \t}\n>   \n> -\tmain_branch = git_main_branch_name();\n> +\tmain_branch = git_main_branch_name(0);\n>   \tif (!strcmp(main_branch, current_branch))\n>   \t\tstrbuf_addch(out, '\\n');\n>   \telse\n> diff --git a/refs.c b/refs.c\n> index f1854cffa2f..7da3ac178c4 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -560,8 +560,9 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n>   \t\targv_array_pushf(prefixes, *p, len, prefix);\n>   }\n>   \n> -char *repo_main_branch_name(struct repository *r)\n> +char *repo_main_branch_name(struct repository *r, int flags)\n>   {\n> +\tint full_name = flags & MAIN_BRANCH_FULL_NAME;\n>   \tconst char *config_key = \"core.mainbranch\";\n>   \tconst char *config_display_key = \"core.mainBranch\";\n>   \tconst char *fall_back = \"master\";\n> @@ -570,7 +571,10 @@ char *repo_main_branch_name(struct repository *r)\n>   \tif (repo_config_get_string(r, config_key, &name) < 0)\n>   \t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n>   \n> -\tret = name ? name : xstrdup(fall_back);\n> +\tif (full_name)\n> +\t\tret = xstrfmt(\"refs/heads/%s\", name ? name : fall_back);\n> +\telse\n> +\t\tret = name ? name : xstrdup(fall_back);\n\nThis looks good, we always check the name before returning it and free \nname if we're returning refs/heads/<name>\n\n>   \tif (check_refname_format(ret, REFNAME_ALLOW_ONELEVEL))\n>   \t\tdie(_(\"invalid branch name: %s = %s\"),\n> @@ -582,9 +586,9 @@ char *repo_main_branch_name(struct repository *r)\n>   \treturn ret;\n>   }\n>   \n> -char *git_main_branch_name(void)\n> +char *git_main_branch_name(int flags)\n>   {\n> -\treturn repo_main_branch_name(the_repository);\n> +\treturn repo_main_branch_name(the_repository, flags);\n>   }\n>   \n>   /*\n> diff --git a/refs.h b/refs.h\n> index a207ef01348..96472f9a9f5 100644\n> --- a/refs.h\n> +++ b/refs.h\n> @@ -157,9 +157,13 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n>   /*\n>    * Retrieves the name of the main (or: primary) branch of the given\n>    * repository.\n> + *\n> + * The result is an allocated string. Unless the flags ask for a short name, it\n> + * will be prefixed with \"refs/heads/\".\n>    */\n\nnit pick: the flag is defined to give the fullname, to get the short \nname you just pass 0.\n\nBest Wishes\n\nPhillip\n\n> -char *git_main_branch_name(void);\n> -char *repo_main_branch_name(struct repository *r);\n> +#define MAIN_BRANCH_FULL_NAME (1<<0)\n> +char *git_main_branch_name(int flags);\n> +char *repo_main_branch_name(struct repository *r, int flags);\n>   \n>   /*\n>    * A ref_transaction represents a collection of reference updates that\n> diff --git a/send-pack.c b/send-pack.c\n> index 2532864c812..898720511d0 100644\n> --- a/send-pack.c\n> +++ b/send-pack.c\n> @@ -405,7 +405,7 @@ int send_pack(struct send_pack_args *args,\n>   \t}\n>   \n>   \tif (!remote_refs) {\n> -\t\tchar *branch_name = git_main_branch_name();\n> +\t\tchar *branch_name = git_main_branch_name(0);\n>   \n>   \t\tfprintf(stderr, \"No refs in common and none specified; doing nothing.\\n\"\n>   \t\t\t\"Perhaps you should specify a branch such as '%s'.\\n\",\n> diff --git a/transport-helper.c b/transport-helper.c\n> index 8c8f40e322d..7a54e5b2fb2 100644\n> --- a/transport-helper.c\n> +++ b/transport-helper.c\n> @@ -1044,7 +1044,7 @@ static int push_refs(struct transport *transport,\n>   \t}\n>   \n>   \tif (!remote_refs) {\n> -\t\tchar *branch_name = git_main_branch_name();\n> +\t\tchar *branch_name = git_main_branch_name(0);\n>   \n>   \t\tfprintf(stderr,\n>   \t\t\t_(\"No refs in common and none specified; doing nothing.\\n\"\n> \n"},{"id":"399789","messageId":"a0982afb-8c44-aeff-1839-6e0aa897fcf2@gmail.com","threadId":"53651","inReplyTo":"a3be4f39aa240e614a2e12756e1ea864c35137a2.1592225416.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 05/12] fast-export: handle overridden main branch names correctly","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2020-06-15T15:05:52Z","receivedAt":"2020-06-15T15:06:00Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi dscho\n\nOn 15/06/2020 13:50, Johannes Schindelin via GitGitGadget wrote:\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> \n> When anonymizing commit history, we are careful to translate the main\n> branch name to `ref0`.\n> \n> When the main branch name is overridden via the config, we will want\n> `git fast-export` to use that overridden name instead.\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>   builtin/fast-export.c            | 11 ++++++++++-\n>   t/t9351-fast-export-anonymize.sh |  6 ++++++\n>   2 files changed, 16 insertions(+), 1 deletion(-)\n> \n> diff --git a/builtin/fast-export.c b/builtin/fast-export.c\n> index 1072bbf041f..deeb01b6937 100644\n> --- a/builtin/fast-export.c\n> +++ b/builtin/fast-export.c\n> @@ -515,14 +515,23 @@ static const char *anonymize_refname(const char *refname)\n>   \t};\n>   \tstatic struct hashmap refs;\n>   \tstatic struct strbuf anon = STRBUF_INIT;\n> +\tstatic char *main_branch;\n>   \tint i;\n>   \n>   \t/*\n>   \t * In certain circumstances, it might be interesting to be able to\n>   \t * identify the main branch. For that reason, let's force its name to\n>   \t * be anonymized to `ref0`.\n> +\t *\n> +\t * While the main branch name might often be `main` for new\n> +\t * repositories (and `master` for aged ones), and such well-known names\n> +\t * may not necessarily need anonymizing, it could be configured to use\n> +\t * a secret word that the user may not want to reveal.\n>   \t */\n> -\tif (!strcmp(refname, \"refs/heads/master\"))\n> +\tif (!main_branch)\n> +\t\tmain_branch = git_main_branch_name(MAIN_BRANCH_FULL_NAME);\n> +\n> +\tif (!strcmp(refname, main_branch))\n>   \t\treturn \"refs/heads/ref0\";\n\nThis leaks main_branch if it came from git_main_branch_name()\n\nBest Wishes\n\nPhillip\n\n>   \tstrbuf_reset(&anon);\n> diff --git a/t/t9351-fast-export-anonymize.sh b/t/t9351-fast-export-anonymize.sh\n> index 2415f0ec213..f42be635c2f 100755\n> --- a/t/t9351-fast-export-anonymize.sh\n> +++ b/t/t9351-fast-export-anonymize.sh\n> @@ -31,6 +31,12 @@ test_expect_success 'stream translates master to ref0' '\n>   \t! grep master stream\n>   '\n>   \n> +test_expect_success 'respects configured main branch' '\n> +\tgit -c core.mainBranch=does-not-exist \\\n> +\t\tfast-export --anonymize --all >stream-without-ref0 &&\n> +\t! grep ref0 stream-without-ref0\n> +'\n> +\n>   test_expect_success 'stream omits other refnames' '\n>   \t! grep other stream &&\n>   \t! grep mytag stream\n> \n"},{"id":"399797","messageId":"xmqqr1ugw97e.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"f4d547391537e5c3b0b4a07adb41b6aa56541fc3.1592225416.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-15T17:05:41Z","receivedAt":"2020-06-15T17:05:48Z","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> diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\n> index 72d32bd73b1..43f4f829242 100644\n> --- a/fmt-merge-msg.c\n> +++ b/fmt-merge-msg.c\n> @@ -407,7 +407,7 @@ static void fmt_merge_msg_title(struct strbuf *out,\n>  \t\t\t\tconst char *current_branch)\n>  {\n>  \tint i = 0;\n> -\tchar *sep = \"\";\n> +\tchar *sep = \"\", *main_branch;\n>  \n>  \tstrbuf_addstr(out, \"Merge \");\n>  \tfor (i = 0; i < srcs.nr; i++) {\n> @@ -451,10 +451,12 @@ static void fmt_merge_msg_title(struct strbuf *out,\n>  \t\t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n>  \t}\n>  \n> -\tif (!strcmp(\"master\", current_branch))\n> +\tmain_branch = git_main_branch_name();\n> +\tif (!strcmp(main_branch, current_branch))\n>  \t\tstrbuf_addch(out, '\\n');\n>  \telse\n>  \t\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n> +\tfree(main_branch);\n\nWhile you are at it, taking\n\nhttps://lore.kernel.org/git/20200614211500.GA22505@dcvr/\n\nand the response to it into consideration, I'd suggest we should\nsupport the case where the user says \"no single branch is special\nhere\" by configuring it to an empty string.\n\n> +core.mainBranch::\n> +\tThe name of the main (or: primary) branch in the current repository.\n> +\tFor historical reasons, `master` is used as the fall-back for this\n> +\tsetting.\n\nAs to the naming of the configuration variable and the actual\nfall-back value, I would strongly suggest making them DIFFERNT\n(i.e. separate the concept from an actual value).\n\nAn instruction\n\n    ... oh, if you want to do so, you can set the core.mainBranch\n    configuration variable to 'main'\n\nsounds strange than\n\n    ... oh, if you want to do so, you can set the core.primaryBranch\n    configuration variable to 'main'\n\nat least to me, and since I am OK with your choice of 'main' as the\nreplacement for 'master', a separate word would be more appropriate\nfor the variable name.\n\n"},{"id":"399798","messageId":"xmqqmu54w91n.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"a3be4f39aa240e614a2e12756e1ea864c35137a2.1592225416.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 05/12] fast-export: handle overridden main branch names correctly","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-15T17:09:08Z","receivedAt":"2020-06-15T17:09:17Z","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> +\t * While the main branch name might often be `main` for new\n> +\t * repositories (and `master` for aged ones), and such well-known names\n\nAs I said, if you used a different word for the first 'main' in the\nsentence, it reads much better.\n\n> +\t * may not necessarily need anonymizing, it could be configured to use\n> +\t * a secret word that the user may not want to reveal.\n>  \t */\n> -\tif (!strcmp(refname, \"refs/heads/master\"))\n> +\tif (!main_branch)\n> +\t\tmain_branch = git_main_branch_name(MAIN_BRANCH_FULL_NAME);\n> +\n> +\tif (!strcmp(refname, main_branch))\n>  \t\treturn \"refs/heads/ref0\";\n\nThe same comment as 02/12 applies here.  If the helper function\nreturns \"\" when the user says that no branch is more special than\nothers in the repository, the code would automatically do the right\nthing.\n\nIn any case, thanks for working on it.  I am on \"vacation\" so will\nbe commenting on the rest of the series later in the week.\n\n"},{"id":"399833","messageId":"20200615231049.GE6531@camp.crustytoothpaste.net","threadId":"53651","inReplyTo":"20200615100327.3mwft27oj7h2bixg@yadavpratyush.com","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2020-06-15T23:10:49Z","receivedAt":"2020-06-15T23:10:58Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2020-06-15 at 10:03:27, Pratyush Yadav wrote:\n> For example, my vim plugins are submodules in the '~/.vim/bundle'\n> directory. When I want to update them, I run:\n> \n>   git submodule foreach 'git remote update && git reset --hard origin/master'\n> \n> With this change hitting a Git release, more and more people would call\n> their main branch different names they like. So what is the recommended\n> way to do something like this now? How do I checkout the tip of the main\n> branch? How do I push to the main branch? How do I pull from the main\n> branch? And so on...\n\nThis is a common issue that's long existed but may become more common as\npeople change their branches.  I believe when you clone that it by\ndefault pulls down a HEAD reference for the remote.  So you can use\norigin/HEAD (a symref) in this case to use the correct default branch,\nwhatever it may be called.  Then your code doesn't have to care about\nthe actual name, which is probably better anyway.\n\nIf you want to know the actual name, you can use this: git rev-parse\n--abbrev-ref origin/HEAD.\n\nIf the owner of the repository chooses to change that name or if you\nlack the HEAD reference for a remote, you can fix it with \"git remote\nset-head origin -a\".\n\nI'll see if I can find time this week to work up a FAQ entry about how\nto do this, since it seems to be a common question folks have.  I myself\nwasn't aware of \"git remote set-head\" until the other day, so I don't\nexpect others to be familiar with it, either.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"399837","messageId":"20200616001955.GA686455@generichostname","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006150011360.56@tvgsbejvaqbjf.bet","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-06-16T00:19:55Z","receivedAt":"2020-06-16T00:20:01Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Hi Dscho,\n\nOn Mon, Jun 15, 2020 at 12:26:03AM +0200, Johannes Schindelin wrote:\n> > For example, my vim plugins are submodules in the '~/.vim/bundle'\n> > directory. When I want to update them, I run:\n> >\n> >   git submodule foreach 'git remote update && git reset --hard origin/master'\n> >\n> > With this change hitting a Git release, more and more people would call\n> > their main branch different names they like. So what is the recommended\n> > way to do something like this now? How do I checkout the tip of the main\n> > branch? How do I push to the main branch? How do I pull from the main\n> > branch? And so on...\n> \n> ... has less to do with a new Git release, but more with the decision of\n> an existing project to change their main branch name.\n> \n> That's something users already had to deal with, of course. For example,\n> projects switching to the Git Flow model will start to use the main branch\n> name `development`.\n\nI brought this concern up in a parallel thread but I'll bring it up here\ntoo since it's relevant. Currently, in the .gitmodules file, if the\nbranch is not specified, it defaults to 'master'.\n\nWhen I want to update my vim plugins, I run\n`git submodule update --remote` which pulls in all of my submodules'\n'master' branches. By convention, a lack of `branch` key in .gitmodules\nconventionally means 'master'.\n\nWith your change, it becomes the value of git_main_branch_name(), which\nis fine for now. However, if this value changes to something else, then\nwhen I update my Git, suddenly `git submodule update --remote` will be\nbroken for me as all of the new repositories that I pull will be for an\nincorrect (and possibly missing) branch.\n\nThis leaves us in a scenario where one developer running an older\nversion of Git would have submodule updates work perfectly fine while a\ndeveloper with a newer version would have it suddenly broken. This might\nbe hard to debug, especially for someone who doesn't follow the release\nnotes around Git and doesn't realise why the default has suddenly\nchanged.\n\nThis problem gets much worse if we allow the main branch name to be\nconfigurable as then the *private* configurations that a developer has\nmay have an effect on the *publicly visible* behaviour of a repository.\n\nI think I see three possible solutions to this:\n\n\t1. Special case 'master' in submodules to retain backwards\n\tcompatibility.\n\n\tI don't think this is very appealing as if the change is made to\n\tuse another default branch name, then the \"default\" branch for\n\tsubmodules would be \"master\" even though the new default\n\teverywhere else would be different. And in the future, someone\n\twho doesn't know the context behind all of this would be very\n\tconfused where there are two different default branch names.\n\n\t2. Disable 'update --remote' support for submodules that don't\n\tspecify a branch.\n\n\tIf Git detects that a branch key is missing when trying to do an\n\t'update --remote', it should just quit out and refuse to do\n\tanything. Of course, this a very backwards incompatible change\n\tand it would require several release cycles to implement where\n\twe warn users about this impending change before we actually\n\tmake it happen.\n\n\t3. Make 'update --remote' get HEAD.\n\n\tI argue that this is how it always should've been implemented\n\tbut, alas, I can't go back in time and fix it. Regardless, it\n\tmight be good to flip this to be the default if we're going to\n\tbe making the change anyway.\n\n\tUnfortunately, this suffers from both the problems of 1 and 2.\n\tAs with 1, we'll end up in a situation where users with\n\tdifferent versions of Git may experience different behaviours\n\tgiven the same public repository and I think this is definitely\n\tundesirable. With 2, this change will also require a long\n\tdeprecation period which I don't think it compatible with how\n\tpeople seem to want the default branch switch to happen this\n\trelease.\n\nSo I dunno. I think my opinion leans on not changing the default branch\nat all. Since it seems like the consensus is generally that it _will_\nchange, I think I would prefer options 3, 2 and 1 in that order.\n\nThoughts?\n"},{"id":"399856","messageId":"877dw7csa0.fsf@evledraar.gmail.com","threadId":"53651","inReplyTo":"f4d547391537e5c3b0b4a07adb41b6aa56541fc3.1592225416.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main branch name","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2020-06-16T08:46:15Z","receivedAt":"2020-06-16T08:46:22Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Mon, Jun 15 2020, Johannes Schindelin via GitGitGadget wrote:\n\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\n> +core.mainBranch::\n> +\tThe name of the main (or: primary) branch in the current repository.\n> +\tFor historical reasons, `master` is used as the fall-back for this\n> +\tsetting.\n\nEverywhere else in git-config(1) we just say something to the effect of\nthe more brief:\n\n    The name of the main (or: primary) branch in the current repository\n    (`master` by default).\n\nI think we should do the same here for consistency & ease of reading.\n\nAs you note at the start of this series we're not changing the default\nyet, so referring to the current default as historical is putting the\ncart before the horse as far as producing self-contained patch serieses\ngoes.\n"},{"id":"399860","messageId":"875zbrcpgh.fsf@evledraar.gmail.com","threadId":"53651","inReplyTo":"pull.656.git.1591823971.gitgitgadget@gmail.com","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2020-06-16T09:47:10Z","receivedAt":"2020-06-16T09:47:16Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Wed, Jun 10 2020, Johannes Schindelin via GitGitGadget wrote:\n\n> This series DOES NOT change the default automatically, but only provides an\n> opt-in mechanism for interested users. It also presents a way forward for\n> such a transition, if and when we decide to do so. Specifically, the new\n> GIT_TEST_DEFAULT_BRANCH_NAME environment variable could be used to update\n> test scripts on an individual basis instead of all-at-once.\n\nI don't have much time for review today, but hopefully these comments\nare useful. These comments are on the series as a whole[1] mainly to\nsave myself time in chasing down individual patches, and I think it's\nmore useful as one E-Mail, hopefully.\n\nI think this change is going in a good technical direction. I'm just\ncommenting on the \"how it would be done\" aspect, I'm not going to add\nanother voice to the larger \"is this a useful endeavor?\" discussion\nvis-a-vis what the larger goal is.\n\nBut I do have purely technical concerns about where this is going.\n\nThe part where we just make it easier to do what you could do all along\nwith sed(1) or whatever to rename the branch after \"git init\" is\nobviously correct (or close enough). That part's easy enough.\n\nThe parts I'm concerned about is the behavior of how we make the branch\nname persistent, which is new \"while we're at it\" behavior in git\nunrelated to the convenience of allowing a configuration of the main\nbranch name without \"git init --template\" or after the fact sed(1)\nmunging.\n\nSpecifically:\n\n 1. The special case in fmt-merge-msg we always had for \"master\" sucked\n    in terms of producing more verbose merge messages for those of us\n    who had repos where the main branch wasn't \"master\", but at least it\n    was consistent.\n\n    Now we've created a situation where a user's local config impacts\n    what we put in the machine-generated commit messages.\n\n    Now, these messages were never \"plumbing\", and other users could use\n    different git frontends than \"core git\" etc, but it's a really\n    useful property we've tried to maintain that a user's local\n    configuration doesn't change what we put in these messages. It's why\n    we've left them out of the i18n mechanism.\n\n 2. The whole core.mainBranch thing rubs me the wrong way. So now if we\n    rename a branch we munge it, but if you've got an older git version\n    or whatever you get different results and the config isn't carried\n    forward.\n\n    I'd *really* like to avoid having what's essentially a refstore\n    side-value if we can.\n\n 3. Whatever we do with the submodule guess-a-name functionality, I\n    think it's the wrong path to make it proceed in lockstep with\n    MAIN_BRANCH_FOR_INIT.\n\n    When you decide to change your branch names != when the rest of the\n    world does it.\n\n    Also, whatever the suckyness of the current hardcoded \"master\"\n    behavior I think it sucks more than different users on the same\n    version can fail or succeed to clone a repository depending on a\n    config they set for \"what branch names do I want on new repos?\".\n\n    This is simlar to #1, in that I'd much rather have behavior that\n    consistently sucks than one that interacts with the wider world\n    (writing commits, cloning random other repos) that differs because\n    of my *local* config preferences.\n\n 4. For fast-export I think we should just drop this entire \"master\"\n    special case instead of making it read the config. That's also in\n    line with its documentation. Let's just call it ref0.\n\n    Either that or just hardcode whatever passes for the \"main\" branch\n    name, but anything but making the to-be-shared anonymized output\n    continue to leak local config, similar to #1 and #3 above.\n\nIn summary, I'd like this series much better if we split off the\nconvenience change for \"init\" from the improved heuristics/guesses for\nremote \"master\". Just my 0.02.\n\n1. git diff --stat -p @{u}...pr-656/dscho/default-branch-name-option-v2\n"},{"id":"399867","messageId":"20200616122559.GA666057@coredump.intra.peff.net","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006141055510.56@tvgsbejvaqbjf.bet","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-16T12:25:59Z","receivedAt":"2020-06-16T12:26:02Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Jun 14, 2020 at 10:57:41AM +0200, Johannes Schindelin wrote:\n\n> > >> Why adding yet another environment variable instead of relying only on a\n> > >> config option?  I understand it's for the tests, but can't we add a\n> > >> shell function in test-lib.sh (and friends) that tries to read\n> > >> `GIT_TEST_DEFAULT_BRANCH_NAME', and, if it exists, sets\n> > >> `core.defaultBranchName'?\n> > >\n> > > Can you produce such a patch that does it cleanly?  My knee jerk\n> > > reaction is that I would suspect that you end up having to touch\n> > > many places in the t/ scripts, but if you prove otherwise, that\n> > > would certainly be appreciated.\n> > >\n> > > And no,\n> > >\n> > >     git () { command git -c core.defaultBranchName=master \"$@\" }\n> > >\n> > > is not an acceptable solution.\n> > >\n> >\n> > I wanted to to do something like this:\n> >\n> >   if test -n \"$GIT_TEST_DEFAULT_BRANCH_NAME\";\n> >   then\n> >       git config core.defaultBranchName \"$GIT_TEST_DEFAULT_BRANCH_NAME\"\n> >   fi\n> >\n> > But since we do not have a repository to store the config, it won't\n> > work.  Sorry for the noise.\n> \n> We actually would have `~/.gitconfig` because `HOME` is set to `t/trash\n> directory.<test-name>/`.\n> \n> However, that would cause all kinds of issues when test scripts expect the\n> directory to be pristine, containing only `.git/` but not `.gitconfig`.\n\nPutting:\n\n  GIT_CONFIG_PARAMETERS=\"'core.defaultBranchName=...'\"\n\ninto the environment would work (and yes, you need the single quotes\nembedded in the variable), and solves all of the complaints above.\nFurther \"git -c\" invocations properly append to it. But:\n\n  - there are a few tests which explicitly tweak that variable\n\n  - it technically changes any tests of \"-c\" because now we'd never\n    cover the case where we start without the variable defined\n\nI think baking in a special environment variable like you have is not so\nbad. If this did become too common a pattern, though (special test-only\nenvironment variables that do have a separate config option), I wouldn't\nbe opposed to a GIT_TEST_CONFIG_PARAMETERS which takes precedence over\nother config, and comes with a big warning label that it shouldn't be\nrelied upon outside the test suite. That's equally ugly to\nGIT_TEST_DEFAULT_BRANCH_NAME, but at least solves the problem once for\nall of them. I'm just not sure we have enough \"all of them\" to make it\nworth doing.\n\n-Peff\n"},{"id":"399868","messageId":"20200616123559.GB666057@coredump.intra.peff.net","threadId":"53651","inReplyTo":"06a2cea051c01ebee38c9910425171f112daf41a.1591823971.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 2/9] remote: respect `core.defaultBranchName`","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-16T12:35:59Z","receivedAt":"2020-06-16T12:36:01Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jun 10, 2020 at 09:19:23PM +0000, Johannes Schindelin via GitGitGadget wrote:\n\n> @@ -2099,7 +2100,10 @@ struct ref *guess_remote_head(const struct ref *head,\n>  \n>  \t/* If refs/heads/master could be right, it is. */\n>  \tif (!all) {\n> -\t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n> +\t\tchar *name = git_default_branch_name(0);\n> +\n> +\t\tr = find_ref_by_name(refs, name);\n> +\t\tfree(name);\n>  \t\tif (r && oideq(&r->old_oid, &head->old_oid))\n>  \t\t\treturn copy_ref(r);\n>  \t}\n\nYou'd perhaps want to update the comment above, too.\n\nHowever, I think we should be a bit more lenient on the \"reading\" side\ndefault names. Just because \"foo\" is _my_ default branch name, does not\nmean it is the default on the remote side. We cannot know what the other\nside's default preference is, but in a world where we have 15 years of\nrepos that may have been created with \"master\", it is probably still a\ngood guess.\n\nI.e., I think this probably ought to check the preferred name, and then\nfall back to the existing behavior, like:\n\n  if (!all) {\n\t  char *name;\n\n          /* try the user's preferred default branch name */\n\t  name = git_default_branch_name(0);\n\t  r = find_ref_by_name(refs, name);\n\t  free(name);\n\t  if (r && oideq(&r->old_oid, &head->old_oid))\n\t          return copy_ref(r);\n\n\t  /* otherwise, try \"master\", which is the historical default */\n\t  r = find_ref_by_name(refs, \"refs/heads/master\");\n\t  if (r && oideq(&r->old_oid, &head->old_oid))\n\t          return copy_ref(r);\n  }\n\nThat will help minimize fallout when git_default_branch_name() changes,\neither by user config or if we switch the baked-in default. In the\nlatter case, we might also consider hard-coding that as a guess between\nthe user's preferred name and the historical \"master\".\n\nHopefully this would not matter _too_ much either way, as most servers\nwould support the symref extension these days. But I still think we\nshould do our best to minimize spots where the user may see a\nregression.\n\n-Peff\n"},{"id":"399869","messageId":"20200616124502.GC666057@coredump.intra.peff.net","threadId":"53651","inReplyTo":"CAPig+cSnEvVB5vsffFXidG1-XNxDX10u2XhD9NqV3pwh8zyxxw@mail.gmail.com","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-16T12:45:02Z","receivedAt":"2020-06-16T12:45:05Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jun 10, 2020 at 08:16:38PM -0400, Eric Sunshine wrote:\n\n> > +/*\n> > + * Retrieves the name of the default branch. If `short_name` is non-zero, the\n> > + * branch name will be prefixed with \"refs/heads/\".\n> > + */\n> > +char *git_default_branch_name(int short_name);\n> \n> Overall, the internal logic regarding duplicating/freeing strings\n> would probably be easier to grok if there were two separate functions:\n> \n>     char *git_default_branch_name(void);\n>     char *git_default_ref_name(void);\n> \n> but that's subjective.\n\nHaving seen one of the callers, might it be worth avoiding handing off\nownership of the string entirely?\n\nI.e., this comes from a string that's already owned for the lifetime of\nthe process (either the environment, or a string stored by the config\nmachinery). Could we just pass that back (or if we want to be more\ncareful about getenv() lifetimes, we can copy it into a static owned by\nthis function)?\n\nThen all of the callers can stop dealing with the extra free(), and you\ncan do:\n\n  const char *git_default_branch_name(void)\n  {\n\treturn skip_prefix(\"refs/heads/\", git_default_ref_name());\n  }\n\n-Peff\n"},{"id":"399870","messageId":"20200616124739.GD666057@coredump.intra.peff.net","threadId":"53651","inReplyTo":"20200616124502.GC666057@coredump.intra.peff.net","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-16T12:47:39Z","receivedAt":"2020-06-16T12:47:42Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jun 16, 2020 at 08:45:02AM -0400, Jeff King wrote:\n\n> On Wed, Jun 10, 2020 at 08:16:38PM -0400, Eric Sunshine wrote:\n> \n> > > +/*\n> > > + * Retrieves the name of the default branch. If `short_name` is non-zero, the\n> > > + * branch name will be prefixed with \"refs/heads/\".\n> > > + */\n> > > +char *git_default_branch_name(int short_name);\n> > \n> > Overall, the internal logic regarding duplicating/freeing strings\n> > would probably be easier to grok if there were two separate functions:\n> > \n> >     char *git_default_branch_name(void);\n> >     char *git_default_ref_name(void);\n> > \n> > but that's subjective.\n> \n> Having seen one of the callers, might it be worth avoiding handing off\n> ownership of the string entirely?\n> \n> I.e., this comes from a string that's already owned for the lifetime of\n> the process (either the environment, or a string stored by the config\n> machinery). Could we just pass that back (or if we want to be more\n> careful about getenv() lifetimes, we can copy it into a static owned by\n> this function)?\n> \n> Then all of the callers can stop dealing with the extra free(), and you\n> can do:\n> \n>   const char *git_default_branch_name(void)\n>   {\n> \treturn skip_prefix(\"refs/heads/\", git_default_ref_name());\n>   }\n\nActually, one small hiccup is that the config option specifies the\nbranch name, not the ref name. So you really would have to prepare a\nstatic-owned copy of it to turn \"foo\" into \"refs/heads/foo\" to get the\nrefname.\n\nOn the other hand, that would also be a good time to run\ncheck_ref_format(). In the patch as-is, the \"short\" return does not\ncheck that the branch is a valid name.\n\n-Peff\n"},{"id":"399872","messageId":"20200616125833.GE666057@coredump.intra.peff.net","threadId":"53651","inReplyTo":"ebd10f73cd73a8fca84d1862e5a4b7b62a549bcd.1592225416.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 01/12] fast-export: do anonymize the primary branch name","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-16T12:58:33Z","receivedAt":"2020-06-16T12:58:37Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jun 15, 2020 at 12:50:05PM +0000, Junio C Hamano via GitGitGadget wrote:\n\n> There is a comment that explains why it is OK to leave 'master'\n> unanonymized (because everybody calls the primary branch 'master'\n> and it is no secret), but that does not justify why it is bad to\n> anonymize 'master' and make it indistinguishable from other\n> branches.  Assuming there _is_ a need to allow the readers of the\n> output to tell where the tip of the primary branch is, let's keep\n> the special casing of 'master', but still anonymize it to \"ref0\".\n> Because all other branches will be given ref+N where N is a positive\n> integer, this will keep the primary branch identifiable in the\n> output stream, without exposing what the name of the primary branch\n> is in the repository the export stream was taken from.\n\nI think this is fine. The reason I left \"master\" as-is in the original\nis that it is potentially helpful to have an idea of its specialness\nwhen reproducing a traversal in the anonymized. I.e., if you know that a\nbug is shown by \"git rev-list master~17..master~3\", then you can\nreproduce it with the same command in the anonymized repo. Losing any\nidea of where the primary branch is would make that impossible. But with\nthis patch, you can swap it out for \"ref0~17\", etc, which is OK.\n\nOf course that only helps you for _one_ branch. A more generally useful\nmechanism would be to teach fast-export to write the ref mapping (and\nperhaps file mappings, etc) to a separate file. Then you could convert\nany reproduction recipe to use the anonymized names, and share only that\nrecipe along with the anonymized dump. But that's _way_ outside the\nscope of your series. This seems like a good interim step to retain the\nstatus quo.\n\n-Peff\n"},{"id":"399873","messageId":"20200616130456.GF666057@coredump.intra.peff.net","threadId":"53651","inReplyTo":"f4d547391537e5c3b0b4a07adb41b6aa56541fc3.1592225416.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main branch name","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-16T13:04:56Z","receivedAt":"2020-06-16T13:04:59Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jun 15, 2020 at 12:50:06PM +0000, Johannes Schindelin via GitGitGadget wrote:\n\n> +char *repo_main_branch_name(struct repository *r)\n> +{\n> +\tconst char *config_key = \"core.mainbranch\";\n> +\tconst char *config_display_key = \"core.mainBranch\";\n> +\tconst char *fall_back = \"master\";\n> +\tchar *name = NULL, *ret;\n> +\n> +\tif (repo_config_get_string(r, config_key, &name) < 0)\n> +\t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n> +\n> +\tret = name ? name : xstrdup(fall_back);\n> +\n> +\tif (check_refname_format(ret, REFNAME_ALLOW_ONELEVEL))\n> +\t\tdie(_(\"invalid branch name: %s = %s\"),\n> +\t\t    config_display_key, name);\n\nAh, this fixes the \"we do not check the format of the short name\" issue\nI pointed out in v1 (sorry, I just realized that v2 existed so I'll\nresume reviewing from there; I do still think this might make life\neasier for callers by returning a const pointer).\n\nI'm not sure if this check_refname_format() is valid, though. IIRC we've\nhad issues where \"ONELEVEL\" was used to check a branch name, but misses\nsome cases. The more full check done by strbuf_check_branch_ref()\nactually creates the full refname and checks that. It also catches stuff\nlike refs/heads/HEAD.\n\nI doubt that it matters too much for us to be completely thorough here\n(unlike some other spots, we are not enforcing rules against potentially\nmalicious names, but rather just helping the user realize early that\ntheir config is bogus). So I'm not sure how careful we want to be.\n\n-Peff\n"},{"id":"399874","messageId":"20200616131039.GG666057@coredump.intra.peff.net","threadId":"53651","inReplyTo":"a0982afb-8c44-aeff-1839-6e0aa897fcf2@gmail.com","subject":"Re: [PATCH v2 05/12] fast-export: handle overridden main branch names correctly","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-16T13:10:39Z","receivedAt":"2020-06-16T13:10:42Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jun 15, 2020 at 04:05:52PM +0100, Phillip Wood wrote:\n\n> > @@ -515,14 +515,23 @@ static const char *anonymize_refname(const char *refname)\n> >   \t};\n> >   \tstatic struct hashmap refs;\n> >   \tstatic struct strbuf anon = STRBUF_INIT;\n> > +\tstatic char *main_branch;\n> [...]\n> > -\tif (!strcmp(refname, \"refs/heads/master\"))\n> > +\tif (!main_branch)\n> > +\t\tmain_branch = git_main_branch_name(MAIN_BRANCH_FULL_NAME);\n> > +\n> > +\tif (!strcmp(refname, main_branch))\n> >   \t\treturn \"refs/heads/ref0\";\n> \n> This leaks main_branch if it came from git_main_branch_name()\n\nIt's a static that's used over and over, so I think it's intentional to\nessentially memoize it for the life of the program (at which point we\ncould free it, but don't bother to do so, letting the process exit take\ncare of it, and trusting in leak detectors to be aware that it's still\nreachable, as we do for lots of other process-lifetime allocations).\n\n-Peff\n"},{"id":"399876","messageId":"20200616132216.GH666057@coredump.intra.peff.net","threadId":"53651","inReplyTo":"0e59b6181699abe17eb46fe3ca5a48ce71889780.1592225416.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 09/12] clone: handle overridden main branch names","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-16T13:22:16Z","receivedAt":"2020-06-16T13:22:21Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jun 15, 2020 at 12:50:13PM +0000, Johannes Schindelin via GitGitGadget wrote:\n\n> diff --git a/builtin/clone.c b/builtin/clone.c\n> index 487b0a42d75..755fcaeb0ba 100644\n> --- a/builtin/clone.c\n> +++ b/builtin/clone.c\n> @@ -718,6 +718,7 @@ static void update_head(const struct ref *our, const struct ref *remote,\n>  \t\t/* Local default branch link */\n>  \t\tif (create_symref(\"HEAD\", our->name, NULL) < 0)\n>  \t\t\tdie(_(\"unable to update HEAD\"));\n> +\t\tgit_config_set(\"core.mainbranch\", head);\n>  \t\tif (!option_bare) {\n>  \t\t\tupdate_ref(msg, \"HEAD\", &our->old_oid, NULL, 0,\n>  \t\t\t\t   UPDATE_REFS_DIE_ON_ERR);\n\nJust making sure I understand what's going on here...\n\nThis covers the case that we've run \"clone -b foo\" or similar, but there\nare two other case arms when \"foo\" is a tag, or the remote HEAD is\nunreachable. And there we don't set core.mainbranch at all.\n\nBut we would not want it to be missing, because that will likely need to\nstay a default for \"master\" indefinitely (to keep behavior for existing\nrepositories). However, it won't be missing. We'll always have set it\nduring the init_db() call, and this is just overriding that. So we'd end\nupdate_head() with either:\n\n  - core.mainbranch set to the same branch we point HEAD to, whether we\n    got it from the remote side or from \"-b foo\"\n\n  - if we write a detached HEAD, then core.mainbranch remains at\n    init.mainbranch (or defaulting to \"master\" now, and probably \"main\"\n    later). We have no better option.\n\nIf so, then that makes sense to me.\n\n-Peff\n"},{"id":"399878","messageId":"20200616134618.GI666057@coredump.intra.peff.net","threadId":"53651","inReplyTo":"59d6267f099f30f830836a2422289bc83f5c35e5.1592225416.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 11/12] submodule: use the correct default for the main branch name","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-16T13:46:18Z","receivedAt":"2020-06-16T13:46:21Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jun 15, 2020 at 12:50:15PM +0000, Johannes Schindelin via GitGitGadget wrote:\n\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> \n> To allow for overriding the default branch name, we have introduced a\n> config setting. With this patch, the `git submodule` command learns\n> about this, too.\n\nThis was the other reading case (besides guess_remote_head()) that I'm\nmost concerned with causing regressions in a world where some repos are\non \"master\" and some are on \"main\".\n\nThis value ends up as the output of \"submodule--helper remote-branch\".\n\nI was initially worried that we used this branch name for the fallback\nwhen the server doesn't allow us to fetch the sha1 directly, but it\ndoesn't look like it. That's good, because handling fallbacks there\nwould be tricky.\n\nInstead, we seem to use this only after fetching all of the refs for a\nsubmodule:\n\n  $ git grep -h -B2 -A11 remote-branch git-submodule.sh\n  \t\tif test -n \"$remote\"\n  \t\tthen\n  \t\t\tbranch=$(git submodule--helper remote-branch \"$sm_path\")\n  \t\t\tif test -z \"$nofetch\"\n  \t\t\tthen\n  \t\t\t\t# Fetch remote before determining tracking $sha1\n  \t\t\t\tfetch_in_submodule \"$sm_path\" $depth ||\n  \t\t\t\tdie \"$(eval_gettext \"Unable to fetch in submodule path '\\$sm_path'\")\"\n  \t\t\tfi\n  \t\t\tremote_name=$(sanitize_submodule_env; cd \"$sm_path\" && get_default_remote)\n  \t\t\tsha1=$(sanitize_submodule_env; cd \"$sm_path\" &&\n  \t\t\t\tgit rev-parse --verify \"${remote_name}/${branch}\") ||\n  \t\t\tdie \"$(eval_gettext \"Unable to find current \\${remote_name}/\\${branch} revision in submodule path '\\$sm_path'\")\"\n  \t\tfi\n\nand then we just use that branch name to resolve a sha1. So this will\nbreak cases where you've set init.mainBranch, the submodule repo is\nstill on \"master\", and you haven't configured a branch in .gitmodules.\n\nIt seems like, independent of any change in the default branch names, we\nought to be using $remote_name/HEAD for this case anyway. I suspect that\nwould be a behavior improvement by itself, as it means more cases could\navoid having to specify the branch name in .gitmodules manually.\nProbably nobody noticed so far because \"HEAD\" is almost always \"master\"\nin the current world. It technically breaks the case that you truly did\nwant to use \"master\" in the submodule, but they set HEAD to something\nelse, and you couldn't be bothered to put it into your .gitmodules file.\nThat seems rather unlikely to me.\n\nAnd then everything would Just Work without having to worry about the\nlocal mainbranch value at all.\n\nAlternatively, submodule--helper could pass back the empty string for\n\"no, we don't have a configured branch name\" and this shell code could\nactually try a sequence of reasonable guesses: init.mainbranch, then\n\"master\" (and between the two, \"main\" if that later becomes the\ndefault).\n\n-Peff\n"},{"id":"399879","messageId":"20200616135121.GJ666057@coredump.intra.peff.net","threadId":"53651","inReplyTo":"e09f857f06857fedc46b91bc918486f34dde8b02.1592225416.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 12/12] testsvn: respect `init.defaultBranch`","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-16T13:51:21Z","receivedAt":"2020-06-16T13:51:27Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jun 15, 2020 at 12:50:16PM +0000, Johannes Schindelin via GitGitGadget wrote:\n\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> \n> The default name of the main branch in new repositories can now be\n> configured. The `testsvn` remote helper translates the remote Subversion\n> repository's branch name `trunk` to the hard-coded name `master`.\n> Clearly, the intention was to make the name align with Git's detaults.\n\ns/detaults/defaults/ :)\n\nI'd agree that moving this to Git's default name makes sense.\n\nThough my overall preference is still to delete this whole testsvn thing\nentirely (I have some other pending tree-wide changes that are being\nheld up by it, too). After getting \"would you mind holding off until...\"\nfrom Jonathan in [1], I've been waiting almost 2 years. Maybe now is the\ntime?\n\n-Peff\n\n[1] https://lore.kernel.org/git/20180818052605.GA241538@aiede.svl.corp.google.com/\n"},{"id":"399881","messageId":"20200616140932.GK666057@coredump.intra.peff.net","threadId":"53651","inReplyTo":"875zbrcpgh.fsf@evledraar.gmail.com","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-16T14:09:32Z","receivedAt":"2020-06-16T14:09:35Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jun 16, 2020 at 11:47:10AM +0200, Ævar Arnfjörð Bjarmason wrote:\n\n> But I do have purely technical concerns about where this is going.\n> \n> The part where we just make it easier to do what you could do all along\n> with sed(1) or whatever to rename the branch after \"git init\" is\n> obviously correct (or close enough). That part's easy enough.\n> \n> The parts I'm concerned about is the behavior of how we make the branch\n> name persistent, which is new \"while we're at it\" behavior in git\n> unrelated to the convenience of allowing a configuration of the main\n> branch name without \"git init --template\" or after the fact sed(1)\n> munging.\n\nI've read the whole thing and left some specific comments, but your\nthinking more or less matches mine, with a few notes below.\n\n> Specifically:\n> \n>  1. The special case in fmt-merge-msg we always had for \"master\" sucked\n>     in terms of producing more verbose merge messages for those of us\n>     who had repos where the main branch wasn't \"master\", but at least it\n>     was consistent.\n> \n>     Now we've created a situation where a user's local config impacts\n>     what we put in the machine-generated commit messages.\n> \n>     Now, these messages were never \"plumbing\", and other users could use\n>     different git frontends than \"core git\" etc, but it's a really\n>     useful property we've tried to maintain that a user's local\n>     configuration doesn't change what we put in these messages. It's why\n>     we've left them out of the i18n mechanism.\n\nI'm actually tempted to say that \"master\" should stop being special.\nIt's a little nice, I guess, if merges back to the main branch are a\nlittle more terse in their message. But I actually think consistently\nsaying:\n\n  Merge branch 'jk/foo' into main\n\n_even if it's the main branch_ is actually pretty sane. It conveys more\ninformation about what happened that could be useful later, and I don't\nthink it makes the result less readable.\n\n>  2. The whole core.mainBranch thing rubs me the wrong way. So now if we\n>     rename a branch we munge it, but if you've got an older git version\n>     or whatever you get different results and the config isn't carried\n>     forward.\n> \n>     I'd *really* like to avoid having what's essentially a refstore\n>     side-value if we can.\n\nI think it's necessary if we're going to have parts of the code that say\n\"this is the special branch in this repo\". Because we must leave the\nunconfigured state as \"master is the special branch\" in order to avoid\nregressing existing repositories. It _could_ be a flag that says \"I was\nconfigured using init.mainBranch, so use that value\". But I don't think\nthat solves your fundamental concerns.\n\nHowever, I wonder if we can get away with saying \"there is no special\nbranch\" entirely. The things that care about the special branch are:\n\n - guessing HEAD; but this is guessing what the _remote_ side wants\n   anyway, so it really has nothing to do with your local\n   core.mainBranch (plus that guess shouldn't even be used much with\n   modern git anyway).\n\n - the default branch for submodules; this is basically the same boat,\n   and really ought to just be using the remote HEAD anyway.\n\n - slightly shorter merge messages. See above.\n\n - various \"perhaps you should specify a branch such as master\"\n   messages. These could be reworded to avoid mentioning a specific\n   branch, or could pick a real branch name.\n\n - fast-export anonymization. We could probably use HEAD as \"ref0\"\n   instead (or do the output-map thing I mentioned, which is a much\n   better solution anyway).\n\nI think with that, we could ditch core.mainBranch entirely, with no\nnotion at all of \"this branch is special in this repo\". We use HEAD\nwhere appropriate, and otherwise avoid any specialness.\n\n>  3. Whatever we do with the submodule guess-a-name functionality, I\n>     think it's the wrong path to make it proceed in lockstep with\n>     MAIN_BRANCH_FOR_INIT.\n> \n>     When you decide to change your branch names != when the rest of the\n>     world does it.\n\nYeah, this was my main concern for the whole series: what will break in\na world of mixed main-branch names. Thankfully very little, it seems.\nBut as much as possible we should be not just choosing our preferred\nvalue, but trying to match possible states. I think teaching the\nHEAD-guessing to try a few names, plus using HEAD for submodules, will\npretty much do it (see my replies to individual patches for more\ndetails).\n\n-Peff\n"},{"id":"399884","messageId":"20200616142423.GA667151@coredump.intra.peff.net","threadId":"53651","inReplyTo":"20200616140932.GK666057@coredump.intra.peff.net","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-16T14:24:23Z","receivedAt":"2020-06-16T14:24:25Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jun 16, 2020 at 10:09:32AM -0400, Jeff King wrote:\n\n> I think with that, we could ditch core.mainBranch entirely, with no\n> notion at all of \"this branch is special in this repo\". We use HEAD\n> where appropriate, and otherwise avoid any specialness.\n\nOne obvious exception is that third-party tools may want to know the\n\"special\" branch for some reason. But I'm inclined to say that they\nshould (in this order):\n\n  - consider whether they really need a special branch at all, or if the\n    mechanism can be made more generic\n\n  - consider whether HEAD is the best value for a special branch (e.g.,\n    GitHub pull requests default to targeting HEAD)\n\n  - rely on per-tool config for what's special (because it really may\n    vary between tools, and that's more flexible anyway)\n\nBut I'm open to hearing about cases where some tool really wants to know\n\"what did the user consider the special branch at the time of creation\".\n\n-Peff\n"},{"id":"399897","messageId":"8c65ab94-3b38-f8fc-c969-2d5eeff91ef1@gmail.com","threadId":"53651","inReplyTo":"20200616131039.GG666057@coredump.intra.peff.net","subject":"Re: [PATCH v2 05/12] fast-export: handle overridden main branch names correctly","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2020-06-16T15:49:33Z","receivedAt":"2020-06-16T16:04:33Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Peff\n\nOn 16/06/2020 14:10, Jeff King wrote:\n> On Mon, Jun 15, 2020 at 04:05:52PM +0100, Phillip Wood wrote:\n> \n>>> @@ -515,14 +515,23 @@ static const char *anonymize_refname(const char *refname)\n>>>    \t};\n>>>    \tstatic struct hashmap refs;\n>>>    \tstatic struct strbuf anon = STRBUF_INIT;\n>>> +\tstatic char *main_branch;\n>> [...]\n>>> -\tif (!strcmp(refname, \"refs/heads/master\"))\n>>> +\tif (!main_branch)\n>>> +\t\tmain_branch = git_main_branch_name(MAIN_BRANCH_FULL_NAME);\n>>> +\n>>> +\tif (!strcmp(refname, main_branch))\n>>>    \t\treturn \"refs/heads/ref0\";\n>>\n>> This leaks main_branch if it came from git_main_branch_name()\n> \n> It's a static that's used over and over, so I think it's intentional to\n> essentially memoize it for the life of the program \n\nOh you're right, I completely misread the patch\n\nThanks\n\nPhillip\n\n> (at which point we\n> could free it, but don't bother to do so, letting the process exit take\n> care of it, and trusting in leak detectors to be aware that it's still\n> reachable, as we do for lots of other process-lifetime allocations).\n> \n> -Peff\n> \n"},{"id":"399986","messageId":"xmqqmu51v9qy.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"20200616125833.GE666057@coredump.intra.peff.net","subject":"Re: [PATCH v2 01/12] fast-export: do anonymize the primary branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-17T18:16:05Z","receivedAt":"2020-06-17T18:16:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Of course that only helps you for _one_ branch. A more generally useful\n> mechanism would be to teach fast-export to write the ref mapping (and\n> perhaps file mappings, etc) to a separate file. Then you could convert\n> any reproduction recipe to use the anonymized names, and share only that\n> recipe along with the anonymized dump. But that's _way_ outside the\n> scope of your series. This seems like a good interim step to retain the\n> status quo.\n\nActually, dropping this special case, and dropping the other special\ncase with fmt-merge-msg, we can do without the notion of the\n\"primary\" branch.\n\nWe still need to have the default name, when user does not specify\none, given to the first branch \"git init\" creates and \"git clone\"\nthat cannot figure out what the HEAD at the origin points at uses,\nbut one less thing to worry about is always better ;-)\n"},{"id":"399987","messageId":"xmqqimfpv9io.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"877dw7csa0.fsf@evledraar.gmail.com","subject":"Re: [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-17T18:21:03Z","receivedAt":"2020-06-17T18:21:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n\n> On Mon, Jun 15 2020, Johannes Schindelin via GitGitGadget wrote:\n>\n>> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n>\n>> +core.mainBranch::\n>> +\tThe name of the main (or: primary) branch in the current repository.\n>> +\tFor historical reasons, `master` is used as the fall-back for this\n>> +\tsetting.\n>\n> Everywhere else in git-config(1) we just say something to the effect of\n> the more brief:\n>\n>     The name of the main (or: primary) branch in the current repository\n>     (`master` by default).\n>\n> I think we should do the same here for consistency & ease of reading.\n>\n> As you note at the start of this series we're not changing the default\n> yet, so referring to the current default as historical is putting the\n> cart before the horse as far as producing self-contained patch serieses\n> goes.\n\nVery good point.  \n\nIn [*1*], I gave a potential outline of how a transition plan might\nlook like (if we were to transition, that is), but what is written\nas step 1. in there should be split into two: step 0, in which the\nmechanisms (1) to change the default name used for the first branch\nand (2) to specify the primary branch that is special-cased by a few\ncommands are introduced, without any future plan, and step 1, in\nwhich warning and/or advice messages knudge the users and hint the\nfuture direction.\n\nThanks.\n\n\n[Reference]\n\n*1* https://lore.kernel.org/git/xmqqeeqiztpq.fsf@gitster.c.googlers.com\n"},{"id":"399988","messageId":"xmqqeeqdv9e8.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"20200616130456.GF666057@coredump.intra.peff.net","subject":"Re: [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-17T18:23:43Z","receivedAt":"2020-06-17T18:23:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> I'm not sure if this check_refname_format() is valid, though. IIRC we've\n> had issues where \"ONELEVEL\" was used to check a branch name, but misses\n> some cases. The more full check done by strbuf_check_branch_ref()\n> actually creates the full refname and checks that. It also catches stuff\n> like refs/heads/HEAD.\n\nYup.\n\nI actually am in favor of removing special casing of a single branch\ndone by fmt-merge-msg and fast-export --anonymize, so this may not\nmatter.\n\nWe still need a mechanism to allow users specify the default name to\nbe given to the first branch \"git init\" creates and used by \"git clone\"\nas a fallback name when it cannot infer what the other side uses, though.\n"},{"id":"399994","messageId":"xmqqtuz9tq30.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006141053170.56@tvgsbejvaqbjf.bet","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-17T20:06:11Z","receivedAt":"2020-06-17T20:06:19Z","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> Yes, the trouble with `maint` did cross my mind, but I try not to\n> \"overfit\" to git/git. :-)\n\nI do not think it is overfitting; if the solution cannot even\nsupport the originating project well, there is something wrong.\n\nMost likely, I'd be tempted to rename it myself away from any name\nthat is too similar to 'maint'; perhaps to 'stable' (or 'devo', h/t\ntla ;-).\n\n"},{"id":"399999","messageId":"xmqqd05xtp2g.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"875zbrcpgh.fsf@evledraar.gmail.com","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-17T20:28:07Z","receivedAt":"2020-06-17T20:28:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n\n>  1. The special case in fmt-merge-msg we always had for \"master\" sucked\n>     in terms of producing more verbose merge messages for those of us\n>     who had repos where the main branch wasn't \"master\", but at least it\n>     was consistent.\n>\n>     Now we've created a situation where a user's local config impacts\n>     what we put in the machine-generated commit messages.\n>\n>     Now, these messages were never \"plumbing\", and other users could use\n>     different git frontends than \"core git\" etc, but it's a really\n>     useful property we've tried to maintain that a user's local\n>     configuration doesn't change what we put in these messages. It's why\n>     we've left them out of the i18n mechanism.\n\nI doubt the last sentence reflects the reality.  As the person who\ninvented the fmt-merge-msg's mechanism (including it special casing\nof 'master'), I know that it was the sentence lego that made it\nimpossible to localize and left the code pretty much intact since\nthe days it was introduced.\n\nHaving said that, I am personally inclined to vote for getting rid\nof the special casing of any branch by \"git fmt-merge-msg\" and \"git\nfast-export --anonymize\".  We still need a mechanism to let users\nconfigure the word used by \"git init\" to give the first branch it\ncreates as its name, but that is merely the first branch created in\nthe repository and does not have to be the primary.\n\n>  2. The whole core.mainBranch thing rubs me the wrong way. So now if we\n>     rename a branch we munge it, but if you've got an older git version\n>     or whatever you get different results and the config isn't carried\n>     forward.\n\nAnd we can get rid of this worry at the same time by doing so.\n\n"},{"id":"400005","messageId":"1612660e-aa49-5d7f-d47e-34740e330eaa@kdbg.org","threadId":"53651","inReplyTo":"f4d547391537e5c3b0b4a07adb41b6aa56541fc3.1592225416.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main branch name","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2020-06-17T20:56:18Z","receivedAt":"2020-06-17T20:56:24Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 15.06.20 um 14:50 schrieb Johannes Schindelin via GitGitGadget:\n> @@ -451,10 +451,12 @@ static void fmt_merge_msg_title(struct strbuf *out,\n>  \t\t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n>  \t}\n>  \n> -\tif (!strcmp(\"master\", current_branch))\n> +\tmain_branch = git_main_branch_name();\n> +\tif (!strcmp(main_branch, current_branch))\n>  \t\tstrbuf_addch(out, '\\n');\n>  \telse\n>  \t\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n> +\tfree(main_branch);\n>  }\n\nNow that the removal of this special case is on the plate, I would\nprefer that the phrase \"into foo\" is never appended instead of always\nappended.\n\nFor me, it was a always more of a hindrance than a help. The story goes\nlike this: A branch that I'm working on was named \"edit-box-fix\"\nyesterday, but today it was renamed to \"layout-fix\" because the scope\nchanged. I had merged a topic \"rename-buttons\" yesterday, and now I have\nto go back and rename that \"into edit-box-fix\" thing! Argh! And tomorrow\nI'm going to branch off yet another feature \"optional-reset\" from\ntoday's state that will be merged into upstream soon; \"Merge branch\n'rename-buttons' into layout-fix\" will read strange in a history that\nends in \"Merge branch 'optional-reset'\".\n\nAnd I haven't even mentioned this horrid \"into HEAD\", which you get\nduring a rebase operation.\n\nTo be clear, the branch name in \"Merge branch 'option-reset'\" is very\nimportant and invaluable. But the \"into foo\" part is mostly noise.\n\n-- Hannes\n"},{"id":"400006","messageId":"xmqqmu51s88k.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"1612660e-aa49-5d7f-d47e-34740e330eaa@kdbg.org","subject":"Re: [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-17T21:16:59Z","receivedAt":"2020-06-17T21:17:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j6t@kdbg.org> writes:\n\n> Am 15.06.20 um 14:50 schrieb Johannes Schindelin via GitGitGadget:\n>> @@ -451,10 +451,12 @@ static void fmt_merge_msg_title(struct strbuf *out,\n>>  \t\t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n>>  \t}\n>>  \n>> -\tif (!strcmp(\"master\", current_branch))\n>> +\tmain_branch = git_main_branch_name();\n>> +\tif (!strcmp(main_branch, current_branch))\n>>  \t\tstrbuf_addch(out, '\\n');\n>>  \telse\n>>  \t\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n>> +\tfree(main_branch);\n>>  }\n>\n> Now that the removal of this special case is on the plate, I would\n> prefer that the phrase \"into foo\" is never appended instead of always\n> appended.\n\nI do not mind such an optional feature.  I always find it useful\nwhenever I read \"git log --oneline --first-parent master..pu\" (of\ncourse I have an alias for that) to see which topics are already in\nmy private \"to be used in real life\" edition, so I would oppose to\nan unconditional removal, though.\n\n"},{"id":"400009","messageId":"20200617212333.GB2809@coredump.intra.peff.net","threadId":"53651","inReplyTo":"xmqqmu51v9qy.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v2 01/12] fast-export: do anonymize the primary branch name","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-17T21:23:33Z","receivedAt":"2020-06-17T21:23:35Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jun 17, 2020 at 11:16:05AM -0700, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > Of course that only helps you for _one_ branch. A more generally useful\n> > mechanism would be to teach fast-export to write the ref mapping (and\n> > perhaps file mappings, etc) to a separate file. Then you could convert\n> > any reproduction recipe to use the anonymized names, and share only that\n> > recipe along with the anonymized dump. But that's _way_ outside the\n> > scope of your series. This seems like a good interim step to retain the\n> > status quo.\n> \n> Actually, dropping this special case, and dropping the other special\n> case with fmt-merge-msg, we can do without the notion of the\n> \"primary\" branch.\n\nThat leaves us in the interim with a \"fast-export --anonymize\" that is a\nlittle harder to use (you have no way to know which branch was which).\n\nBut I don't mind at all implementing the map-dumping feature to help\nmove this along. As long as both make it into the same release, then\nfast-export only gets better, and never regresses. :)\n\n-Peff\n"},{"id":"400022","messageId":"CABPp-BETyMYm=5APqAA3D1JmkurDFNkKLDrcF4MUgEfqEuVKFA@mail.gmail.com","threadId":"53651","inReplyTo":"20200617212333.GB2809@coredump.intra.peff.net","subject":"Re: [PATCH v2 01/12] fast-export: do anonymize the primary branch name","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2020-06-18T02:06:26Z","receivedAt":"2020-06-18T02:06:46Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Wed, Jun 17, 2020 at 2:25 PM Jeff King <peff@peff.net> wrote:\n>\n> On Wed, Jun 17, 2020 at 11:16:05AM -0700, Junio C Hamano wrote:\n>\n> > Jeff King <peff@peff.net> writes:\n> >\n> > > Of course that only helps you for _one_ branch. A more generally useful\n> > > mechanism would be to teach fast-export to write the ref mapping (and\n> > > perhaps file mappings, etc) to a separate file. Then you could convert\n> > > any reproduction recipe to use the anonymized names, and share only that\n> > > recipe along with the anonymized dump. But that's _way_ outside the\n> > > scope of your series. This seems like a good interim step to retain the\n> > > status quo.\n> >\n> > Actually, dropping this special case, and dropping the other special\n> > case with fmt-merge-msg, we can do without the notion of the\n> > \"primary\" branch.\n>\n> That leaves us in the interim with a \"fast-export --anonymize\" that is a\n> little harder to use (you have no way to know which branch was which).\n\nWhy does fast-export special case on \"master\" rather than on HEAD?\nIsn't it more relevant to know the active branch than what _might_\nhave been the initial branch?  It kind of feels like a bug to me that\nHEAD isn't the special case construct.\n\n(Speaking as someone whose company a number of years ago had most\ntheir big repos and lots of little repos switch their main branch to\nbe named \"develop\", and in some of those repos deleted \"master\" but\ndidn't in others.  If I had needed some steps to reproduce a problem,\nand hadn't been on the inside, any special casing from fast-export\nwould make more sense to me to apply to \"develop\" than to \"master\".)\n\n> But I don't mind at all implementing the map-dumping feature to help\n> move this along. As long as both make it into the same release, then\n> fast-export only gets better, and never regresses. :)\n"},{"id":"400030","messageId":"xmqqzh90q414.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"CABPp-BETyMYm=5APqAA3D1JmkurDFNkKLDrcF4MUgEfqEuVKFA@mail.gmail.com","subject":"Re: [PATCH v2 01/12] fast-export: do anonymize the primary branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-18T06:30:47Z","receivedAt":"2020-06-18T06:30:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Elijah Newren <newren@gmail.com> writes:\n\n>> That leaves us in the interim with a \"fast-export --anonymize\" that is a\n>> little harder to use (you have no way to know which branch was which).\n>\n> Why does fast-export special case on \"master\" rather than on HEAD?\n> Isn't it more relevant to know the active branch than what _might_\n> have been the initial branch?  It kind of feels like a bug to me that\n> HEAD isn't the special case construct.\n\nI am torn on that one.  Surely HEAD is often the branch that has our\ncurrent attention.  It may well be what we are exporting and we may\nwant to see the topology formed by other refs relative to it.\n\nOn the other hand, the current branch may not necessarily be what we\nare exporting.  Historically a project has a single branch that is\nthe focus of most users' attention when they talk about the general\nstate of the project's progress, so it is understandable to expect\nthat the topology may want to be seen relative to that one central\nline of development.\n\n> (Speaking as someone whose company a number of years ago had most\n> their big repos and lots of little repos switch their main branch to\n> be named \"develop\", and in some of those repos deleted \"master\" but\n> didn't in others.  If I had needed some steps to reproduce a problem,\n> and hadn't been on the inside, any special casing from fast-export\n> would make more sense to me to apply to \"develop\" than to \"master\".)\n\nYes, absolutely.  You either check \"develop\" out temporarily just to\ntake anonymized export to make \"develop\" discoverable in the output,\nor you would have set core.primaryBranch to \"develop\" once sometime\nin the past to tell Git that \"develop\" is that special one, not\n\"master\", so you can take such an export from any branch.  As the\nanonymized export is primarily/solely a debugging aid, convenience\nwould not be of much value, but the latter feels more convenient to\nme.\n\n"},{"id":"400032","messageId":"CABPp-BHB_WQqvRBKyA3bGy0L8FZhnN2CL2jHepDBrkjUDNrE=Q@mail.gmail.com","threadId":"53651","inReplyTo":"xmqqzh90q414.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v2 01/12] fast-export: do anonymize the primary branch name","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2020-06-18T07:13:53Z","receivedAt":"2020-06-18T07:14:07Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"Hi Junio,\n\nOn Wed, Jun 17, 2020 at 11:30 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Elijah Newren <newren@gmail.com> writes:\n>\n> >> That leaves us in the interim with a \"fast-export --anonymize\" that is a\n> >> little harder to use (you have no way to know which branch was which).\n> >\n> > Why does fast-export special case on \"master\" rather than on HEAD?\n> > Isn't it more relevant to know the active branch than what _might_\n> > have been the initial branch?  It kind of feels like a bug to me that\n> > HEAD isn't the special case construct.\n>\n> I am torn on that one.  Surely HEAD is often the branch that has our\n> current attention.  It may well be what we are exporting and we may\n> want to see the topology formed by other refs relative to it.\n>\n> On the other hand, the current branch may not necessarily be what we\n> are exporting.  Historically a project has a single branch that is\n> the focus of most users' attention when they talk about the general\n> state of the project's progress, so it is understandable to expect\n> that the topology may want to be seen relative to that one central\n> line of development.\n\nI'm trying to understand here, but I feel like I'm missing something.\nLet me try to explain what I understand and hopefully you can figure\nout what I'm not seeing...\n\n\nRegardless of what is mainline and whether or not it is important,\nusers probably trigger their bug when a certain branch is checked out.\nTheir bug may also trigger on other branches, but it at least triggers\non one, and some bugs will only trigger on one branch.  It seems\nlogical to me that we would want to have the same branch checked out\n(it's the one most likely to trigger the same issue), and thus\nidentifying the HEAD branch is generally important.  (Mainline may be\ntoo, I'm merely asserting that HEAD is important at this point.)\n\nIf users trigger their bug by providing various revision\nspecifications on the command line that compare multiple branches or\nsomething, then we're already in the situation of needing to know how\nto map more than one reference to anonymized ones in order to be able\nto replicate their issue.  However, knowing the mainline might not\neven help in this case; we instead need to know the anonymized form of\nthe references they are using, whatever those are, and mainline is\nonly useful if it happens to be one of them.\n\nSo, I think HEAD is always useful.  Additional references would\nsometimes be useful, but it's not clear to me that mainline is one of\nthose additional references.  Maybe I'm just being dense, and I\napologize if so, but under what circumstances does knowing the\nmainline help with debugging a user issue where an anonymized\nfast-export is provided?\n\n> > (Speaking as someone whose company a number of years ago had most\n> > their big repos and lots of little repos switch their main branch to\n> > be named \"develop\", and in some of those repos deleted \"master\" but\n> > didn't in others.  If I had needed some steps to reproduce a problem,\n> > and hadn't been on the inside, any special casing from fast-export\n> > would make more sense to me to apply to \"develop\" than to \"master\".)\n>\n> Yes, absolutely.  You either check \"develop\" out temporarily just to\n> take anonymized export to make \"develop\" discoverable in the output,\n\nThat makes sense; if the bug triggers while they are on develop then\nI'd expect them to be on develop when they export.  If it triggers on\nsome other branch, I'd expect them to stay on that other branch when\nthey export even if \"develop\" is the mainline.\n\n> or you would have set core.primaryBranch to \"develop\" once sometime\n> in the past to tell Git that \"develop\" is that special one, not\n> \"master\", so you can take such an export from any branch.\n\nThis doesn't make sense to me.  The person who changed the primary\nbranch to \"develop\" for some repository did so years ago.  That\nindividual might not even still be at the company, and even if they\nare, may well be working on a totally different project (and\nrepository) today.  Perhaps that individual set core.primaryBranch at\nthe time, but git-config settings aren't copied by fetch/clone/push,\nso I don't see how this one helps at all.  We could tell all future\ndevelopers who clone any of these repositories that they also need to\nset core.primaryBranch when they clone the repo, but that seems super\nlame to me especially since the odds that any one of them will ever\nneed or benefit from it are approximately 0.  And yet, it'll be one of\nthese developers who joined the project long after the switchover who\nruns into problems and provides fast-export dumps.\n\n\nIt feels like I'm probably just missing something obvious, but I\nreally don't see how the mainline is special here.  Please do point\nout what I'm missing.\n\nThanks,\nElijah\n"},{"id":"400047","messageId":"nycvar.QRO.7.76.6.2006181208180.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200616131039.GG666057@coredump.intra.peff.net","subject":"Re: [PATCH v2 05/12] fast-export: handle overridden main branch names correctly","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-18T10:08:50Z","receivedAt":"2020-06-18T10:09:59Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Peff,\n\nOn Tue, 16 Jun 2020, Jeff King wrote:\n\n> On Mon, Jun 15, 2020 at 04:05:52PM +0100, Phillip Wood wrote:\n>\n> > > @@ -515,14 +515,23 @@ static const char *anonymize_refname(const char *refname)\n> > >   \t};\n> > >   \tstatic struct hashmap refs;\n> > >   \tstatic struct strbuf anon = STRBUF_INIT;\n> > > +\tstatic char *main_branch;\n> > [...]\n> > > -\tif (!strcmp(refname, \"refs/heads/master\"))\n> > > +\tif (!main_branch)\n> > > +\t\tmain_branch = git_main_branch_name(MAIN_BRANCH_FULL_NAME);\n> > > +\n> > > +\tif (!strcmp(refname, main_branch))\n> > >   \t\treturn \"refs/heads/ref0\";\n> >\n> > This leaks main_branch if it came from git_main_branch_name()\n>\n> It's a static that's used over and over, so I think it's intentional to\n> essentially memoize it for the life of the program (at which point we\n> could free it, but don't bother to do so, letting the process exit take\n> care of it, and trusting in leak detectors to be aware that it's still\n> reachable, as we do for lots of other process-lifetime allocations).\n\nThat is indeed the intention, and I will edit the commit message\naccordingly.\n\nThanks,\nDscho\n"},{"id":"400050","messageId":"nycvar.QRO.7.76.6.2006181216440.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200616122559.GA666057@coredump.intra.peff.net","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-18T10:17:37Z","receivedAt":"2020-06-18T10:18:13Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Peff,\n\nOn Tue, 16 Jun 2020, Jeff King wrote:\n\n> On Sun, Jun 14, 2020 at 10:57:41AM +0200, Johannes Schindelin wrote:\n>\n> > > >> Why adding yet another environment variable instead of relying only on a\n> > > >> config option?  I understand it's for the tests, but can't we add a\n> > > >> shell function in test-lib.sh (and friends) that tries to read\n> > > >> `GIT_TEST_DEFAULT_BRANCH_NAME', and, if it exists, sets\n> > > >> `core.defaultBranchName'?\n> > > >\n> > > > Can you produce such a patch that does it cleanly?  My knee jerk\n> > > > reaction is that I would suspect that you end up having to touch\n> > > > many places in the t/ scripts, but if you prove otherwise, that\n> > > > would certainly be appreciated.\n> > > >\n> > > > And no,\n> > > >\n> > > >     git () { command git -c core.defaultBranchName=master \"$@\" }\n> > > >\n> > > > is not an acceptable solution.\n> > > >\n> > >\n> > > I wanted to to do something like this:\n> > >\n> > >   if test -n \"$GIT_TEST_DEFAULT_BRANCH_NAME\";\n> > >   then\n> > >       git config core.defaultBranchName \"$GIT_TEST_DEFAULT_BRANCH_NAME\"\n> > >   fi\n> > >\n> > > But since we do not have a repository to store the config, it won't\n> > > work.  Sorry for the noise.\n> >\n> > We actually would have `~/.gitconfig` because `HOME` is set to `t/trash\n> > directory.<test-name>/`.\n> >\n> > However, that would cause all kinds of issues when test scripts expect the\n> > directory to be pristine, containing only `.git/` but not `.gitconfig`.\n>\n> Putting:\n>\n>   GIT_CONFIG_PARAMETERS=\"'core.defaultBranchName=...'\"\n>\n> into the environment would work (and yes, you need the single quotes\n> embedded in the variable), and solves all of the complaints above.\n> Further \"git -c\" invocations properly append to it. But:\n>\n>   - there are a few tests which explicitly tweak that variable\n>\n>   - it technically changes any tests of \"-c\" because now we'd never\n>     cover the case where we start without the variable defined\n\nIndeed.\n\n> I think baking in a special environment variable like you have is not so\n> bad. If this did become too common a pattern, though (special test-only\n> environment variables that do have a separate config option), I wouldn't\n> be opposed to a GIT_TEST_CONFIG_PARAMETERS which takes precedence over\n> other config, and comes with a big warning label that it shouldn't be\n> relied upon outside the test suite. That's equally ugly to\n> GIT_TEST_DEFAULT_BRANCH_NAME, but at least solves the problem once for\n> all of them. I'm just not sure we have enough \"all of them\" to make it\n> worth doing.\n\nFWIW I do not plan on using that variable for a long time. And it is not\nin this here patch series any longer, so let's discuss it in the future\npatch contribution of mine.\n\nThanks,\nDscho\n"},{"id":"400051","messageId":"nycvar.QRO.7.76.6.2006181218270.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200616123559.GB666057@coredump.intra.peff.net","subject":"Re: [PATCH 2/9] remote: respect `core.defaultBranchName`","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-18T10:21:30Z","receivedAt":"2020-06-18T10:21:48Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Peff,\n\nOn Tue, 16 Jun 2020, Jeff King wrote:\n\n> On Wed, Jun 10, 2020 at 09:19:23PM +0000, Johannes Schindelin via GitGitGadget wrote:\n>\n> > @@ -2099,7 +2100,10 @@ struct ref *guess_remote_head(const struct ref *head,\n> >\n> >  \t/* If refs/heads/master could be right, it is. */\n> >  \tif (!all) {\n> > -\t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n> > +\t\tchar *name = git_default_branch_name(0);\n> > +\n> > +\t\tr = find_ref_by_name(refs, name);\n> > +\t\tfree(name);\n> >  \t\tif (r && oideq(&r->old_oid, &head->old_oid))\n> >  \t\t\treturn copy_ref(r);\n> >  \t}\n>\n> You'd perhaps want to update the comment above, too.\n>\n> However, I think we should be a bit more lenient on the \"reading\" side\n> default names. Just because \"foo\" is _my_ default branch name, does not\n> mean it is the default on the remote side. We cannot know what the other\n> side's default preference is, but in a world where we have 15 years of\n> repos that may have been created with \"master\", it is probably still a\n> good guess.\n>\n> I.e., I think this probably ought to check the preferred name, and then\n> fall back to the existing behavior, like:\n>\n>   if (!all) {\n> \t  char *name;\n>\n>           /* try the user's preferred default branch name */\n> \t  name = git_default_branch_name(0);\n> \t  r = find_ref_by_name(refs, name);\n> \t  free(name);\n> \t  if (r && oideq(&r->old_oid, &head->old_oid))\n> \t          return copy_ref(r);\n>\n> \t  /* otherwise, try \"master\", which is the historical default */\n> \t  r = find_ref_by_name(refs, \"refs/heads/master\");\n> \t  if (r && oideq(&r->old_oid, &head->old_oid))\n> \t          return copy_ref(r);\n>   }\n>\n> That will help minimize fallout when git_default_branch_name() changes,\n> either by user config or if we switch the baked-in default. In the\n> latter case, we might also consider hard-coding that as a guess between\n> the user's preferred name and the historical \"master\".\n>\n> Hopefully this would not matter _too_ much either way, as most servers\n> would support the symref extension these days. But I still think we\n> should do our best to minimize spots where the user may see a\n> regression.\n\nSure, we could just leave this alone, or we can just ditch the\nspecial-casing of `master` here.\n\nAs you say, this does not affect any modern Git version, and IIRC the code\nafter that special-casing tries to find any remote ref that matches the\nremote `HEAD`.\n\nSo it's not like we _need_ this special-casing, anyway.\n\nCiao,\nDscho\n"},{"id":"400054","messageId":"20200618114530.GA41345@coredump.intra.peff.net","threadId":"53651","inReplyTo":"CABPp-BETyMYm=5APqAA3D1JmkurDFNkKLDrcF4MUgEfqEuVKFA@mail.gmail.com","subject":"Re: [PATCH v2 01/12] fast-export: do anonymize the primary branch name","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-18T11:45:30Z","receivedAt":"2020-06-18T11:45:34Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jun 17, 2020 at 07:06:26PM -0700, Elijah Newren wrote:\n\n> > That leaves us in the interim with a \"fast-export --anonymize\" that is a\n> > little harder to use (you have no way to know which branch was which).\n> \n> Why does fast-export special case on \"master\" rather than on HEAD?\n> Isn't it more relevant to know the active branch than what _might_\n> have been the initial branch?  It kind of feels like a bug to me that\n> HEAD isn't the special case construct.\n\nI don't really remember my exact thought at the time, but it was\nprobably along the lines of: \"master\" is special not because it's\ninherently special, but because revealing it doesn't compromise the\nanonymity, since it's not a user-selected name.\n\nThat's not true of other names we might see in HEAD. But if we're\nturning it into \"ref0\" or some other special name anyway, then we\nhaven't revealed anything.\n\nThat said, I still lean towards just being able to dump the whole\nmapping by request. That solves this problem and many more.\n\n-Peff\n"},{"id":"400055","messageId":"20200618115028.GB41345@coredump.intra.peff.net","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006181218270.54@tvgsbejvaqbjf.bet","subject":"Re: [PATCH 2/9] remote: respect `core.defaultBranchName`","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-18T11:50:28Z","receivedAt":"2020-06-18T11:50:31Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Jun 18, 2020 at 12:21:30PM +0200, Johannes Schindelin wrote:\n\n> > Hopefully this would not matter _too_ much either way, as most servers\n> > would support the symref extension these days. But I still think we\n> > should do our best to minimize spots where the user may see a\n> > regression.\n> \n> Sure, we could just leave this alone, or we can just ditch the\n> special-casing of `master` here.\n> \n> As you say, this does not affect any modern Git version, and IIRC the code\n> after that special-casing tries to find any remote ref that matches the\n> remote `HEAD`.\n\nI think we need to be a little careful with \"any modern Git\", because a\nmodern client against an old (or perhaps an alternative implementation)\nserver might still use it. I have to imagine it's pretty rare, but I\nthink it's still useful to return _some_ value.\n\nBut as you note, even without a symref extension, we already try to\nguess based on a unique branch. Probably even choosing the first one\nalphabetically would be reasonable. But I'd rather err on the side of\nhistorical compatibility if we can do so easily. Looking for\ninit.mainBranch, followed by master, accomplishes that and isn't many\nlines of code.\n\n-Peff\n"},{"id":"400056","messageId":"nycvar.QRO.7.76.6.2006181507370.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200616124739.GD666057@coredump.intra.peff.net","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-18T13:08:13Z","receivedAt":"2020-06-18T13:08:32Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Peff,\n\nOn Tue, 16 Jun 2020, Jeff King wrote:\n\n> On Tue, Jun 16, 2020 at 08:45:02AM -0400, Jeff King wrote:\n>\n> > On Wed, Jun 10, 2020 at 08:16:38PM -0400, Eric Sunshine wrote:\n> >\n> > > > +/*\n> > > > + * Retrieves the name of the default branch. If `short_name` is non-zero, the\n> > > > + * branch name will be prefixed with \"refs/heads/\".\n> > > > + */\n> > > > +char *git_default_branch_name(int short_name);\n> > >\n> > > Overall, the internal logic regarding duplicating/freeing strings\n> > > would probably be easier to grok if there were two separate functions:\n> > >\n> > >     char *git_default_branch_name(void);\n> > >     char *git_default_ref_name(void);\n> > >\n> > > but that's subjective.\n> >\n> > Having seen one of the callers, might it be worth avoiding handing off\n> > ownership of the string entirely?\n> >\n> > I.e., this comes from a string that's already owned for the lifetime of\n> > the process (either the environment, or a string stored by the config\n> > machinery). Could we just pass that back (or if we want to be more\n> > careful about getenv() lifetimes, we can copy it into a static owned by\n> > this function)?\n> >\n> > Then all of the callers can stop dealing with the extra free(), and you\n> > can do:\n> >\n> >   const char *git_default_branch_name(void)\n> >   {\n> > \treturn skip_prefix(\"refs/heads/\", git_default_ref_name());\n> >   }\n>\n> Actually, one small hiccup is that the config option specifies the\n> branch name, not the ref name. So you really would have to prepare a\n> static-owned copy of it to turn \"foo\" into \"refs/heads/foo\" to get the\n> refname.\n>\n> On the other hand, that would also be a good time to run\n> check_ref_format(). In the patch as-is, the \"short\" return does not\n> check that the branch is a valid name.\n\nLegit.\n\nI will work on this.\n\nThanks,\nDscho\n"},{"id":"400057","messageId":"nycvar.QRO.7.76.6.2006181514430.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqeeqdv9e8.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-18T13:15:34Z","receivedAt":"2020-06-18T13:15:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 17 Jun 2020, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n>\n> > I'm not sure if this check_refname_format() is valid, though. IIRC we've\n> > had issues where \"ONELEVEL\" was used to check a branch name, but misses\n> > some cases. The more full check done by strbuf_check_branch_ref()\n> > actually creates the full refname and checks that. It also catches stuff\n> > like refs/heads/HEAD.\n>\n> Yup.\n>\n> I actually am in favor of removing special casing of a single branch\n> done by fmt-merge-msg and fast-export --anonymize, so this may not\n> matter.\n>\n> We still need a mechanism to allow users specify the default name to\n> be given to the first branch \"git init\" creates and used by \"git clone\"\n> as a fallback name when it cannot infer what the other side uses, though.\n\nAll right, `core.mainBranch` will go, then, and `init.defaultBranch` will\nstay and I will check the full ref.\n\nThank you for your help improving the patch series,\nDscho\n"},{"id":"400358","messageId":"nycvar.QRO.7.76.6.2006231357260.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"b530fe66-9cf6-ea63-e9e6-123448e2d978@gmail.com","subject":"Re: [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-23T12:31:53Z","receivedAt":"2020-06-23T12:32:19Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Phillip,\n\nOn Mon, 15 Jun 2020, Phillip Wood wrote:\n\n> On 15/06/2020 13:50, Johannes Schindelin via GitGitGadget wrote:\n> > From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> >\n> > There is a growing number of projects and companies desiring to change\n> > the main branch name of their repositories (see e.g.\n> > https://twitter.com/mislav/status/1270388510684598272 for background on\n> > this).\n>\n> I think this is a good way of phrasing the rationale for the change\n\nAs I am replacing this patch in v3 with a version that simply drops the\nspecial handling of the `master` branch, I moved that rationale into the\npatch introducing support for `git init --initial-branch=<name>`.\n\n> > However, there are a couple of hard-coded spots in Git's source code\n> > that make this endeavor harder than necessary. For example, when\n> > formatting the commit message for merge commits, Git appends \"into\n> > <branch-name>\" unless the current branch is the `master` branch.\n> >\n> > Clearly, this is not what one wants when already having gone through all\n> > the steps to manually rename the main branch\n>\n> This didn't quite scan for me maybe s/already having/one has already/ ?\n\nThank you! If I had not dropped that part of the commit message, I would\nhave taken your suggested fix.\n\n> > (and taking care of all the\n> > fall-out such as re-targeting existing Pull Requests).\n> >\n> > Let's introduce a way to override Git's hard-coded default:\n> > `core.mainBranch`.\n> >\n> > We will start supporting this config option in the `git fmt-merge-msg`\n> > command and successively adjust all other places where the main branch\n> > name is hard-coded.\n> >\n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> > ---\n> >   Documentation/config/core.txt |  5 +++++\n> >   fmt-merge-msg.c               |  6 ++++--\n> >   refs.c                        | 27 +++++++++++++++++++++++++++\n> >   refs.h                        |  7 +++++++\n> >   t/t6200-fmt-merge-msg.sh      |  7 +++++++\n> >   5 files changed, 50 insertions(+), 2 deletions(-)\n> >\n> > diff --git a/Documentation/config/core.txt b/Documentation/config/core.txt\n> > index 74619a9c03b..32bb5368ebb 100644\n> > --- a/Documentation/config/core.txt\n> > +++ b/Documentation/config/core.txt\n> > @@ -626,3 +626,8 @@ core.abbrev::\n> >    in your repository, which hopefully is enough for\n> >    abbreviated object names to stay unique for some time.\n> >    The minimum length is 4.\n> > +\n> > +core.mainBranch::\n> > +\tThe name of the main (or: primary) branch in the current repository.\n> > +\tFor historical reasons, `master` is used as the fall-back for this\n> > +\tsetting.\n> > diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\n> > index 72d32bd73b1..43f4f829242 100644\n> > --- a/fmt-merge-msg.c\n> > +++ b/fmt-merge-msg.c\n> > @@ -407,7 +407,7 @@ static void fmt_merge_msg_title(struct strbuf *out,\n> >   \t\t\t\tconst char *current_branch)\n> >   {\n> >   \tint i = 0;\n> > -\tchar *sep = \"\";\n> > +\tchar *sep = \"\", *main_branch;\n> >\n> >    strbuf_addstr(out, \"Merge \");\n> >    for (i = 0; i < srcs.nr; i++) {\n> > @@ -451,10 +451,12 @@ static void fmt_merge_msg_title(struct strbuf *out,\n> >    \t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n> >    }\n> >   -\tif (!strcmp(\"master\", current_branch))\n> > +\tmain_branch = git_main_branch_name();\n> > +\tif (!strcmp(main_branch, current_branch))\n> >    \tstrbuf_addch(out, '\\n');\n> >    else\n> >   \t\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n> > +\tfree(main_branch);\n> >   }\n> >\n> >   static void fmt_tag_signature(struct strbuf *tagbuf,\n> > diff --git a/refs.c b/refs.c\n> > index 224ff66c7bb..f1854cffa2f 100644\n> > --- a/refs.c\n> > +++ b/refs.c\n> > @@ -560,6 +560,33 @@ void expand_ref_prefix(struct argv_array *prefixes,\n> > const char *prefix)\n> >   \t\targv_array_pushf(prefixes, *p, len, prefix);\n> >   }\n> >\n> > +char *repo_main_branch_name(struct repository *r)\n> > +{\n> > +\tconst char *config_key = \"core.mainbranch\";\n> > +\tconst char *config_display_key = \"core.mainBranch\";\n> > +\tconst char *fall_back = \"master\";\n> > +\tchar *name = NULL, *ret;\n> > +\n> > +\tif (repo_config_get_string(r, config_key, &name) < 0)\n> > +\t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n> > +\n> > +\tret = name ? name : xstrdup(fall_back);\n> > +\n> > +\tif (check_refname_format(ret, REFNAME_ALLOW_ONELEVEL))\n> > +\t\tdie(_(\"invalid branch name: %s = %s\"),\n> > +\t\t    config_display_key, name);\n> > +\n> > +\tif (name != ret)\n> > +\t\tfree(name);\n>\n> I'm struggling to come up with a scenario where name != NULL && name != ret\n> here, however once we get to patch 4 that scenario definitely does exist.\n\nRight.\n\nBut as I am dropping the concept of `core.mainBranch` from v3, this won't\napply anymore.\n\n>\n> > +\n> > +\treturn ret;\n> > +}\n> > +\n> > +char *git_main_branch_name(void)\n> > +{\n> > +\treturn repo_main_branch_name(the_repository);\n> > +}\n> > +\n> >   /*\n> >    * *string and *len will only be substituted, and *string returned (for\n> >    * later free()ing) if the string passed in is a magic short-hand form\n> > diff --git a/refs.h b/refs.h\n> > index a92d2c74c83..a207ef01348 100644\n> > --- a/refs.h\n> > +++ b/refs.h\n> > @@ -154,6 +154,13 @@ int repo_dwim_log(struct repository *r, const char\n> > *str, int len, struct object_\n> >   int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n> >   int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n> >\n> > +/*\n> > + * Retrieves the name of the main (or: primary) branch of the given\n>\n> nit pick, I'm confused by the ':'\n\nRight, v3 won't have that peculiar construct.\n\nThank you for your review!\nDscho\n\n>\n> Best Wishes\n>\n> Phillip\n>\n> > + * repository.\n> > + */\n> > +char *git_main_branch_name(void);\n> > +char *repo_main_branch_name(struct repository *r);\n> > +\n> >   /*\n> >    * A ref_transaction represents a collection of reference updates that\n> >    * should succeed or fail together.\n> > diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh\n> > index e4c2a6eca43..7a873f4a05c 100755\n> > --- a/t/t6200-fmt-merge-msg.sh\n> > +++ b/t/t6200-fmt-merge-msg.sh\n> > @@ -158,6 +158,13 @@ test_expect_success 'setup FETCH_HEAD' '\n> >   \tgit fetch . left\n> >   '\n> >\n> > +test_expect_success 'with overridden default branch name' '\n> > +\ttest_when_finished \"git switch master\" &&\n> > +\tgit switch -c default &&\n> > +\tgit -c core.mainBranch=default fmt-merge-msg <.git/FETCH_HEAD >actual\n> > &&\n> > +\t! grep \"into default\" actual\n> > +'\n> > +\n> >   test_expect_success 'merge.log=3 limits shortlog length' '\n> >    cat >expected <<-EOF &&\n> >    Merge branch ${apos}left${apos}\n> >\n>\n>\n"},{"id":"400426","messageId":"nycvar.QRO.7.76.6.2006232116210.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"e8ed76e8-bdd5-ae58-56ea-0513a21ac5d6@gmail.com","subject":"Re: [PATCH v2 04/12] git_main_branch_name(): optionally report the full ref name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-23T19:17:57Z","receivedAt":"2020-06-23T19:18:18Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Phillip,\n\nOn Mon, 15 Jun 2020, Phillip Wood wrote:\n\n> On 15/06/2020 13:50, Johannes Schindelin via GitGitGadget wrote:\n> > From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> >\n> > We are about to introduce the first caller of that function (`git\n> > fast-export`) that wants a full ref name instead of the short branch\n> > name.\n> >\n> > To make this change easier to review, let's refactor the function\n> > accordingly without mixing in the actual first call using the new flag.\n> >\n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> > ---\n> >   fmt-merge-msg.c    |  2 +-\n> >   refs.c             | 12 ++++++++----\n> >   refs.h             |  8 ++++++--\n> >   send-pack.c        |  2 +-\n> >   transport-helper.c |  2 +-\n> >   5 files changed, 17 insertions(+), 9 deletions(-)\n> >\n> > diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\n> > index 43f4f829242..03dba905643 100644\n> > --- a/fmt-merge-msg.c\n> > +++ b/fmt-merge-msg.c\n> > @@ -451,7 +451,7 @@ static void fmt_merge_msg_title(struct strbuf *out,\n> >    \t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n> >    }\n> >   -\tmain_branch = git_main_branch_name();\n> > +\tmain_branch = git_main_branch_name(0);\n> >    if (!strcmp(main_branch, current_branch))\n> >    \tstrbuf_addch(out, '\\n');\n> >   \telse\n> > diff --git a/refs.c b/refs.c\n> > index f1854cffa2f..7da3ac178c4 100644\n> > --- a/refs.c\n> > +++ b/refs.c\n> > @@ -560,8 +560,9 @@ void expand_ref_prefix(struct argv_array *prefixes,\n> > const char *prefix)\n> >   \t\targv_array_pushf(prefixes, *p, len, prefix);\n> >   }\n> >\n> > -char *repo_main_branch_name(struct repository *r)\n> > +char *repo_main_branch_name(struct repository *r, int flags)\n> >   {\n> > +\tint full_name = flags & MAIN_BRANCH_FULL_NAME;\n> >    const char *config_key = \"core.mainbranch\";\n> >    const char *config_display_key = \"core.mainBranch\";\n> >    const char *fall_back = \"master\";\n> > @@ -570,7 +571,10 @@ char *repo_main_branch_name(struct repository *r)\n> >    if (repo_config_get_string(r, config_key, &name) < 0)\n> >     die(_(\"could not retrieve `%s`\"), config_display_key);\n> >   -\tret = name ? name : xstrdup(fall_back);\n> > +\tif (full_name)\n> > +\t\tret = xstrfmt(\"refs/heads/%s\", name ? name : fall_back);\n> > +\telse\n> > +\t\tret = name ? name : xstrdup(fall_back);\n>\n> This looks good, we always check the name before returning it and free name if\n> we're returning refs/heads/<name>\n>\n> >    if (check_refname_format(ret, REFNAME_ALLOW_ONELEVEL))\n> >   \t\tdie(_(\"invalid branch name: %s = %s\"),\n> > @@ -582,9 +586,9 @@ char *repo_main_branch_name(struct repository *r)\n> >   \treturn ret;\n> >   }\n> >\n> > -char *git_main_branch_name(void)\n> > +char *git_main_branch_name(int flags)\n> >   {\n> > -\treturn repo_main_branch_name(the_repository);\n> > +\treturn repo_main_branch_name(the_repository, flags);\n> >   }\n> >\n> >   /*\n> > diff --git a/refs.h b/refs.h\n> > index a207ef01348..96472f9a9f5 100644\n> > --- a/refs.h\n> > +++ b/refs.h\n> > @@ -157,9 +157,13 @@ int dwim_log(const char *str, int len, struct object_id\n> > *oid, char **ref);\n> >   /*\n> >    * Retrieves the name of the main (or: primary) branch of the given\n> >    * repository.\n> > + *\n> > + * The result is an allocated string. Unless the flags ask for a short\n> > name, it\n> > + * will be prefixed with \"refs/heads/\".\n> >    */\n>\n> nit pick: the flag is defined to give the fullname, to get the short name you\n> just pass 0.\n\nI decided to drop the flag and always return the name, not the full ref.\nIt makes the code _slightly_ less efficient, but easier to follow.\n\nCiao,\nDscho\n\n>\n> Best Wishes\n>\n> Phillip\n>\n> > -char *git_main_branch_name(void);\n> > -char *repo_main_branch_name(struct repository *r);\n> > +#define MAIN_BRANCH_FULL_NAME (1<<0)\n> > +char *git_main_branch_name(int flags);\n> > +char *repo_main_branch_name(struct repository *r, int flags);\n> >\n> >   /*\n> >    * A ref_transaction represents a collection of reference updates that\n> > diff --git a/send-pack.c b/send-pack.c\n> > index 2532864c812..898720511d0 100644\n> > --- a/send-pack.c\n> > +++ b/send-pack.c\n> > @@ -405,7 +405,7 @@ int send_pack(struct send_pack_args *args,\n> >    }\n> >\n> >   \tif (!remote_refs) {\n> > -\t\tchar *branch_name = git_main_branch_name();\n> > +\t\tchar *branch_name = git_main_branch_name(0);\n> >\n> >     fprintf(stderr, \"No refs in common and none specified; doing nothing.\\n\"\n> >   \t\t\t\"Perhaps you should specify a branch such as '%s'.\\n\",\n> > diff --git a/transport-helper.c b/transport-helper.c\n> > index 8c8f40e322d..7a54e5b2fb2 100644\n> > --- a/transport-helper.c\n> > +++ b/transport-helper.c\n> > @@ -1044,7 +1044,7 @@ static int push_refs(struct transport *transport,\n> >    }\n> >\n> >   \tif (!remote_refs) {\n> > -\t\tchar *branch_name = git_main_branch_name();\n> > +\t\tchar *branch_name = git_main_branch_name(0);\n> >\n> >     fprintf(stderr,\n> >      _(\"No refs in common and none specified; doing nothing.\\n\"\n> >\n>\n"},{"id":"400427","messageId":"nycvar.QRO.7.76.6.2006232118220.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqr1ugw97e.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-23T19:19:56Z","receivedAt":"2020-06-23T19:20:13Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Mon, 15 Jun 2020, Junio C Hamano wrote:\n\n> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> > diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\n> > index 72d32bd73b1..43f4f829242 100644\n> > --- a/fmt-merge-msg.c\n> > +++ b/fmt-merge-msg.c\n> > @@ -407,7 +407,7 @@ static void fmt_merge_msg_title(struct strbuf *out,\n> >  \t\t\t\tconst char *current_branch)\n> >  {\n> >  \tint i = 0;\n> > -\tchar *sep = \"\";\n> > +\tchar *sep = \"\", *main_branch;\n> >\n> >  \tstrbuf_addstr(out, \"Merge \");\n> >  \tfor (i = 0; i < srcs.nr; i++) {\n> > @@ -451,10 +451,12 @@ static void fmt_merge_msg_title(struct strbuf *out,\n> >  \t\t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n> >  \t}\n> >\n> > -\tif (!strcmp(\"master\", current_branch))\n> > +\tmain_branch = git_main_branch_name();\n> > +\tif (!strcmp(main_branch, current_branch))\n> >  \t\tstrbuf_addch(out, '\\n');\n> >  \telse\n> >  \t\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n> > +\tfree(main_branch);\n>\n> While you are at it, taking\n>\n> https://lore.kernel.org/git/20200614211500.GA22505@dcvr/\n>\n> and the response to it into consideration, I'd suggest we should\n> support the case where the user says \"no single branch is special\n> here\" by configuring it to an empty string.\n\nTogether with Peff's comments, I think we're even further than that: v3 of\nthis patch series will completely drop `core.mainBranch` and not\nspecial-case *any* branch in `fmt-merge-msg`.\n\nThere is still merit in Hannes Sixt's wish to be able to turn off the\n`into <branch>` suffix, but that is orthogonal to the purpose of this here\npatch series.\n\nCiao,\nDscho\n\n>\n> > +core.mainBranch::\n> > +\tThe name of the main (or: primary) branch in the current repository.\n> > +\tFor historical reasons, `master` is used as the fall-back for this\n> > +\tsetting.\n>\n> As to the naming of the configuration variable and the actual\n> fall-back value, I would strongly suggest making them DIFFERNT\n> (i.e. separate the concept from an actual value).\n>\n> An instruction\n>\n>     ... oh, if you want to do so, you can set the core.mainBranch\n>     configuration variable to 'main'\n>\n> sounds strange than\n>\n>     ... oh, if you want to do so, you can set the core.primaryBranch\n>     configuration variable to 'main'\n>\n> at least to me, and since I am OK with your choice of 'main' as the\n> replacement for 'master', a separate word would be more appropriate\n> for the variable name.\n>\n>\n"},{"id":"400428","messageId":"nycvar.QRO.7.76.6.2006232120221.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqmu54w91n.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v2 05/12] fast-export: handle overridden main branch names correctly","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-23T19:22:02Z","receivedAt":"2020-06-23T19:22:16Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Mon, 15 Jun 2020, Junio C Hamano wrote:\n\n> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> > +\t * While the main branch name might often be `main` for new\n> > +\t * repositories (and `master` for aged ones), and such well-known names\n>\n> As I said, if you used a different word for the first 'main' in the\n> sentence, it reads much better.\n>\n> > +\t * may not necessarily need anonymizing, it could be configured to use\n> > +\t * a secret word that the user may not want to reveal.\n> >  \t */\n> > -\tif (!strcmp(refname, \"refs/heads/master\"))\n> > +\tif (!main_branch)\n> > +\t\tmain_branch = git_main_branch_name(MAIN_BRANCH_FULL_NAME);\n> > +\n> > +\tif (!strcmp(refname, main_branch))\n> >  \t\treturn \"refs/heads/ref0\";\n>\n> The same comment as 02/12 applies here.  If the helper function\n> returns \"\" when the user says that no branch is more special than\n> others in the repository, the code would automatically do the right\n> thing.\n\nSeeing as the `fast-export` patches in this here patch series will be\ndropped from v3, in favor of Peff's patches, this does no longer need to\nbe addressed.\n\n> In any case, thanks for working on it.  I am on \"vacation\" so will\n> be commenting on the rest of the series later in the week.\n\nWelcome back! I hope you were able to rest.\n\nCiao,\nDscho\n"},{"id":"400433","messageId":"nycvar.QRO.7.76.6.2006232122360.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200616001955.GA686455@generichostname","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-23T20:10:13Z","receivedAt":"2020-06-23T20:10:30Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Denton,\n\nOn Mon, 15 Jun 2020, Denton Liu wrote:\n\n> On Mon, Jun 15, 2020 at 12:26:03AM +0200, Johannes Schindelin wrote:\n> > > For example, my vim plugins are submodules in the '~/.vim/bundle'\n> > > directory. When I want to update them, I run:\n> > >\n> > >   git submodule foreach 'git remote update && git reset --hard origin/master'\n> > >\n> > > With this change hitting a Git release, more and more people would call\n> > > their main branch different names they like. So what is the recommended\n> > > way to do something like this now? How do I checkout the tip of the main\n> > > branch? How do I push to the main branch? How do I pull from the main\n> > > branch? And so on...\n> >\n> > ... has less to do with a new Git release, but more with the decision of\n> > an existing project to change their main branch name.\n> >\n> > That's something users already had to deal with, of course. For example,\n> > projects switching to the Git Flow model will start to use the main branch\n> > name `development`.\n>\n> I brought this concern up in a parallel thread but I'll bring it up here\n> too since it's relevant. Currently, in the .gitmodules file, if the\n> branch is not specified, it defaults to 'master'.\n>\n> When I want to update my vim plugins, I run\n> `git submodule update --remote` which pulls in all of my submodules'\n> 'master' branches. By convention, a lack of `branch` key in .gitmodules\n> conventionally means 'master'.\n>\n> With your change, it becomes the value of git_main_branch_name(), which\n> is fine for now. However, if this value changes to something else, then\n> when I update my Git, suddenly `git submodule update --remote` will be\n> broken for me as all of the new repositories that I pull will be for an\n> incorrect (and possibly missing) branch.\n>\n> This leaves us in a scenario where one developer running an older\n> version of Git would have submodule updates work perfectly fine while a\n> developer with a newer version would have it suddenly broken. This might\n> be hard to debug, especially for someone who doesn't follow the release\n> notes around Git and doesn't realise why the default has suddenly\n> changed.\n>\n> This problem gets much worse if we allow the main branch name to be\n> configurable as then the *private* configurations that a developer has\n> may have an effect on the *publicly visible* behaviour of a repository.\n>\n> I think I see three possible solutions to this:\n>\n> \t1. Special case 'master' in submodules to retain backwards\n> \tcompatibility.\n>\n> \tI don't think this is very appealing as if the change is made to\n> \tuse another default branch name, then the \"default\" branch for\n> \tsubmodules would be \"master\" even though the new default\n> \teverywhere else would be different. And in the future, someone\n> \twho doesn't know the context behind all of this would be very\n> \tconfused where there are two different default branch names.\n>\n> \t2. Disable 'update --remote' support for submodules that don't\n> \tspecify a branch.\n>\n> \tIf Git detects that a branch key is missing when trying to do an\n> \t'update --remote', it should just quit out and refuse to do\n> \tanything. Of course, this a very backwards incompatible change\n> \tand it would require several release cycles to implement where\n> \twe warn users about this impending change before we actually\n> \tmake it happen.\n>\n> \t3. Make 'update --remote' get HEAD.\n>\n> \tI argue that this is how it always should've been implemented\n> \tbut, alas, I can't go back in time and fix it. Regardless, it\n> \tmight be good to flip this to be the default if we're going to\n> \tbe making the change anyway.\n>\n> \tUnfortunately, this suffers from both the problems of 1 and 2.\n> \tAs with 1, we'll end up in a situation where users with\n> \tdifferent versions of Git may experience different behaviours\n> \tgiven the same public repository and I think this is definitely\n> \tundesirable. With 2, this change will also require a long\n> \tdeprecation period which I don't think it compatible with how\n> \tpeople seem to want the default branch switch to happen this\n> \trelease.\n>\n> So I dunno. I think my opinion leans on not changing the default branch\n> at all. Since it seems like the consensus is generally that it _will_\n> change, I think I would prefer options 3, 2 and 1 in that order.\n>\n> Thoughts?\n\nMy intuition matches your preference, and I have a strong preference for\n3.\n\nIt took some banging my head (not my HEAD...) against the code to convince\nmyself that the patch I prepared for v3 is good: I managed to confuse\nmyself what with all those submodules and clones in t7406.\n\nCiao,\nDscho\n"},{"id":"400434","messageId":"nycvar.QRO.7.76.6.2006232214030.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200616142423.GA667151@coredump.intra.peff.net","subject":"Re: [PATCH 0/9] Allow overriding the default name of the default branch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-23T20:28:11Z","receivedAt":"2020-06-23T20:28:29Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Peff & Ævar,\n\nOn Tue, 16 Jun 2020, Jeff King wrote:\n\n> On Tue, Jun 16, 2020 at 10:09:32AM -0400, Jeff King wrote:\n>\n> > I think with that, we could ditch core.mainBranch entirely, with no\n> > notion at all of \"this branch is special in this repo\". We use HEAD\n> > where appropriate, and otherwise avoid any specialness.\n>\n> One obvious exception is that third-party tools may want to know the\n> \"special\" branch for some reason. But I'm inclined to say that they\n> should (in this order):\n>\n>   - consider whether they really need a special branch at all, or if the\n>     mechanism can be made more generic\n>\n>   - consider whether HEAD is the best value for a special branch (e.g.,\n>     GitHub pull requests default to targeting HEAD)\n\nIndeed, this is applicable in many circumstances. For example, instead of\nhttps://github.com/git/git/blob/master/README.md it is just as easy (and\nmore robust) to write https://github.com/git/git/blob/HEAD/README.md.\n\nThe same goes for `git ls-remote origin HEAD` and as a consequence, `git\nfetch origin HEAD`: it fetches the default branch of the remote\nrepository.\n\nAnd with that, I could imagine that this is not actually necessary:\n\n>   - rely on per-tool config for what's special (because it really may\n>     vary between tools, and that's more flexible anyway)\n>\n> But I'm open to hearing about cases where some tool really wants to know\n> \"what did the user consider the special branch at the time of creation\".\n\nI cannot think of any use cases, apart from essentially creating a new\nrepository, where a tool or a user would want to know of such a\npreference.\n\nCiao,\nDscho\n"},{"id":"400436","messageId":"nycvar.QRO.7.76.6.2006232233290.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200616132216.GH666057@coredump.intra.peff.net","subject":"Re: [PATCH v2 09/12] clone: handle overridden main branch names","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-23T20:58:36Z","receivedAt":"2020-06-23T20:58:54Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Peff,\n\nOn Tue, 16 Jun 2020, Jeff King wrote:\n\n> On Mon, Jun 15, 2020 at 12:50:13PM +0000, Johannes Schindelin via GitGitGadget wrote:\n>\n> > diff --git a/builtin/clone.c b/builtin/clone.c\n> > index 487b0a42d75..755fcaeb0ba 100644\n> > --- a/builtin/clone.c\n> > +++ b/builtin/clone.c\n> > @@ -718,6 +718,7 @@ static void update_head(const struct ref *our, const struct ref *remote,\n> >  \t\t/* Local default branch link */\n> >  \t\tif (create_symref(\"HEAD\", our->name, NULL) < 0)\n> >  \t\t\tdie(_(\"unable to update HEAD\"));\n> > +\t\tgit_config_set(\"core.mainbranch\", head);\n> >  \t\tif (!option_bare) {\n> >  \t\t\tupdate_ref(msg, \"HEAD\", &our->old_oid, NULL, 0,\n> >  \t\t\t\t   UPDATE_REFS_DIE_ON_ERR);\n>\n> Just making sure I understand what's going on here...\n>\n> This covers the case that we've run \"clone -b foo\" or similar, but there\n> are two other case arms when \"foo\" is a tag, or the remote HEAD is\n> unreachable. And there we don't set core.mainbranch at all.\n\nIt was actually meant to catch the case where the remote repository has a\ndefault branch other than `master`.\n\n> But we would not want it to be missing, because that will likely need to\n> stay a default for \"master\" indefinitely (to keep behavior for existing\n> repositories). However, it won't be missing. We'll always have set it\n> during the init_db() call, and this is just overriding that. So we'd end\n> update_head() with either:\n>\n>   - core.mainbranch set to the same branch we point HEAD to, whether we\n>     got it from the remote side or from \"-b foo\"\n>\n>   - if we write a detached HEAD, then core.mainbranch remains at\n>     init.mainbranch (or defaulting to \"master\" now, and probably \"main\"\n>     later). We have no better option.\n>\n> If so, then that makes sense to me.\n\nIn any case, this does not matter anymore, as I am dropping\n`core.mainBranch` from v3, as you had suggested elsewhere in this thread.\n\nCiao,\nDscho\n"},{"id":"400439","messageId":"nycvar.QRO.7.76.6.2006232259320.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200616134618.GI666057@coredump.intra.peff.net","subject":"Re: [PATCH v2 11/12] submodule: use the correct default for the main branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-23T21:03:57Z","receivedAt":"2020-06-23T21:04:24Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Peff,\n\nOn Tue, 16 Jun 2020, Jeff King wrote:\n\n> On Mon, Jun 15, 2020 at 12:50:15PM +0000, Johannes Schindelin via GitGitGadget wrote:\n>\n> > From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> >\n> > To allow for overriding the default branch name, we have introduced a\n> > config setting. With this patch, the `git submodule` command learns\n> > about this, too.\n>\n> This was the other reading case (besides guess_remote_head()) that I'm\n> most concerned with causing regressions in a world where some repos are\n> on \"master\" and some are on \"main\".\n>\n> This value ends up as the output of \"submodule--helper remote-branch\".\n>\n> I was initially worried that we used this branch name for the fallback\n> when the server doesn't allow us to fetch the sha1 directly, but it\n> doesn't look like it. That's good, because handling fallbacks there\n> would be tricky.\n>\n> Instead, we seem to use this only after fetching all of the refs for a\n> submodule:\n>\n>   $ git grep -h -B2 -A11 remote-branch git-submodule.sh\n>   \t\tif test -n \"$remote\"\n>   \t\tthen\n>   \t\t\tbranch=$(git submodule--helper remote-branch \"$sm_path\")\n>   \t\t\tif test -z \"$nofetch\"\n>   \t\t\tthen\n>   \t\t\t\t# Fetch remote before determining tracking $sha1\n>   \t\t\t\tfetch_in_submodule \"$sm_path\" $depth ||\n>   \t\t\t\tdie \"$(eval_gettext \"Unable to fetch in submodule path '\\$sm_path'\")\"\n>   \t\t\tfi\n>   \t\t\tremote_name=$(sanitize_submodule_env; cd \"$sm_path\" && get_default_remote)\n>   \t\t\tsha1=$(sanitize_submodule_env; cd \"$sm_path\" &&\n>   \t\t\t\tgit rev-parse --verify \"${remote_name}/${branch}\") ||\n>   \t\t\tdie \"$(eval_gettext \"Unable to find current \\${remote_name}/\\${branch} revision in submodule path '\\$sm_path'\")\"\n>   \t\tfi\n>\n> and then we just use that branch name to resolve a sha1. So this will\n> break cases where you've set init.mainBranch, the submodule repo is\n> still on \"master\", and you haven't configured a branch in .gitmodules.\n>\n> It seems like, independent of any change in the default branch names, we\n> ought to be using $remote_name/HEAD for this case anyway. I suspect that\n> would be a behavior improvement by itself, as it means more cases could\n> avoid having to specify the branch name in .gitmodules manually.\n> Probably nobody noticed so far because \"HEAD\" is almost always \"master\"\n> in the current world. It technically breaks the case that you truly did\n> want to use \"master\" in the submodule, but they set HEAD to something\n> else, and you couldn't be bothered to put it into your .gitmodules file.\n> That seems rather unlikely to me.\n>\n> And then everything would Just Work without having to worry about the\n> local mainbranch value at all.\n\nThis is the route that I am taking.\n\nPlease note that t7519 contains a few test cases that rely on the current\nconfusing behavior where `git submodule update --remote` fetches the\nremote `master` even if that is not the remote repository's current\nbranch!\n\nI did adjust t7519 to stop verifying this confusing behavior, and to\nverify the saner behavior instead.\n\nThis is of course a bit worrisome, as there might actually be users out\nthere relying on the confusing behavior.\n\nHowever, I think it is okay to fix this:\n\n- The `git submodule update --remote` command does not strike me as\n  awfully common. In fact, I had never heard of it before I worked on this\n  here patch.\n\n- Current Git's behavior when running this command is outright confusing,\n  unless the remote repository's current branch _is_ `master` (in which\n  case the proposed behavior matches the old behavior).\n\n- It is actually easily fixed by setting `submodule.<name>.branch` to\n  `master` _iff_ users want to reinstate the old behavior.\n\n> Alternatively, submodule--helper could pass back the empty string for\n> \"no, we don't have a configured branch name\" and this shell code could\n> actually try a sequence of reasonable guesses: init.mainbranch, then\n> \"master\" (and between the two, \"main\" if that later becomes the\n> default).\n\nQuite honestly: I'd rather not.\n\nThank you,\nDscho\n"},{"id":"400441","messageId":"nycvar.QRO.7.76.6.2006232305160.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200616135121.GJ666057@coredump.intra.peff.net","subject":"Re: [PATCH v2 12/12] testsvn: respect `init.defaultBranch`","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-23T21:07:29Z","receivedAt":"2020-06-23T21:07:46Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Peff,\n\nOn Tue, 16 Jun 2020, Jeff King wrote:\n\n> On Mon, Jun 15, 2020 at 12:50:16PM +0000, Johannes Schindelin via GitGitGadget wrote:\n>\n> > From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> >\n> > The default name of the main branch in new repositories can now be\n> > configured. The `testsvn` remote helper translates the remote Subversion\n> > repository's branch name `trunk` to the hard-coded name `master`.\n> > Clearly, the intention was to make the name align with Git's detaults.\n>\n> s/detaults/defaults/ :)\n\n:-)\n\nWill fix.\n\n> I'd agree that moving this to Git's default name makes sense.\n\nOkay.\n\n> Though my overall preference is still to delete this whole testsvn thing\n> entirely (I have some other pending tree-wide changes that are being\n> held up by it, too). After getting \"would you mind holding off until...\"\n> from Jonathan in [1], I've been waiting almost 2 years. Maybe now is the\n> time?\n\nI wouldn't mind dropping `testsvn`, seeing as there are fewer and fewer\nusers of `git svn` (and even those are unlikely to switch to `testsvn`,\nshould that ever become production-ready).\n\nHaving said that, this is an orthogonal issue to the purpose of this patch\nseries. And I would really like to get this patch series into a shape that\ncan be merged down to `next` soon.\n\nThank you,\nDscho\n\n>\n> -Peff\n>\n> [1] https://lore.kernel.org/git/20180818052605.GA241538@aiede.svl.corp.google.com/\n>\n"},{"id":"400442","messageId":"nycvar.QRO.7.76.6.2006232228560.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200616124502.GC666057@coredump.intra.peff.net","subject":"Re: [PATCH 1/9] init: allow overriding the default branch name for new repositories","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-23T20:32:46Z","receivedAt":"2020-06-23T21:10:39Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Peff,\n\n\nOn Tue, 16 Jun 2020, Jeff King wrote:\n\n> On Wed, Jun 10, 2020 at 08:16:38PM -0400, Eric Sunshine wrote:\n>\n> > > +/*\n> > > + * Retrieves the name of the default branch. If `short_name` is non-zero, the\n> > > + * branch name will be prefixed with \"refs/heads/\".\n> > > + */\n> > > +char *git_default_branch_name(int short_name);\n> >\n> > Overall, the internal logic regarding duplicating/freeing strings\n> > would probably be easier to grok if there were two separate functions:\n> >\n> >     char *git_default_branch_name(void);\n> >     char *git_default_ref_name(void);\n> >\n> > but that's subjective.\n>\n> Having seen one of the callers, might it be worth avoiding handing off\n> ownership of the string entirely?\n\nFor `git_default_branch_name()`: yes. For `repo_default_branch_name()`,\nnot really, as that is potentially repository-specific.\n\n(Side note: while I cannot really think of a use case where you would want\nto set `init.defaultBranch` in a repository-local config, there _might_ be\nuse cases for that out there, and it _is_ how our config machinery works.)\n\n> I.e., this comes from a string that's already owned for the lifetime of\n> the process (either the environment, or a string stored by the config\n> machinery). Could we just pass that back (or if we want to be more\n> careful about getenv() lifetimes, we can copy it into a static owned by\n> this function)?\n>\n> Then all of the callers can stop dealing with the extra free(), and you\n> can do:\n>\n>   const char *git_default_branch_name(void)\n>   {\n> \treturn skip_prefix(\"refs/heads/\", git_default_ref_name());\n>   }\n\nFor ease of use, I decided to only ever return the branch name (but check\nthe full ref).\n\nThose callers that actually need the full ref usually also need the branch\nname, and it is easy enough to call `xstrfmt(\"refs/heads/%s\", ...)`.\n\nIt might make the code a bit less efficient (but who cares, it's not like\nwe're setting up a gazillion repositories per second all the time), but\nquite a bit easier to reason about.\n\nCiao,\nDscho\n"},{"id":"400443","messageId":"nycvar.QRO.7.76.6.2006232309190.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqtuz9tq30.fsf@gitster.c.googlers.com","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-23T21:11:10Z","receivedAt":"2020-06-23T21:11:29Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Wed, 17 Jun 2020, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n>\n> > Yes, the trouble with `maint` did cross my mind, but I try not to\n> > \"overfit\" to git/git. :-)\n>\n> I do not think it is overfitting; if the solution cannot even\n> support the originating project well, there is something wrong.\n>\n> Most likely, I'd be tempted to rename it myself away from any name\n> that is too similar to 'maint'; perhaps to 'stable' (or 'devo', h/t\n> tla ;-).\n\nYou could also use `next` instead of `master`, which would make intuitive\nsense because the commits that make it into that branch are slated to be\npart of the next major Git version.\n\nAnd a relatively obvious name for the current `next` might be `cooking`.\n\nI refrained from proposing this earlier, thinking that this would be too\ndisruptive, but since `pu` was renamed to `seen`...\n\n:-)\n\nCiao,\nDscho\n"},{"id":"400444","messageId":"nycvar.QRO.7.76.6.2006232311270.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqmu51s88k.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v2 02/12] fmt-merge-msg: introduce a way to override the main branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-23T21:12:48Z","receivedAt":"2020-06-23T21:13:12Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio & Hannes,\n\n\nOn Wed, 17 Jun 2020, Junio C Hamano wrote:\n\n> Johannes Sixt <j6t@kdbg.org> writes:\n>\n> > Am 15.06.20 um 14:50 schrieb Johannes Schindelin via GitGitGadget:\n> >> @@ -451,10 +451,12 @@ static void fmt_merge_msg_title(struct strbuf *out,\n> >>  \t\t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n> >>  \t}\n> >>\n> >> -\tif (!strcmp(\"master\", current_branch))\n> >> +\tmain_branch = git_main_branch_name();\n> >> +\tif (!strcmp(main_branch, current_branch))\n> >>  \t\tstrbuf_addch(out, '\\n');\n> >>  \telse\n> >>  \t\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n> >> +\tfree(main_branch);\n> >>  }\n> >\n> > Now that the removal of this special case is on the plate, I would\n> > prefer that the phrase \"into foo\" is never appended instead of always\n> > appended.\n>\n> I do not mind such an optional feature.  I always find it useful\n> whenever I read \"git log --oneline --first-parent master..pu\" (of\n> course I have an alias for that) to see which topics are already in\n> my private \"to be used in real life\" edition, so I would oppose to\n> an unconditional removal, though.\n\nI concur that this would make for a fine optional feature. Of course, that\nis an issue that is separate from the goal to make the default branch name\nused by `git init` configurable, so I will leave that feature to be\nimplemented later (and by somebody else).\n\nCiao,\nDscho\n"},{"id":"400446","messageId":"20200623211426.GA2072288@coredump.intra.peff.net","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006232259320.54@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v2 11/12] submodule: use the correct default for the main branch name","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-06-23T21:14:26Z","receivedAt":"2020-06-23T21:14:31Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jun 23, 2020 at 11:03:57PM +0200, Johannes Schindelin wrote:\n\n> > [use HEAD instead of master]\n> This is the route that I am taking.\n> [...]\n> This is of course a bit worrisome, as there might actually be users out\n> there relying on the confusing behavior.\n> \n> However, I think it is okay to fix this:\n> \n> - The `git submodule update --remote` command does not strike me as\n>   awfully common. In fact, I had never heard of it before I worked on this\n>   here patch.\n> \n> - Current Git's behavior when running this command is outright confusing,\n>   unless the remote repository's current branch _is_ `master` (in which\n>   case the proposed behavior matches the old behavior).\n> \n> - It is actually easily fixed by setting `submodule.<name>.branch` to\n>   `master` _iff_ users want to reinstate the old behavior.\n\nThanks, I agree that this is the best way forward, and that the current\nconfusing behavior is as likely to be doing the wrong thing as the right\n(when it even differs).\n\n-Peff\n"},{"id":"400447","messageId":"nycvar.QRO.7.76.6.2006232313540.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200618115028.GB41345@coredump.intra.peff.net","subject":"Re: [PATCH 2/9] remote: respect `core.defaultBranchName`","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-23T21:15:38Z","receivedAt":"2020-06-23T21:15:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Peff,\n\nOn Thu, 18 Jun 2020, Jeff King wrote:\n\n> On Thu, Jun 18, 2020 at 12:21:30PM +0200, Johannes Schindelin wrote:\n>\n> > > Hopefully this would not matter _too_ much either way, as most servers\n> > > would support the symref extension these days. But I still think we\n> > > should do our best to minimize spots where the user may see a\n> > > regression.\n> >\n> > Sure, we could just leave this alone, or we can just ditch the\n> > special-casing of `master` here.\n> >\n> > As you say, this does not affect any modern Git version, and IIRC the code\n> > after that special-casing tries to find any remote ref that matches the\n> > remote `HEAD`.\n>\n> I think we need to be a little careful with \"any modern Git\", because a\n> modern client against an old (or perhaps an alternative implementation)\n> server might still use it. I have to imagine it's pretty rare, but I\n> think it's still useful to return _some_ value.\n>\n> But as you note, even without a symref extension, we already try to\n> guess based on a unique branch. Probably even choosing the first one\n> alphabetically would be reasonable. But I'd rather err on the side of\n> historical compatibility if we can do so easily. Looking for\n> init.mainBranch, followed by master, accomplishes that and isn't many\n> lines of code.\n\nI ended up using `init.defaultBranch` as preference, falling back to\n`master`, and then falling back to the first ref matching the given commit\nhash.\n\nThat should be safe enough.\n\nCiao,\nDscho\n"},{"id":"400454","messageId":"xmqqpn9pbh8q.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006232309190.54@tvgsbejvaqbjf.bet","subject":"Re: Re* [PATCH 8/9] fast-export: respect the possibly-overridden default branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-23T21:32:37Z","receivedAt":"2020-06-23T21:32:50Z","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> You could also use `next` instead of `master`, which would make intuitive\n> sense because the commits that make it into that branch are slated to be\n> part of the next major Git version.\n>\n> And a relatively obvious name for the current `next` might be `cooking`.\n>\n> I refrained from proposing this earlier, thinking that this would be too\n> disruptive, but since `pu` was renamed to `seen`...\n\nRenaming 'pu' away from two-letter has a positive technical and\nsocial effect.  Using 'next' for anything but what it currently\nmeans does not have any such upside and only the downside of\nconfusing people.\n\nAs to 'cooking', I am not sure.  Personally I consider that the\ntopics that are in 'next' plus those that are soon to be in 'next'\nare all 'cooking'.  But I do not think anybody's dying to rename\n'next', so...\n\n\n"},{"id":"400460","messageId":"a29943d7bbc11a524089348a4abbd33c7514eee9.1592951611.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v3.git.1592951611.gitgitgadget@gmail.com","subject":"[PATCH v3 2/8] send-pack/transport-helper: avoid mentioning a particular branch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-23T22:33:24Z","receivedAt":"2020-06-23T22:47:35Z","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\nWhen trying to push all matching branches, but none match, we offer a\nmessage suggesting to push the `master` branch.\n\nHowever, we want to step away from making that branch any more special\nthan any other branch, so let's reword that message to mention no branch\nin particular.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n send-pack.c             | 2 +-\n t/t5528-push-default.sh | 6 ++++++\n transport-helper.c      | 2 +-\n 3 files changed, 8 insertions(+), 2 deletions(-)\n\ndiff --git a/send-pack.c b/send-pack.c\nindex 0abee22283..db79cdac77 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -406,7 +406,7 @@ int send_pack(struct send_pack_args *args,\n \n \tif (!remote_refs) {\n \t\tfprintf(stderr, \"No refs in common and none specified; doing nothing.\\n\"\n-\t\t\t\"Perhaps you should specify a branch such as 'master'.\\n\");\n+\t\t\t\"Perhaps you should specify a specific branch.\\n\");\n \t\treturn 0;\n \t}\n \tif (args->atomic && !atomic_supported)\ndiff --git a/t/t5528-push-default.sh b/t/t5528-push-default.sh\nindex 4d1e0c363e..68b84c4add 100755\n--- a/t/t5528-push-default.sh\n+++ b/t/t5528-push-default.sh\n@@ -98,6 +98,12 @@ test_expect_success 'push from/to new branch with upstream, matching and simple'\n \ttest_push_failure upstream\n '\n \n+test_expect_success '\"matching\" fails if none match' '\n+\tgit init --bare empty &&\n+\ttest_must_fail git push empty : 2>actual &&\n+\ttest_i18ngrep \"Perhaps you should specify a specific branch\" actual\n+'\n+\n test_expect_success 'push ambiguously named branch with upstream, matching and simple' '\n \tgit checkout -b ambiguous &&\n \ttest_config branch.ambiguous.remote parent1 &&\ndiff --git a/transport-helper.c b/transport-helper.c\nindex a46afcb69d..b81a3486bd 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -1046,7 +1046,7 @@ static int push_refs(struct transport *transport,\n \tif (!remote_refs) {\n \t\tfprintf(stderr,\n \t\t\t_(\"No refs in common and none specified; doing nothing.\\n\"\n-\t\t\t  \"Perhaps you should specify a branch such as 'master'.\\n\"));\n+\t\t\t  \"Perhaps you should specify a specific branch.\\n\"));\n \t\treturn 0;\n \t}\n \n-- \ngitgitgadget\n\n"},{"id":"400462","messageId":"fffdb9944fc2672ccb7eac776cdd18855a1f99dc.1592951611.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v3.git.1592951611.gitgitgadget@gmail.com","subject":"[PATCH v3 1/8] fmt-merge-msg: stop treating `master` specially","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-23T22:33:23Z","receivedAt":"2020-06-23T22:47:39Z","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 the context of many projects renaming their primary branch names away\nfrom `master`, Git wants to stop treating the `master` branch specially.\n\nLet's start with `git fmt-merge-msg`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n fmt-merge-msg.c                               |  5 +-\n t/t1507-rev-parse-upstream.sh                 |  2 +-\n t/t4013-diff-various.sh                       |  4 +-\n t/t4013/diff.log_--decorate=full_--all        |  2 +-\n t/t4013/diff.log_--decorate_--all             |  2 +-\n ...--patch-with-stat_--summary_master_--_dir_ |  2 +-\n t/t4013/diff.log_--patch-with-stat_master     |  2 +-\n .../diff.log_--patch-with-stat_master_--_dir_ |  2 +-\n ...ot_--cc_--patch-with-stat_--summary_master |  2 +-\n ..._--root_--patch-with-stat_--summary_master |  2 +-\n .../diff.log_--root_--patch-with-stat_master  |  2 +-\n ...root_-c_--patch-with-stat_--summary_master |  2 +-\n t/t4013/diff.log_--root_-p_master             |  2 +-\n t/t4013/diff.log_--root_master                |  2 +-\n t/t4013/diff.log_-m_-p_--first-parent_master  |  2 +-\n t/t4013/diff.log_-m_-p_master                 |  4 +-\n t/t4013/diff.log_-p_--first-parent_master     |  2 +-\n t/t4013/diff.log_-p_master                    |  2 +-\n t/t4013/diff.log_master                       |  2 +-\n t/t4013/diff.show_--first-parent_master       |  2 +-\n t/t4013/diff.show_-c_master                   |  2 +-\n t/t4013/diff.show_-m_master                   |  4 +-\n t/t4013/diff.show_master                      |  2 +-\n ...ot_--cc_--patch-with-stat_--summary_master |  2 +-\n ...root_-c_--patch-with-stat_--summary_master |  2 +-\n t/t4202-log.sh                                | 72 +++++++++----------\n t/t6200-fmt-merge-msg.sh                      | 36 +++++-----\n t/t7600-merge.sh                              | 14 ++--\n t/t7608-merge-messages.sh                     | 10 +--\n 29 files changed, 94 insertions(+), 97 deletions(-)\n\ndiff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\nindex 72d32bd73b..cfb8ff2f33 100644\n--- a/fmt-merge-msg.c\n+++ b/fmt-merge-msg.c\n@@ -451,10 +451,7 @@ static void fmt_merge_msg_title(struct strbuf *out,\n \t\t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n \t}\n \n-\tif (!strcmp(\"master\", current_branch))\n-\t\tstrbuf_addch(out, '\\n');\n-\telse\n-\t\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n+\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n }\n \n static void fmt_tag_signature(struct strbuf *tagbuf,\ndiff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh\nindex dfc0d96d8a..f213aa8053 100755\n--- a/t/t1507-rev-parse-upstream.sh\n+++ b/t/t1507-rev-parse-upstream.sh\n@@ -137,7 +137,7 @@ test_expect_success 'merge my-side@{u} records the correct name' '\n \tgit branch -t new my-side@{u} &&\n \tgit merge -s ours new@{u} &&\n \tgit show -s --pretty=tformat:%s >actual &&\n-\techo \"Merge remote-tracking branch ${SQ}origin/side${SQ}\" >expect &&\n+\techo \"Merge remote-tracking branch ${SQ}origin/side${SQ} into master\" >expect &&\n \ttest_cmp expect actual\n )\n '\ndiff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh\nindex 3f60f7d96c..43267d6024 100755\n--- a/t/t4013-diff-various.sh\n+++ b/t/t4013-diff-various.sh\n@@ -117,12 +117,12 @@ test_expect_success setup '\n \n : <<\\EOF\n ! [initial] Initial\n- * [master] Merge branch 'side'\n+ * [master] Merge branch 'side' into master\n   ! [rearrange] Rearranged lines in dir/sub\n    ! [side] Side\n ----\n   +  [rearrange] Rearranged lines in dir/sub\n- -   [master] Merge branch 'side'\n+ -   [master] Merge branch 'side' into master\n  * + [side] Side\n  *   [master^] Third\n  *   [master~2] Second\ndiff --git a/t/t4013/diff.log_--decorate=full_--all b/t/t4013/diff.log_--decorate=full_--all\nindex 3f9b872ece..c56783b985 100644\n--- a/t/t4013/diff.log_--decorate=full_--all\n+++ b/t/t4013/diff.log_--decorate=full_--all\n@@ -31,7 +31,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (refs/heads/side)\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--decorate_--all b/t/t4013/diff.log_--decorate_--all\nindex f5e20e1e14..1cbdc038f4 100644\n--- a/t/t4013/diff.log_--decorate_--all\n+++ b/t/t4013/diff.log_--decorate_--all\n@@ -31,7 +31,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (side)\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--patch-with-stat_--summary_master_--_dir_ b/t/t4013/diff.log_--patch-with-stat_--summary_master_--_dir_\nindex a18f1472a9..f5b1b6516b 100644\n--- a/t/t4013/diff.log_--patch-with-stat_--summary_master_--_dir_\n+++ b/t/t4013/diff.log_--patch-with-stat_--summary_master_--_dir_\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--patch-with-stat_master b/t/t4013/diff.log_--patch-with-stat_master\nindex ae425c4672..af23803cdc 100644\n--- a/t/t4013/diff.log_--patch-with-stat_master\n+++ b/t/t4013/diff.log_--patch-with-stat_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--patch-with-stat_master_--_dir_ b/t/t4013/diff.log_--patch-with-stat_master_--_dir_\nindex d5207cadf4..814098fbf8 100644\n--- a/t/t4013/diff.log_--patch-with-stat_master_--_dir_\n+++ b/t/t4013/diff.log_--patch-with-stat_master_--_dir_\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--root_--cc_--patch-with-stat_--summary_master b/t/t4013/diff.log_--root_--cc_--patch-with-stat_--summary_master\nindex 0fc1e8cd71..b927fe4a98 100644\n--- a/t/t4013/diff.log_--root_--cc_--patch-with-stat_--summary_master\n+++ b/t/t4013/diff.log_--root_--cc_--patch-with-stat_--summary_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n  dir/sub | 2 ++\n  file0   | 3 +++\ndiff --git a/t/t4013/diff.log_--root_--patch-with-stat_--summary_master b/t/t4013/diff.log_--root_--patch-with-stat_--summary_master\nindex dffc09dde9..6db3cea329 100644\n--- a/t/t4013/diff.log_--root_--patch-with-stat_--summary_master\n+++ b/t/t4013/diff.log_--root_--patch-with-stat_--summary_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--root_--patch-with-stat_master b/t/t4013/diff.log_--root_--patch-with-stat_master\nindex 55aa98012d..98e9c320c3 100644\n--- a/t/t4013/diff.log_--root_--patch-with-stat_master\n+++ b/t/t4013/diff.log_--root_--patch-with-stat_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--root_-c_--patch-with-stat_--summary_master b/t/t4013/diff.log_--root_-c_--patch-with-stat_--summary_master\nindex 019d85f7de..b61b1117ae 100644\n--- a/t/t4013/diff.log_--root_-c_--patch-with-stat_--summary_master\n+++ b/t/t4013/diff.log_--root_-c_--patch-with-stat_--summary_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n  dir/sub | 2 ++\n  file0   | 3 +++\ndiff --git a/t/t4013/diff.log_--root_-p_master b/t/t4013/diff.log_--root_-p_master\nindex b42c334439..345bd9e8a9 100644\n--- a/t/t4013/diff.log_--root_-p_master\n+++ b/t/t4013/diff.log_--root_-p_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--root_master b/t/t4013/diff.log_--root_master\nindex e8f46159da..db56b1fe6b 100644\n--- a/t/t4013/diff.log_--root_master\n+++ b/t/t4013/diff.log_--root_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_-m_-p_--first-parent_master b/t/t4013/diff.log_-m_-p_--first-parent_master\nindex 7a0073f529..bcadb50e26 100644\n--- a/t/t4013/diff.log_-m_-p_--first-parent_master\n+++ b/t/t4013/diff.log_-m_-p_--first-parent_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --git a/dir/sub b/dir/sub\n index cead32e..992913c 100644\ndiff --git a/t/t4013/diff.log_-m_-p_master b/t/t4013/diff.log_-m_-p_master\nindex 9ca62a01ed..2acf43a9fb 100644\n--- a/t/t4013/diff.log_-m_-p_master\n+++ b/t/t4013/diff.log_-m_-p_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --git a/dir/sub b/dir/sub\n index cead32e..992913c 100644\n@@ -33,7 +33,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --git a/dir/sub b/dir/sub\n index 7289e35..992913c 100644\ndiff --git a/t/t4013/diff.log_-p_--first-parent_master b/t/t4013/diff.log_-p_--first-parent_master\nindex 3fc896d424..c6a5876d80 100644\n--- a/t/t4013/diff.log_-p_--first-parent_master\n+++ b/t/t4013/diff.log_-p_--first-parent_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_-p_master b/t/t4013/diff.log_-p_master\nindex bf1326dc36..1841cded94 100644\n--- a/t/t4013/diff.log_-p_master\n+++ b/t/t4013/diff.log_-p_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_master b/t/t4013/diff.log_master\nindex a8f6ce5abd..f8ec445eb3 100644\n--- a/t/t4013/diff.log_master\n+++ b/t/t4013/diff.log_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.show_--first-parent_master b/t/t4013/diff.show_--first-parent_master\nindex 3dcbe473a0..94548f4598 100644\n--- a/t/t4013/diff.show_--first-parent_master\n+++ b/t/t4013/diff.show_--first-parent_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --git a/dir/sub b/dir/sub\n index cead32e..992913c 100644\ndiff --git a/t/t4013/diff.show_-c_master b/t/t4013/diff.show_-c_master\nindex 81aba8da96..1c46ed64fd 100644\n--- a/t/t4013/diff.show_-c_master\n+++ b/t/t4013/diff.show_-c_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --combined dir/sub\n index cead32e,7289e35..992913c\ndiff --git a/t/t4013/diff.show_-m_master b/t/t4013/diff.show_-m_master\nindex 4ea2ee453d..7559fc22f8 100644\n--- a/t/t4013/diff.show_-m_master\n+++ b/t/t4013/diff.show_-m_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --git a/dir/sub b/dir/sub\n index cead32e..992913c 100644\n@@ -33,7 +33,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --git a/dir/sub b/dir/sub\n index 7289e35..992913c 100644\ndiff --git a/t/t4013/diff.show_master b/t/t4013/diff.show_master\nindex fb08ce0e46..57091c5d90 100644\n--- a/t/t4013/diff.show_master\n+++ b/t/t4013/diff.show_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --cc dir/sub\n index cead32e,7289e35..992913c\ndiff --git a/t/t4013/diff.whatchanged_--root_--cc_--patch-with-stat_--summary_master b/t/t4013/diff.whatchanged_--root_--cc_--patch-with-stat_--summary_master\nindex 30aae7817b..5f13a71bb5 100644\n--- a/t/t4013/diff.whatchanged_--root_--cc_--patch-with-stat_--summary_master\n+++ b/t/t4013/diff.whatchanged_--root_--cc_--patch-with-stat_--summary_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n  dir/sub | 2 ++\n  file0   | 3 +++\ndiff --git a/t/t4013/diff.whatchanged_--root_-c_--patch-with-stat_--summary_master b/t/t4013/diff.whatchanged_--root_-c_--patch-with-stat_--summary_master\nindex d1d32bd34c..8acb88267b 100644\n--- a/t/t4013/diff.whatchanged_--root_-c_--patch-with-stat_--summary_master\n+++ b/t/t4013/diff.whatchanged_--root_-c_--patch-with-stat_--summary_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n  dir/sub | 2 ++\n  file0   | 3 +++\ndiff --git a/t/t4202-log.sh b/t/t4202-log.sh\nindex a0930599aa..fd9af658af 100755\n--- a/t/t4202-log.sh\n+++ b/t/t4202-log.sh\n@@ -483,7 +483,7 @@ test_expect_success 'set up merge history' '\n '\n \n cat > expect <<\\EOF\n-*   Merge branch 'side'\n+*   Merge branch 'side' into master\n |\\\n | * side-2\n | * side-1\n@@ -502,7 +502,7 @@ test_expect_success 'log --graph with merge' '\n '\n \n cat > expect <<\\EOF\n-| | | *   Merge branch 'side'\n+| | | *   Merge branch 'side' into master\n | | | |\\\n | | | | * side-2\n | | | | * side-1\n@@ -521,7 +521,7 @@ test_expect_success 'log --graph --line-prefix=\"| | | \" with merge' '\n '\n \n cat > expect.colors <<\\EOF\n-*   Merge branch 'side'\n+*   Merge branch 'side' into master\n <BLUE>|<RESET><CYAN>\\<RESET>\n <BLUE>|<RESET> * side-2\n <BLUE>|<RESET> * side-1\n@@ -555,7 +555,7 @@ cat > expect <<\\EOF\n |\\  Merge: A B\n | | Author: A U Thor <author@example.com>\n | |\n-| |     Merge branch 'side'\n+| |     Merge branch 'side' into master\n | |\n | * commit tags/side-2\n | | Author: A U Thor <author@example.com>\n@@ -632,11 +632,11 @@ test_expect_success 'set up more tangled history' '\n '\n \n cat > expect <<\\EOF\n-*   Merge tag 'reach'\n+*   Merge tag 'reach' into master\n |\\\n | \\\n |  \\\n-*-. \\   Merge tags 'octopus-a' and 'octopus-b'\n+*-. \\   Merge tags 'octopus-a' and 'octopus-b' into master\n |\\ \\ \\\n * | | | seventh\n | | * | octopus-b\n@@ -646,14 +646,14 @@ cat > expect <<\\EOF\n |/ /\n | * reach\n |/\n-*   Merge branch 'tangle'\n+*   Merge branch 'tangle' into master\n |\\\n | *   Merge branch 'side' (early part) into tangle\n | |\\\n | * \\   Merge branch 'master' (early part) into tangle\n | |\\ \\\n | * | | tangle-a\n-* | | |   Merge branch 'side'\n+* | | |   Merge branch 'side' into master\n |\\ \\ \\ \\\n | * | | | side-2\n | | |_|/\n@@ -735,16 +735,16 @@ test_expect_success 'log.decorate configuration' '\n \n test_expect_success 'decorate-refs with glob' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh\n \toctopus-b (octopus-b)\n \toctopus-a (octopus-a)\n \treach\n \tEOF\n \tcat >expect.no-decorate <<-\\EOF &&\n-\tMerge-tag-reach\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh\n \toctopus-b\n \toctopus-a\n@@ -765,8 +765,8 @@ test_expect_success 'decorate-refs with glob' '\n \n test_expect_success 'decorate-refs without globs' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh\n \toctopus-b\n \toctopus-a\n@@ -779,8 +779,8 @@ test_expect_success 'decorate-refs without globs' '\n \n test_expect_success 'multiple decorate-refs' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh\n \toctopus-b (octopus-b)\n \toctopus-a (octopus-a)\n@@ -794,8 +794,8 @@ test_expect_success 'multiple decorate-refs' '\n \n test_expect_success 'decorate-refs-exclude with glob' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach (HEAD -> master)\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master (HEAD -> master)\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh (tag: seventh)\n \toctopus-b (tag: octopus-b)\n \toctopus-a (tag: octopus-a)\n@@ -811,8 +811,8 @@ test_expect_success 'decorate-refs-exclude with glob' '\n \n test_expect_success 'decorate-refs-exclude without globs' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach (HEAD -> master)\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master (HEAD -> master)\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh (tag: seventh)\n \toctopus-b (tag: octopus-b, octopus-b)\n \toctopus-a (tag: octopus-a, octopus-a)\n@@ -828,8 +828,8 @@ test_expect_success 'decorate-refs-exclude without globs' '\n \n test_expect_success 'multiple decorate-refs-exclude' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach (HEAD -> master)\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master (HEAD -> master)\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh (tag: seventh)\n \toctopus-b (tag: octopus-b)\n \toctopus-a (tag: octopus-a)\n@@ -851,8 +851,8 @@ test_expect_success 'multiple decorate-refs-exclude' '\n \n test_expect_success 'decorate-refs and decorate-refs-exclude' '\n \tcat >expect.no-decorate <<-\\EOF &&\n-\tMerge-tag-reach (master)\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master (master)\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh\n \toctopus-b\n \toctopus-a\n@@ -866,8 +866,8 @@ test_expect_success 'decorate-refs and decorate-refs-exclude' '\n \n test_expect_success 'deocrate-refs and log.excludeDecoration' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach (master)\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master (master)\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh\n \toctopus-b (octopus-b)\n \toctopus-a (octopus-a)\n@@ -881,10 +881,10 @@ test_expect_success 'deocrate-refs and log.excludeDecoration' '\n \n test_expect_success 'decorate-refs-exclude and simplify-by-decoration' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach (HEAD -> master)\n+\tMerge-tag-reach-into-master (HEAD -> master)\n \treach (tag: reach, reach)\n \tseventh (tag: seventh)\n-\tMerge-branch-tangle\n+\tMerge-branch-tangle-into-master\n \tMerge-branch-side-early-part-into-tangle (tangle)\n \ttangle-a (tag: tangle-a)\n \tEOF\n@@ -1068,7 +1068,7 @@ cat >expect <<\\EOF\n |\\  Merge: MERGE_PARENTS\n | | Author: A U Thor <author@example.com>\n | |\n-| |     Merge branch 'tangle'\n+| |     Merge branch 'tangle' into master\n | |\n | *   commit COMMIT_OBJECT_NAME\n | |\\  Merge: MERGE_PARENTS\n@@ -1102,7 +1102,7 @@ cat >expect <<\\EOF\n |\\ \\ \\ \\  Merge: MERGE_PARENTS\n | | | | | Author: A U Thor <author@example.com>\n | | | | |\n-| | | | |     Merge branch 'side'\n+| | | | |     Merge branch 'side' into master\n | | | | |\n | * | | | commit COMMIT_OBJECT_NAME\n | | |_|/  Author: A U Thor <author@example.com>\n@@ -1343,7 +1343,7 @@ cat >expect <<\\EOF\n *** |\\  Merge: MERGE_PARENTS\n *** | | Author: A U Thor <author@example.com>\n *** | |\n-*** | |     Merge branch 'tangle'\n+*** | |     Merge branch 'tangle' into master\n *** | |\n *** | *   commit COMMIT_OBJECT_NAME\n *** | |\\  Merge: MERGE_PARENTS\n@@ -1377,7 +1377,7 @@ cat >expect <<\\EOF\n *** |\\ \\ \\ \\  Merge: MERGE_PARENTS\n *** | | | | | Author: A U Thor <author@example.com>\n *** | | | | |\n-*** | | | | |     Merge branch 'side'\n+*** | | | | |     Merge branch 'side' into master\n *** | | | | |\n *** | * | | | commit COMMIT_OBJECT_NAME\n *** | | |_|/  Author: A U Thor <author@example.com>\n@@ -1540,8 +1540,8 @@ cat >expect <<-\\EOF\n * reach\n |\n | A\treach.t\n-* Merge branch 'tangle'\n-*   Merge branch 'side'\n+* Merge branch 'tangle' into master\n+*   Merge branch 'side' into master\n |\\\n | * side-2\n |\n@@ -1562,8 +1562,8 @@ cat >expect <<-\\EOF\n * reach\n |\n | reach.t\n-* Merge branch 'tangle'\n-*   Merge branch 'side'\n+* Merge branch 'tangle' into master\n+*   Merge branch 'side' into master\n |\\\n | * side-2\n |\ndiff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh\nindex e4c2a6eca4..2b3fd498d0 100755\n--- a/t/t6200-fmt-merge-msg.sh\n+++ b/t/t6200-fmt-merge-msg.sh\n@@ -79,7 +79,7 @@ test_expect_success GPG 'set up a signed tag' '\n '\n \n test_expect_success 'message for merging local branch' '\n-\techo \"Merge branch ${apos}left${apos}\" >expected &&\n+\techo \"Merge branch ${apos}left${apos} into master\" >expected &&\n \n \tgit checkout master &&\n \tgit fetch . left &&\n@@ -107,7 +107,7 @@ test_expect_success GPG 'message for merging local tag signed by unknown key' '\n '\n \n test_expect_success 'message for merging external branch' '\n-\techo \"Merge branch ${apos}left${apos} of $(pwd)\" >expected &&\n+\techo \"Merge branch ${apos}left${apos} of $(pwd) into master\" >expected &&\n \n \tgit checkout master &&\n \tgit fetch \"$(pwd)\" left &&\n@@ -118,7 +118,7 @@ test_expect_success 'message for merging external branch' '\n \n test_expect_success '[merge] summary/log configuration' '\n \tcat >expected <<-EOF &&\n-\tMerge branch ${apos}left${apos}\n+\tMerge branch ${apos}left${apos} into master\n \n \t# By Another Author (3) and A U Thor (2)\n \t# Via Another Committer\n@@ -160,7 +160,7 @@ test_expect_success 'setup FETCH_HEAD' '\n \n test_expect_success 'merge.log=3 limits shortlog length' '\n \tcat >expected <<-EOF &&\n-\tMerge branch ${apos}left${apos}\n+\tMerge branch ${apos}left${apos} into master\n \n \t# By Another Author (3) and A U Thor (2)\n \t# Via Another Committer\n@@ -177,7 +177,7 @@ test_expect_success 'merge.log=3 limits shortlog length' '\n \n test_expect_success 'merge.log=5 shows all 5 commits' '\n \tcat >expected <<-EOF &&\n-\tMerge branch ${apos}left${apos}\n+\tMerge branch ${apos}left${apos} into master\n \n \t# By Another Author (3) and A U Thor (2)\n \t# Via Another Committer\n@@ -195,7 +195,7 @@ test_expect_success 'merge.log=5 shows all 5 commits' '\n \n test_expect_success '--log=5 with custom comment character' '\n \tcat >expected <<-EOF &&\n-\tMerge branch ${apos}left${apos}\n+\tMerge branch ${apos}left${apos} into master\n \n \tx By Another Author (3) and A U Thor (2)\n \tx Via Another Committer\n@@ -212,14 +212,14 @@ test_expect_success '--log=5 with custom comment character' '\n '\n \n test_expect_success 'merge.log=0 disables shortlog' '\n-\techo \"Merge branch ${apos}left${apos}\" >expected &&\n+\techo \"Merge branch ${apos}left${apos} into master\" >expected &&\n \tgit -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&\n \ttest_cmp expected actual\n '\n \n test_expect_success '--log=3 limits shortlog length' '\n \tcat >expected <<-EOF &&\n-\tMerge branch ${apos}left${apos}\n+\tMerge branch ${apos}left${apos} into master\n \n \t# By Another Author (3) and A U Thor (2)\n \t# Via Another Committer\n@@ -236,7 +236,7 @@ test_expect_success '--log=3 limits shortlog length' '\n \n test_expect_success '--log=5 shows all 5 commits' '\n \tcat >expected <<-EOF &&\n-\tMerge branch ${apos}left${apos}\n+\tMerge branch ${apos}left${apos} into master\n \n \t# By Another Author (3) and A U Thor (2)\n \t# Via Another Committer\n@@ -253,13 +253,13 @@ test_expect_success '--log=5 shows all 5 commits' '\n '\n \n test_expect_success '--no-log disables shortlog' '\n-\techo \"Merge branch ${apos}left${apos}\" >expected &&\n+\techo \"Merge branch ${apos}left${apos} into master\" >expected &&\n \tgit fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&\n \ttest_cmp expected actual\n '\n \n test_expect_success '--log=0 disables shortlog' '\n-\techo \"Merge branch ${apos}left${apos}\" >expected &&\n+\techo \"Merge branch ${apos}left${apos} into master\" >expected &&\n \tgit fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&\n \ttest_cmp expected actual\n '\n@@ -300,7 +300,7 @@ test_expect_success 'fmt-merge-msg -m' '\n \n test_expect_success 'setup: expected shortlog for two branches' '\n \tcat >expected <<-EOF\n-\tMerge branches ${apos}left${apos} and ${apos}right${apos}\n+\tMerge branches ${apos}left${apos} and ${apos}right${apos} into master\n \n \t# By Another Author (3) and A U Thor (2)\n \t# Via Another Committer\n@@ -397,7 +397,7 @@ test_expect_success 'merge-msg with nothing to merge' '\n \n test_expect_success 'merge-msg tag' '\n \tcat >expected <<-EOF &&\n-\tMerge tag ${apos}tag-r3${apos}\n+\tMerge tag ${apos}tag-r3${apos} into master\n \n \t* tag ${apos}tag-r3${apos}:\n \t  Right #3\n@@ -418,7 +418,7 @@ test_expect_success 'merge-msg tag' '\n \n test_expect_success 'merge-msg two tags' '\n \tcat >expected <<-EOF &&\n-\tMerge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}\n+\tMerge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos} into master\n \n \t* tag ${apos}tag-r3${apos}:\n \t  Right #3\n@@ -448,7 +448,7 @@ test_expect_success 'merge-msg two tags' '\n \n test_expect_success 'merge-msg tag and branch' '\n \tcat >expected <<-EOF &&\n-\tMerge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}\n+\tMerge branch ${apos}left${apos}, tag ${apos}tag-r3${apos} into master\n \n \t* tag ${apos}tag-r3${apos}:\n \t  Right #3\n@@ -479,7 +479,7 @@ test_expect_success 'merge-msg tag and branch' '\n test_expect_success 'merge-msg lots of commits' '\n \t{\n \t\tcat <<-EOF &&\n-\t\tMerge branch ${apos}long${apos}\n+\t\tMerge branch ${apos}long${apos} into master\n \n \t\t* long: (35 commits)\n \t\tEOF\n@@ -516,7 +516,7 @@ test_expect_success 'merge-msg with \"merging\" an annotated tag' '\n \tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n \t{\n \t\tcat <<-\\EOF\n-\t\tMerge tag '\\''annote'\\''\n+\t\tMerge tag '\\''annote'\\'' into master\n \n \t\tAn annotated one\n \n@@ -531,7 +531,7 @@ test_expect_success 'merge-msg with \"merging\" an annotated tag' '\n \tgit merge --no-commit --no-ff $annote &&\n \t{\n \t\tcat <<-EOF\n-\t\tMerge tag '\\''$annote'\\''\n+\t\tMerge tag '\\''$annote'\\'' into master\n \n \t\tAn annotated one\n \ndiff --git a/t/t7600-merge.sh b/t/t7600-merge.sh\nindex 5883a6adc3..1d45f9a4ed 100755\n--- a/t/t7600-merge.sh\n+++ b/t/t7600-merge.sh\n@@ -14,9 +14,9 @@ Testing basic merge operations/option parsing.\n     ! [c4] c4\n      ! [c5] c5\n       ! [c6] c6\n-       * [master] Merge commit 'c1'\n+       * [master] Merge commit 'c1' into master\n --------\n-       - [master] Merge commit 'c1'\n+       - [master] Merge commit 'c1' into master\n  +     * [c1] commit 1\n       +  [c6] c6\n      +   [c5] c5\n@@ -44,8 +44,8 @@ test_write_lines '1 X' 2 '3 X' 4 '5 X' 6 7 8 '9 X' >result.1-3-5-9\n test_write_lines 1 2 3 4 5 6 7 8 '9 Z' >result.9z\n \n create_merge_msgs () {\n-\techo \"Merge tag 'c2'\" >msg.1-5 &&\n-\techo \"Merge tags 'c2' and 'c3'\" >msg.1-5-9 &&\n+\techo \"Merge tag 'c2' into master\" >msg.1-5 &&\n+\techo \"Merge tags 'c2' and 'c3' into master\" >msg.1-5-9 &&\n \t{\n \t\techo \"Squashed commit of the following:\" &&\n \t\techo &&\n@@ -258,7 +258,7 @@ test_expect_success 'merge c3 with c7 with commit.cleanup = scissors' '\n \tgit commit --no-edit -a &&\n \n \tcat >expect <<-\\EOF &&\n-\tMerge tag '\"'\"'c7'\"'\"'\n+\tMerge tag '\"'\"'c7'\"'\"' into master\n \n \t# ------------------------ >8 ------------------------\n \t# Do not modify or remove the line above.\n@@ -808,10 +808,10 @@ test_expect_success 'merge with conflicted --autostash changes' '\n '\n \n cat >expected.branch <<\\EOF\n-Merge branch 'c5-branch' (early part)\n+Merge branch 'c5-branch' (early part) into master\n EOF\n cat >expected.tag <<\\EOF\n-Merge commit 'c5~1'\n+Merge commit 'c5~1' into master\n EOF\n \n test_expect_success 'merge early part of c2' '\ndiff --git a/t/t7608-merge-messages.sh b/t/t7608-merge-messages.sh\nindex 8e7e0a5865..2af33f195b 100755\n--- a/t/t7608-merge-messages.sh\n+++ b/t/t7608-merge-messages.sh\n@@ -16,7 +16,7 @@ test_expect_success 'merge local branch' '\n \tgit checkout master &&\n \ttest_commit master-2 &&\n \tgit merge local-branch &&\n-\tcheck_oneline \"Merge branch Qlocal-branchQ\"\n+\tcheck_oneline \"Merge branch Qlocal-branchQ into master\"\n '\n \n test_expect_success 'merge octopus branches' '\n@@ -26,7 +26,7 @@ test_expect_success 'merge octopus branches' '\n \ttest_commit octopus-2 &&\n \tgit checkout master &&\n \tgit merge octopus-a octopus-b &&\n-\tcheck_oneline \"Merge branches Qoctopus-aQ and Qoctopus-bQ\"\n+\tcheck_oneline \"Merge branches Qoctopus-aQ and Qoctopus-bQ into master\"\n '\n \n test_expect_success 'merge tag' '\n@@ -35,7 +35,7 @@ test_expect_success 'merge tag' '\n \tgit checkout master &&\n \ttest_commit master-3 &&\n \tgit merge tag-1 &&\n-\tcheck_oneline \"Merge tag Qtag-1Q\"\n+\tcheck_oneline \"Merge tag Qtag-1Q into master\"\n '\n \n test_expect_success 'ambiguous tag' '\n@@ -44,7 +44,7 @@ test_expect_success 'ambiguous tag' '\n \tgit checkout master &&\n \ttest_commit master-4 &&\n \tgit merge ambiguous &&\n-\tcheck_oneline \"Merge tag QambiguousQ\"\n+\tcheck_oneline \"Merge tag QambiguousQ into master\"\n '\n \n test_expect_success 'remote-tracking branch' '\n@@ -54,7 +54,7 @@ test_expect_success 'remote-tracking branch' '\n \tgit checkout master &&\n \ttest_commit master-5 &&\n \tgit merge origin/master &&\n-\tcheck_oneline \"Merge remote-tracking branch Qorigin/masterQ\"\n+\tcheck_oneline \"Merge remote-tracking branch Qorigin/masterQ into master\"\n '\n \n test_done\n-- \ngitgitgadget\n\n"},{"id":"400461","messageId":"1aa0e63785c5c64cc0d45f51f5ce4b45a16e89c8.1592951611.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v3.git.1592951611.gitgitgadget@gmail.com","subject":"[PATCH v3 8/8] testsvn: respect `init.defaultBranch`","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-23T22:33:30Z","receivedAt":"2020-06-23T22:47:40Z","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\nThe default name of the initial branch in new repositories can now be\nconfigured. The `testsvn` remote helper translates the remote Subversion\nrepository's branch name `trunk` to the hard-coded name `master`.\nClearly, the intention was to make the name align with Git's defaults.\n\nSo while we are not talking about a newly-created repository in the\n`testsvn` context, it is a newly-created _Git_ repository, si it _still_\nmakes sense to use the overridden default name for the initial branch\nwhenever users configured it.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n remote-testsvn.c      | 10 +++++++---\n t/t9020-remote-svn.sh |  6 ++++++\n 2 files changed, 13 insertions(+), 3 deletions(-)\n\ndiff --git a/remote-testsvn.c b/remote-testsvn.c\nindex 3af708c5b6..cde39b94fb 100644\n--- a/remote-testsvn.c\n+++ b/remote-testsvn.c\n@@ -13,7 +13,7 @@\n static const char *url;\n static int dump_from_file;\n static const char *private_ref;\n-static const char *remote_ref = \"refs/heads/master\";\n+static char *remote_ref;\n static const char *marksfilename, *notes_ref;\n struct rev_note { unsigned int rev_nr; };\n \n@@ -286,7 +286,7 @@ int cmd_main(int argc, const char **argv)\n \t\t\tprivate_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT,\n \t\t\tnotes_ref_sb = STRBUF_INIT;\n \tstatic struct remote *remote;\n-\tconst char *url_in;\n+\tconst char *url_in, *remote_ref_short;\n \n \tsetup_git_directory();\n \tif (argc < 2 || argc > 3) {\n@@ -294,6 +294,9 @@ int cmd_main(int argc, const char **argv)\n \t\treturn 1;\n \t}\n \n+\tremote_ref_short = git_default_branch_name();\n+\tremote_ref = xstrfmt(\"refs/heads/%s\", remote_ref_short);\n+\n \tremote = remote_get(argv[1]);\n \turl_in = (argc == 3) ? argv[2] : remote->url[0];\n \n@@ -306,7 +309,8 @@ int cmd_main(int argc, const char **argv)\n \t\turl = url_sb.buf;\n \t}\n \n-\tstrbuf_addf(&private_ref_sb, \"refs/svn/%s/master\", remote->name);\n+\tstrbuf_addf(&private_ref_sb, \"refs/svn/%s/%s\",\n+\t\t    remote->name, remote_ref_short);\n \tprivate_ref = private_ref_sb.buf;\n \n \tstrbuf_addf(&notes_ref_sb, \"refs/notes/%s/revs\", remote->name);\ndiff --git a/t/t9020-remote-svn.sh b/t/t9020-remote-svn.sh\nindex 9fcfa969a9..754c4a3284 100755\n--- a/t/t9020-remote-svn.sh\n+++ b/t/t9020-remote-svn.sh\n@@ -84,6 +84,12 @@ test_expect_success REMOTE_SVN 'incremental imports must lead to the same head'\n \ttest_cmp master.good .git/refs/remotes/svnsim/master\n '\n \n+test_expect_success REMOTE_SVN 'respects configured default initial branch' '\n+\tgit -c init.defaultBranch=trunk remote add -f trunk \\\n+\t\t\"testsvn::file://$TEST_DIRECTORY/t9154/svn.dump\" &&\n+\tgit rev-parse --verify refs/remotes/trunk/trunk\n+'\n+\n test_debug 'git branch -a'\n \n test_done\n-- \ngitgitgadget\n"},{"id":"400463","messageId":"e8a6587c1a783476413277296c6ce3db74e217e6.1592951611.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v3.git.1592951611.gitgitgadget@gmail.com","subject":"[PATCH v3 4/8] init: allow specifying the initial branch name for the new repository","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-23T22:33:26Z","receivedAt":"2020-06-23T22:47:44Z","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\nThere is a growing number of projects and companies desiring to change\nthe main branch name of their repositories (see e.g.\nhttps://twitter.com/mislav/status/1270388510684598272 for background on\nthis).\n\nTo change that branch name for new repositories, currently the only way\nto do that automatically is by copying all of Git's template directory,\nthen hard-coding the desired default branch name into the `.git/HEAD`\nfile, and then configuring `init.templateDir` to point to those copied\ntemplate files.\n\nTo make this process much less cumbersome, let's introduce a new option:\n`--initial-branch=<branch-name>`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/git-init.txt |  7 +++++++\n builtin/clone.c            |  3 ++-\n builtin/init-db.c          | 34 +++++++++++++++++++++++++++-------\n cache.h                    |  2 +-\n t/t0001-init.sh            | 13 +++++++++++++\n 5 files changed, 50 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\nindex adc6adfd38..36dccc6e52 100644\n--- a/Documentation/git-init.txt\n+++ b/Documentation/git-init.txt\n@@ -11,6 +11,7 @@ SYNOPSIS\n [verse]\n 'git init' [-q | --quiet] [--bare] [--template=<template_directory>]\n \t  [--separate-git-dir <git dir>] [--object-format=<format]\n+\t  [-b <branch-name> | --initial-branch=<branch-name>]\n \t  [--shared[=<permissions>]] [directory]\n \n \n@@ -67,6 +68,12 @@ repository.\n +\n If this is reinitialization, the repository will be moved to the specified path.\n \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+\n --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::\n \n Specify that the Git repository is to be shared amongst several users.  This\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 2a8e3aaaed..b751bdf13e 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -1111,7 +1111,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \n-\tinit_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, INIT_DB_QUIET);\n+\tinit_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,\n+\t\tINIT_DB_QUIET);\n \n \tif (real_git_dir)\n \t\tgit_dir = real_git_dir;\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 0b7222e718..a898153901 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -203,6 +203,7 @@ void initialize_repository_version(int hash_algo)\n \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 {\n \tstruct stat st1;\n@@ -258,16 +259,29 @@ static int create_default_files(const char *template_path,\n \t\tdie(\"failed to set up refs db: %s\", err.buf);\n \n \t/*\n-\t * Create the default symlink from \".git/HEAD\" to the \"master\"\n-\t * branch, if it does not exist yet.\n+\t * Create the default symlink from \".git/HEAD\" to the default\n+\t * branch name, if it does not exist yet.\n \t */\n \tpath = git_path_buf(&buf, \"HEAD\");\n \treinit = (!access(path, R_OK)\n \t\t  || readlink(path, junk, sizeof(junk)-1) != -1);\n \tif (!reinit) {\n-\t\tif (create_symref(\"HEAD\", \"refs/heads/master\", NULL) < 0)\n+\t\tchar *ref;\n+\n+\t\tif (!initial_branch)\n+\t\t\tinitial_branch = \"master\";\n+\n+\t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n+\t\tif (check_refname_format(ref, 0) < 0)\n+\t\t\tdie(_(\"invalid initial branch name: '%s'\"),\n+\t\t\t    initial_branch);\n+\n+\t\tif (create_symref(\"HEAD\", ref, NULL) < 0)\n \t\t\texit(1);\n-\t}\n+\t\tfree(ref);\n+\t} else if (initial_branch)\n+\t\twarning(_(\"re-init: ignoring --initial-branch=%s\"),\n+\t\t\tinitial_branch);\n \n \tinitialize_repository_version(fmt->hash_algo);\n \n@@ -383,7 +397,8 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash\n }\n \n int init_db(const char *git_dir, const char *real_git_dir,\n-\t    const char *template_dir, int hash, unsigned int flags)\n+\t    const char *template_dir, int hash, const char *initial_branch,\n+\t    unsigned int flags)\n {\n \tint reinit;\n \tint exist_ok = flags & INIT_DB_EXIST_OK;\n@@ -425,7 +440,8 @@ int init_db(const char *git_dir, const char *real_git_dir,\n \n \tvalidate_hash_algorithm(&repo_fmt, hash);\n \n-\treinit = create_default_files(template_dir, original_git_dir, &repo_fmt);\n+\treinit = create_default_files(template_dir, original_git_dir,\n+\t\t\t\t      initial_branch, &repo_fmt);\n \n \tcreate_object_directory();\n \n@@ -528,6 +544,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \tconst char *template_dir = NULL;\n \tunsigned int flags = 0;\n \tconst char *object_format = NULL;\n+\tconst char *initial_branch = NULL;\n \tint hash_algo = GIT_HASH_UNKNOWN;\n \tconst struct option init_db_options[] = {\n \t\tOPT_STRING(0, \"template\", &template_dir, N_(\"template-directory\"),\n@@ -541,6 +558,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \t\tOPT_BIT('q', \"quiet\", &flags, N_(\"be quiet\"), INIT_DB_QUIET),\n \t\tOPT_STRING(0, \"separate-git-dir\", &real_git_dir, N_(\"gitdir\"),\n \t\t\t   N_(\"separate git dir from working tree\")),\n+\t\tOPT_STRING('b', \"initial-branch\", &initial_branch, N_(\"name\"),\n+\t\t\t   N_(\"override the name of the initial branch\")),\n \t\tOPT_STRING(0, \"object-format\", &object_format, N_(\"hash\"),\n \t\t\t   N_(\"specify the hash algorithm to use\")),\n \t\tOPT_END()\n@@ -652,5 +671,6 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \tUNLEAK(work_tree);\n \n \tflags |= INIT_DB_EXIST_OK;\n-\treturn init_db(git_dir, real_git_dir, template_dir, hash_algo, flags);\n+\treturn init_db(git_dir, real_git_dir, template_dir, hash_algo,\n+\t\t       initial_branch, flags);\n }\ndiff --git a/cache.h b/cache.h\nindex 0f0485ecfe..654426460c 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -628,7 +628,7 @@ int path_inside_repo(const char *prefix, const char *path);\n \n int init_db(const char *git_dir, const char *real_git_dir,\n \t    const char *template_dir, int hash_algo,\n-\t    unsigned int flags);\n+\t    const char *initial_branch, unsigned int flags);\n void initialize_repository_version(int hash_algo);\n \n void sanitize_stdfds(void);\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 1edd5aeb8f..61837ca25f 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -464,4 +464,17 @@ test_expect_success MINGW 'redirect std handles' '\n \tgrep \"Needed a single revision\" output.txt\n '\n \n+test_expect_success '--initial-branch' '\n+\tgit init --initial-branch=hello initial-branch-option &&\n+\tgit -C initial-branch-option symbolic-ref HEAD >actual &&\n+\techo refs/heads/hello >expect &&\n+\ttest_cmp expect actual &&\n+\n+\t: re-initializing should not change the branch name &&\n+\tgit init --initial-branch=ignore initial-branch-option 2>err &&\n+\ttest_i18ngrep \"ignoring --initial-branch\" err &&\n+\tgit -C initial-branch-option symbolic-ref HEAD >actual &&\n+\tgrep hello actual\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"400464","messageId":"00a1b281e5ae4cf14435a6745cc55fc248f378a5.1592951611.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v3.git.1592951611.gitgitgadget@gmail.com","subject":"[PATCH v3 7/8] remote: use the configured default branch name when appropriate","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-23T22:33:29Z","receivedAt":"2020-06-23T22:47: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\nWhen guessing the default branch name of a remote, and there are no refs\nto guess from, we want to go with the preference specified by the user\nfor the fall-back, i.e. the default name to be used for the initial\nbranch of new repositories (because as far as the user is concerned, a\nremote that has no branches yet is a new repository).\n\nAt the same time, when talking to an older Git server that does not\nreport a symref for `HEAD` (but instead reports a commit hash), let's\ntry to guess the configured default branch name first. If it does not\nmatch the reported commit hash, let's fall back to `master` as before.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n remote.c                 | 14 +++++++++++---\n t/t5606-clone-options.sh | 11 ++++++++++-\n 2 files changed, 21 insertions(+), 4 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex 534c6426f1..965129adc3 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -276,7 +276,7 @@ static void read_branches_file(struct remote *remote)\n \n \t/*\n \t * The branches file would have URL and optionally\n-\t * #branch specified.  The \"master\" (or specified) branch is\n+\t * #branch specified.  The main (or specified) branch is\n \t * fetched and stored in the local branch matching the\n \t * remote name.\n \t */\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 = \"master\";\n+\t\tfrag = (char *)git_default_branch_name();\n \n \tadd_url_alias(remote, strbuf_detach(&buf, NULL));\n \tstrbuf_addf(&buf, \"refs/heads/%s:refs/heads/%s\",\n@@ -2097,8 +2097,16 @@ struct ref *guess_remote_head(const struct ref *head,\n \tif (head->symref)\n \t\treturn copy_ref(find_ref_by_name(refs, head->symref));\n \n-\t/* If refs/heads/master could be right, it is. */\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+\n+\t\tr = find_ref_by_name(refs, ref);\n+\t\tfree(ref);\n+\t\tif (r && oideq(&r->old_oid, &head->old_oid))\n+\t\t\treturn copy_ref(r);\n+\n+\t\t/* Fall back to the hard-coded historical default */\n \t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n \t\tif (r && oideq(&r->old_oid, &head->old_oid))\n \t\t\treturn copy_ref(r);\ndiff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh\nindex 286bfd93ac..e69427f881 100755\n--- a/t/t5606-clone-options.sh\n+++ b/t/t5606-clone-options.sh\n@@ -47,7 +47,16 @@ test_expect_success 'guesses initial branch name correctly' '\n \ttest_commit -C initial-branch no-spoilers &&\n \tgit -C initial-branch branch abc guess &&\n \tgit clone initial-branch is-it &&\n-\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD)\n+\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD) &&\n+\n+\tgit -c init.defaultBranch=none init --bare no-head &&\n+\tgit -C initial-branch push ../no-head guess abc &&\n+\tgit clone no-head is-it2 &&\n+\ttest_must_fail git -C is-it2 symbolic-ref refs/remotes/origin/HEAD &&\n+\tgit -C no-head update-ref --no-deref HEAD refs/heads/guess &&\n+\tgit -c init.defaultBranch=guess clone no-head is-it3 &&\n+\ttest refs/remotes/origin/guess = \\\n+\t\t$(git -C is-it3 symbolic-ref refs/remotes/origin/HEAD)\n '\n \n test_done\n-- \ngitgitgadget\n\n"},{"id":"400465","messageId":"6bda69541b12e93cfcf7b841b8691296dc82eeba.1592951611.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v3.git.1592951611.gitgitgadget@gmail.com","subject":"[PATCH v3 3/8] submodule: use a better fall-back for missing remote.<name>.branch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-23T22:33:25Z","receivedAt":"2020-06-23T22:48:00Z","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\nWhen `remote.<name>.branch` is not configured, `git submodule update`\ncurrently falls back to using the branch name `master`. A much better\nidea, however, is to use `HEAD`: on all Git servers running reasonably\nrecent Git versions, the symref `HEAD` points to the main branch.\n\nNote: t7419 demonstrates that there _might_ be use cases out there that\n_expect_ `git submodule update --remote` to update submodules to the\nremote `master` branch even if the remote `HEAD` points to another\nbranch. Arguably, this patch makes the behavior more intuitive, but\nthere is a slight possibility that this might cause regressions in\nobscure setups.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/git-submodule.txt |  4 ++--\n builtin/submodule--helper.c     |  2 +-\n t/t7406-submodule-update.sh     | 16 ++++++++++++++++\n t/t7419-submodule-set-branch.sh |  7 +++++--\n 4 files changed, 24 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex c9ed2bf3d5..b20f85e622 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -284,7 +284,7 @@ OPTIONS\n \t`.gitmodules` for `update --remote`.  A special value of `.` is used to\n \tindicate that the name of the branch in the submodule should be the\n \tsame name as the current branch in the current repository.  If the\n-\toption is not specified, it defaults to 'master'.\n+\toption is not specified, it defaults to 'HEAD'.\n \n -f::\n --force::\n@@ -322,7 +322,7 @@ OPTIONS\n \tthe superproject's recorded SHA-1 to update the submodule, use the\n \tstatus of the submodule's remote-tracking branch.  The remote used\n \tis branch's remote (`branch.<name>.remote`), defaulting to `origin`.\n-\tThe remote branch used defaults to `master`, but the branch name may\n+\tThe remote branch used defaults to `HEAD`, but the branch name may\n \tbe overridden by setting the `submodule.<name>.branch` option in\n \teither `.gitmodules` or `.git/config` (with `.git/config` taking\n \tprecedence).\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 46c03d2a12..f55f7b7704 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1981,7 +1981,7 @@ static const char *remote_submodule_branch(const char *path)\n \tfree(key);\n \n \tif (!branch)\n-\t\treturn \"master\";\n+\t\treturn \"HEAD\";\n \n \tif (!strcmp(branch, \".\")) {\n \t\tconst char *refname = resolve_ref_unsafe(\"HEAD\", 0, NULL, NULL);\ndiff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\nindex 4fb447a143..aa19ff3a2e 100755\n--- a/t/t7406-submodule-update.sh\n+++ b/t/t7406-submodule-update.sh\n@@ -70,6 +70,22 @@ test_expect_success 'setup a submodule tree' '\n \t)\n '\n \n+test_expect_success 'update --remote falls back to using HEAD' '\n+\ttest_create_repo main-branch-submodule &&\n+\ttest_commit -C main-branch-submodule initial &&\n+\n+\ttest_create_repo main-branch &&\n+\tgit -C main-branch submodule add ../main-branch-submodule &&\n+\tgit -C main-branch commit -m add-submodule &&\n+\n+\tgit -C main-branch-submodule switch -c hello &&\n+\ttest_commit -C main-branch-submodule world &&\n+\n+\tgit clone --recursive main-branch main-branch-clone &&\n+\tgit -C main-branch-clone submodule update --remote main-branch-submodule &&\n+\ttest_path_exists main-branch-clone/main-branch-submodule/world.t\n+'\n+\n test_expect_success 'submodule update detaching the HEAD ' '\n \t(cd super/submodule &&\n \t git reset --hard HEAD~1\ndiff --git a/t/t7419-submodule-set-branch.sh b/t/t7419-submodule-set-branch.sh\nindex fd25f786a3..3b925c302f 100755\n--- a/t/t7419-submodule-set-branch.sh\n+++ b/t/t7419-submodule-set-branch.sh\n@@ -52,12 +52,13 @@ test_expect_success 'test submodule set-branch --branch' '\n '\n \n test_expect_success 'test submodule set-branch --default' '\n+\ttest_commit -C submodule c &&\n \t(cd super &&\n \t\tgit submodule set-branch --default submodule &&\n \t\t! grep branch .gitmodules &&\n \t\tgit submodule update --remote &&\n \t\tcat <<-\\EOF >expect &&\n-\t\ta\n+\t\tc\n \t\tEOF\n \t\tgit -C submodule show -s --pretty=%s >actual &&\n \t\ttest_cmp expect actual\n@@ -65,6 +66,7 @@ test_expect_success 'test submodule set-branch --default' '\n '\n \n test_expect_success 'test submodule set-branch -b' '\n+\ttest_commit -C submodule b &&\n \t(cd super &&\n \t\tgit submodule set-branch -b topic submodule &&\n \t\tgrep \"branch = topic\" .gitmodules &&\n@@ -78,12 +80,13 @@ test_expect_success 'test submodule set-branch -b' '\n '\n \n test_expect_success 'test submodule set-branch -d' '\n+\ttest_commit -C submodule d &&\n \t(cd super &&\n \t\tgit submodule set-branch -d submodule &&\n \t\t! grep branch .gitmodules &&\n \t\tgit submodule update --remote &&\n \t\tcat <<-\\EOF >expect &&\n-\t\ta\n+\t\td\n \t\tEOF\n \t\tgit -C submodule show -s --pretty=%s >actual &&\n \t\ttest_cmp expect actual\n-- \ngitgitgadget\n\n"},{"id":"400466","messageId":"c0d74cedd1571e0d791ec123fc4d0e1ec98e7862.1592951611.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v3.git.1592951611.gitgitgadget@gmail.com","subject":"[PATCH v3 6/8] clone: use configured default branch name when appropriate","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-23T22:33:28Z","receivedAt":"2020-06-23T22:48: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\nWhen cloning a repository without any branches, Git chooses a default\nbranch name for the as-yet unborn branch.\n\nAs part of the implicit initialization of the local repository, Git just\nlearned to respect `init.defaultBranch` to choose a different initial\nbranch name. We now really want that branch name to be used as a\nfall-back.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/config/init.txt |  4 ++--\n builtin/clone.c               | 10 +++++++---\n t/t5606-clone-options.sh      | 15 +++++++++++++++\n 3 files changed, 24 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/config/init.txt b/Documentation/config/init.txt\nindex 6ae4a38416..dc77f8c844 100644\n--- a/Documentation/config/init.txt\n+++ b/Documentation/config/init.txt\n@@ -3,5 +3,5 @@ init.templateDir::\n \t(See the \"TEMPLATE DIRECTORY\" section of linkgit:git-init[1].)\n \n init.defaultBranch::\n-\tAllows overriding the default branch name when initializing\n-\ta new repository.\n+\tAllows overriding the default branch name e.g. when initializing\n+\ta new repository or when cloning an empty repository.\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex b751bdf13e..9a3f91b268 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -1267,9 +1267,13 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\tremote_head_points_at = NULL;\n \t\tremote_head = NULL;\n \t\toption_no_checkout = 1;\n-\t\tif (!option_bare)\n-\t\t\tinstall_branch_config(0, \"master\", option_origin,\n-\t\t\t\t\t      \"refs/heads/master\");\n+\t\tif (!option_bare) {\n+\t\t\tconst char *branch = git_default_branch_name();\n+\t\t\tchar *ref = xstrfmt(\"refs/heads/%s\", branch);\n+\n+\t\t\tinstall_branch_config(0, branch, option_origin, ref);\n+\t\t\tfree(ref);\n+\t\t}\n \t}\n \n \twrite_refspec_config(src_ref_prefix, our_head_points_at,\ndiff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh\nindex 9e24ec88e6..286bfd93ac 100755\n--- a/t/t5606-clone-options.sh\n+++ b/t/t5606-clone-options.sh\n@@ -35,4 +35,19 @@ test_expect_success 'redirected clone -v does show progress' '\n \n '\n \n+test_expect_success 'chooses correct default initial branch name' '\n+\tgit init --bare empty &&\n+\tgit -c init.defaultBranch=up clone empty whats-up &&\n+\ttest refs/heads/up = $(git -C whats-up symbolic-ref HEAD) &&\n+\ttest refs/heads/up = $(git -C whats-up config branch.up.merge)\n+'\n+\n+test_expect_success 'guesses initial branch name correctly' '\n+\tgit init --initial-branch=guess initial-branch &&\n+\ttest_commit -C initial-branch no-spoilers &&\n+\tgit -C initial-branch branch abc guess &&\n+\tgit clone initial-branch is-it &&\n+\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD)\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"400467","messageId":"a500e0f214a0ea4bf5cf4e26f688ae68a0b84bcd.1592951611.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v3.git.1592951611.gitgitgadget@gmail.com","subject":"[PATCH v3 5/8] init: allow setting the default for the initial branch name via the config","fromName":"Don Goodman-Wilson via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-23T22:33:27Z","receivedAt":"2020-06-23T22:48:05Z","isPatch":true,"sender":{"key":"don@goodman-wilson.com","avatar":"https://gravatar.com/avatar/9819ec326d55ea4c398b8ff018dcf63b4e9603b00db9cc019c725bffc9c05d17?d=mp&s=160"},"body":"From: Don Goodman-Wilson <don@goodman-wilson.com>\n\nWe just introduced the command-line option\n`--initial-branch=<branch-name>` to allow initializing a new repository\nwith a different initial branch than the hard-coded one.\n\nTo allow users to override the initial branch name more permanently\n(i.e. without having to specify the name manually for each and every\n`git init` invocation), let's introduce the `init.defaultBranch` config\nsetting.\n\nHelped-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nHelped-by: Derrick Stolee <dstolee@microsoft.com>\nSigned-off-by: Don Goodman-Wilson <don@goodman-wilson.com>\n---\n Documentation/config/init.txt |  4 ++++\n builtin/init-db.c             |  2 +-\n refs.c                        | 30 ++++++++++++++++++++++++++++++\n refs.h                        |  9 +++++++++\n t/t0001-init.sh               | 13 +++++++++++++\n 5 files changed, 57 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/config/init.txt b/Documentation/config/init.txt\nindex 46fa8c6a08..6ae4a38416 100644\n--- a/Documentation/config/init.txt\n+++ b/Documentation/config/init.txt\n@@ -1,3 +1,7 @@\n init.templateDir::\n \tSpecify the directory from which templates will be copied.\n \t(See the \"TEMPLATE DIRECTORY\" section of linkgit:git-init[1].)\n+\n+init.defaultBranch::\n+\tAllows overriding the default branch name when initializing\n+\ta new repository.\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex a898153901..b8634b5f35 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -269,7 +269,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 = \"master\";\n+\t\t\tinitial_branch = git_default_branch_name();\n \n \t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n \t\tif (check_refname_format(ref, 0) < 0)\ndiff --git a/refs.c b/refs.c\nindex 224ff66c7b..b98dea5217 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -560,6 +560,36 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n \t\targv_array_pushf(prefixes, *p, len, prefix);\n }\n \n+char *repo_default_branch_name(struct repository *r)\n+{\n+\tconst char *config_key = \"init.defaultbranch\";\n+\tconst char *config_display_key = \"init.defaultBranch\";\n+\tchar *ret = NULL, *full_ref;\n+\n+\tif (repo_config_get_string(r, config_key, &ret) < 0)\n+\t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n+\n+\tif (!ret)\n+\t\tret = xstrdup(\"master\");\n+\n+\tfull_ref = xstrfmt(\"refs/heads/%s\", ret);\n+\tif (check_refname_format(full_ref, 0))\n+\t\tdie(_(\"invalid branch name: %s = %s\"), config_display_key, ret);\n+\tfree(full_ref);\n+\n+\treturn ret;\n+}\n+\n+const char *git_default_branch_name(void)\n+{\n+\tstatic char *ret;\n+\n+\tif (!ret)\n+\t\tret = repo_default_branch_name(the_repository);\n+\n+\treturn ret;\n+}\n+\n /*\n  * *string and *len will only be substituted, and *string returned (for\n  * later free()ing) if the string passed in is a magic short-hand form\ndiff --git a/refs.h b/refs.h\nindex e010f8aec2..f212f8945e 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -154,6 +154,15 @@ int repo_dwim_log(struct repository *r, const char *str, int len, struct object_\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \n+/*\n+ * Retrieves the default branch name for newly-initialized repositories.\n+ *\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+\n /*\n  * A ref_transaction represents a collection of reference updates that\n  * should succeed or fail together.\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 61837ca25f..047197d08f 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -477,4 +477,17 @@ test_expect_success '--initial-branch' '\n \tgrep hello actual\n '\n \n+test_expect_success 'overridden default initial branch name (config)' '\n+\ttest_config_global init.defaultBranch nmb &&\n+\tgit init initial-branch-config &&\n+\tgit -C initial-branch-config symbolic-ref HEAD >actual &&\n+\tgrep nmb actual\n+'\n+\n+test_expect_success 'invalid default branch name' '\n+\ttest_config_global init.defaultBranch \"with space\" &&\n+\ttest_must_fail git init initial-branch-invalid 2>err &&\n+\ttest_i18ngrep \"invalid branch name\" err\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"400468","messageId":"pull.656.v3.git.1592951611.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v2.git.1592225416.gitgitgadget@gmail.com","subject":"[PATCH v3 0/8] Allow overriding the default name of the default branch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-23T22:33:22Z","receivedAt":"2020-06-23T22:48:10Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"A growing number of open source projects aims to avoid the branch name \nmaster due to its negative connotation. See [1] for an existing discussion\non this. The links [2], [3], and [4] describe community-driven ways for\nusers to rename their default branches or use template edits to set a new\ndefault branch name.\n\n[1] \nhttps://lore.kernel.org/git/CAOAHyQwyXC1Z3v7BZAC+Bq6JBaM7FvBenA-1fcqeDV==apdWDg@mail.gmail.com/\n\n[2] https://twitter.com/mislav/status/1270388510684598272\n\n[3] \nhttps://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx\n\n[4] https://github.com/ethomson/retarget_prs\n\nBy necessity, existing repositories require a lot of manual work to move\naway from that branch name, but it should be much easier for new\nrepositories.\n\nThis patch series allows overriding the branch name being used for new\nrepositories' main branch. This can be configured via init.defaultBranch.\n\nThe initial patch was started by newcomer Don Goodman-Wilson, as well as the\nbigger change that morphed into #655, where we demonstrate how to change\nGit's hard-coded default branch name for new repositories to main based on\nthis here patch series, verifying the approach. Thanks for the contribution!\n\nThis series DOES NOT change the default automatically, but only provides an\nopt-in mechanism for interested users. The plan for that is to convert the\ntest scripts incrementally (by introducing GIT_TEST_DEFAULT_MAIN_BRANCH_NAME\n, which overrides init.defaultBranch, and then converting the tricky test\nscripts first, one by one, using that environment variable).\n\nChanges since v2:\n\n * Dropped the fast-export patches, as they have been superseded by Peff's \n   jk/fast-export-anonym\n   [https://github.com/gitgitgadget/git/commits/jk/fast-export-anonym].\n   \n   \n * Adjusted the fmt-merge-msg patch so as to not special-case master anymore\n   (instead of special-casing a specific \"main\" branch).\n   \n   \n * Modified the git submodule patch so that it uses origin/HEAD instead of\n   trying to look for a remote branch with the name indicated by \n   init.defaultBranch.\n   \n   \n\nChanges since v1:\n\n * The modifications to respect GIT_TEST_DEFAULT_BRANCH_NAME have been\n   backed out from this patch series, as they are only relevant once we\n   start converting the test suite to accommodate for a new default main\n   branch name.\n   \n   \n * An error message that started with an upper-case letter was downcased.\n   \n   \n * git_default_branch_name()'s logic was simplified by replacing an if ...\n   else ... by a ternary assignment.\n   \n   \n * The git_default_branch_name() function was renamed to \n   git_main_branch_name() and a corresponding repo_main_branch_name() was\n   introduced.\n   \n   \n * The \"init\" commit message's first paragraph now elaborates a little bit\n   on the reasoning why projects want to move away from the current default\n   branch name.\n   \n   \n * The \"init\" commit was split into two.\n   \n   \n * There are now two config settings: init.defaultBranch (defining the\n   branch name to use when initializing new repositories) and \n   core.mainBranch (which is now configured by init_db(), declaring what the\n   name of the main branch is in this repository).\n   \n   \n * The commits were re-ordered to introduce the concept of core.mainBranch \n   first because technically, this is something that we could do even\n   without changing git init at all.\n   \n   \n * git fast-export --anonymize now always uses the ref name ref0 for the\n   main branch, no matter whether it was overridden or whether the fall-back\n   is in effect.\n   \n   \n * The code comment regarding anonymizing the main branch to ref0 in git\n   fast-export --anonymize was enhanced.\n   \n   \n * A new patch was added to rename core.mainBranch if the main branch is\n   renamed via git branch -m.\n   \n   \n * Added a patch that introduces support for git init\n   --main-branch=<branch-name>.\n   \n   \n * Where possible, I added tests (although I did not try to extend test\n   coverage to all changes: the send-pack.c/transport-helper.c patch only\n   adds a test for the send-pack.c adjustment, for example).\n\nDon Goodman-Wilson (1):\n  init: allow setting the default for the initial branch name via the\n    config\n\nJohannes Schindelin (7):\n  fmt-merge-msg: stop treating `master` specially\n  send-pack/transport-helper: avoid mentioning a particular branch\n  submodule: use a better fall-back for missing remote.<name>.branch\n  init: allow specifying the initial branch name for the new repository\n  clone: use configured default branch name when appropriate\n  remote: use the configured default branch name when appropriate\n  testsvn: respect `init.defaultBranch`\n\n Documentation/config/init.txt                 |  4 ++\n Documentation/git-init.txt                    |  7 ++\n Documentation/git-submodule.txt               |  4 +-\n builtin/clone.c                               | 13 ++--\n builtin/init-db.c                             | 34 +++++++--\n builtin/submodule--helper.c                   |  2 +-\n cache.h                                       |  2 +-\n fmt-merge-msg.c                               |  5 +-\n refs.c                                        | 30 ++++++++\n refs.h                                        |  9 +++\n remote-testsvn.c                              | 10 ++-\n remote.c                                      | 14 +++-\n send-pack.c                                   |  2 +-\n t/t0001-init.sh                               | 26 +++++++\n t/t1507-rev-parse-upstream.sh                 |  2 +-\n t/t4013-diff-various.sh                       |  4 +-\n t/t4013/diff.log_--decorate=full_--all        |  2 +-\n t/t4013/diff.log_--decorate_--all             |  2 +-\n ...--patch-with-stat_--summary_master_--_dir_ |  2 +-\n t/t4013/diff.log_--patch-with-stat_master     |  2 +-\n .../diff.log_--patch-with-stat_master_--_dir_ |  2 +-\n ...ot_--cc_--patch-with-stat_--summary_master |  2 +-\n ..._--root_--patch-with-stat_--summary_master |  2 +-\n .../diff.log_--root_--patch-with-stat_master  |  2 +-\n ...root_-c_--patch-with-stat_--summary_master |  2 +-\n t/t4013/diff.log_--root_-p_master             |  2 +-\n t/t4013/diff.log_--root_master                |  2 +-\n t/t4013/diff.log_-m_-p_--first-parent_master  |  2 +-\n t/t4013/diff.log_-m_-p_master                 |  4 +-\n t/t4013/diff.log_-p_--first-parent_master     |  2 +-\n t/t4013/diff.log_-p_master                    |  2 +-\n t/t4013/diff.log_master                       |  2 +-\n t/t4013/diff.show_--first-parent_master       |  2 +-\n t/t4013/diff.show_-c_master                   |  2 +-\n t/t4013/diff.show_-m_master                   |  4 +-\n t/t4013/diff.show_master                      |  2 +-\n ...ot_--cc_--patch-with-stat_--summary_master |  2 +-\n ...root_-c_--patch-with-stat_--summary_master |  2 +-\n t/t4202-log.sh                                | 72 +++++++++----------\n t/t5528-push-default.sh                       |  6 ++\n t/t5606-clone-options.sh                      | 24 +++++++\n t/t6200-fmt-merge-msg.sh                      | 36 +++++-----\n t/t7406-submodule-update.sh                   | 16 +++++\n t/t7419-submodule-set-branch.sh               |  7 +-\n t/t7600-merge.sh                              | 14 ++--\n t/t7608-merge-messages.sh                     | 10 +--\n t/t9020-remote-svn.sh                         |  6 ++\n transport-helper.c                            |  2 +-\n 48 files changed, 287 insertions(+), 122 deletions(-)\n\n\nbase-commit: c9c318d6bf26bcecdca5b6f31683b9d5887a83ee\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-656%2Fdscho%2Fdefault-branch-name-option-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-656/dscho/default-branch-name-option-v3\nPull-Request: https://github.com/gitgitgadget/git/pull/656\n\nRange-diff vs v2:\n\n  1:  ebd10f73cd <  -:  ---------- fast-export: do anonymize the primary branch name\n  -:  ---------- >  1:  fffdb9944f fmt-merge-msg: stop treating `master` specially\n  3:  bd8af3755a !  2:  a29943d7bb send-pack/transport-helper: respect `core.mainBranch`\n     @@ Metadata\n      Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n      \n       ## Commit message ##\n     -    send-pack/transport-helper: respect `core.mainBranch`\n     +    send-pack/transport-helper: avoid mentioning a particular branch\n      \n     -    When mentioning the main branch name in an error message, we want to go\n     -    with the preference specified by the user, only falling back to Git's\n     -    own, hard-coded default when none was configured explicitly.\n     +    When trying to push all matching branches, but none match, we offer a\n     +    message suggesting to push the `master` branch.\n     +\n     +    However, we want to step away from making that branch any more special\n     +    than any other branch, so let's reword that message to mention no branch\n     +    in particular.\n      \n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n       ## send-pack.c ##\n      @@ send-pack.c: int send_pack(struct send_pack_args *args,\n     - \t}\n       \n       \tif (!remote_refs) {\n     -+\t\tchar *branch_name = git_main_branch_name();\n     -+\n       \t\tfprintf(stderr, \"No refs in common and none specified; doing nothing.\\n\"\n      -\t\t\t\"Perhaps you should specify a branch such as 'master'.\\n\");\n     -+\t\t\t\"Perhaps you should specify a branch such as '%s'.\\n\",\n     -+\t\t\tbranch_name);\n     -+\t\tfree(branch_name);\n     ++\t\t\t\"Perhaps you should specify a specific branch.\\n\");\n       \t\treturn 0;\n       \t}\n       \tif (args->atomic && !atomic_supported)\n     @@ t/t5528-push-default.sh: test_expect_success 'push from/to new branch with upstr\n       \n      +test_expect_success '\"matching\" fails if none match' '\n      +\tgit init --bare empty &&\n     -+\ttest_must_fail git -c core.mainBranch=unmatch push empty : 2>actual &&\n     -+\tneedle=\"Perhaps you should specify a branch such as '\\''unmatch'\\''\" &&\n     -+\ttest_i18ngrep \"$needle\" actual\n     ++\ttest_must_fail git push empty : 2>actual &&\n     ++\ttest_i18ngrep \"Perhaps you should specify a specific branch\" actual\n      +'\n      +\n       test_expect_success 'push ambiguously named branch with upstream, matching and simple' '\n     @@ t/t5528-push-default.sh: test_expect_success 'push from/to new branch with upstr\n      \n       ## transport-helper.c ##\n      @@ transport-helper.c: static int push_refs(struct transport *transport,\n     - \t}\n     - \n       \tif (!remote_refs) {\n     -+\t\tchar *branch_name = git_main_branch_name();\n     -+\n       \t\tfprintf(stderr,\n       \t\t\t_(\"No refs in common and none specified; doing nothing.\\n\"\n      -\t\t\t  \"Perhaps you should specify a branch such as 'master'.\\n\"));\n     -+\t\t\t  \"Perhaps you should specify a branch such as '%s'.\\n\"),\n     -+\t\t\tbranch_name);\n     -+\t\tfree(branch_name);\n     ++\t\t\t  \"Perhaps you should specify a specific branch.\\n\"));\n       \t\treturn 0;\n       \t}\n       \n 11:  59d6267f09 !  3:  6bda69541b submodule: use the correct default for the main branch name\n     @@ Metadata\n      Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n      \n       ## Commit message ##\n     -    submodule: use the correct default for the main branch name\n     +    submodule: use a better fall-back for missing remote.<name>.branch\n      \n     -    To allow for overriding the default branch name, we have introduced a\n     -    config setting. With this patch, the `git submodule` command learns\n     -    about this, too.\n     +    When `remote.<name>.branch` is not configured, `git submodule update`\n     +    currently falls back to using the branch name `master`. A much better\n     +    idea, however, is to use `HEAD`: on all Git servers running reasonably\n     +    recent Git versions, the symref `HEAD` points to the main branch.\n     +\n     +    Note: t7419 demonstrates that there _might_ be use cases out there that\n     +    _expect_ `git submodule update --remote` to update submodules to the\n     +    remote `master` branch even if the remote `HEAD` points to another\n     +    branch. Arguably, this patch makes the behavior more intuitive, but\n     +    there is a slight possibility that this might cause regressions in\n     +    obscure setups.\n      \n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n     + ## Documentation/git-submodule.txt ##\n     +@@ Documentation/git-submodule.txt: OPTIONS\n     + \t`.gitmodules` for `update --remote`.  A special value of `.` is used to\n     + \tindicate that the name of the branch in the submodule should be the\n     + \tsame name as the current branch in the current repository.  If the\n     +-\toption is not specified, it defaults to 'master'.\n     ++\toption is not specified, it defaults to 'HEAD'.\n     + \n     + -f::\n     + --force::\n     +@@ Documentation/git-submodule.txt: OPTIONS\n     + \tthe superproject's recorded SHA-1 to update the submodule, use the\n     + \tstatus of the submodule's remote-tracking branch.  The remote used\n     + \tis branch's remote (`branch.<name>.remote`), defaulting to `origin`.\n     +-\tThe remote branch used defaults to `master`, but the branch name may\n     ++\tThe remote branch used defaults to `HEAD`, but the branch name may\n     + \tbe overridden by setting the `submodule.<name>.branch` option in\n     + \teither `.gitmodules` or `.git/config` (with `.git/config` taking\n     + \tprecedence).\n     +\n       ## builtin/submodule--helper.c ##\n      @@ builtin/submodule--helper.c: static const char *remote_submodule_branch(const char *path)\n     - \t\tbranch = sub->branch;\n       \tfree(key);\n       \n     --\tif (!branch)\n     + \tif (!branch)\n      -\t\treturn \"master\";\n     -+\tif (!branch) {\n     -+\t\tstatic char *fall_back;\n     -+\n     -+\t\tif (!fall_back)\n     -+\t\t\tfall_back = git_main_branch_name(MAIN_BRANCH_FOR_INIT);\n     -+\n     -+\t\treturn fall_back;\n     -+\t}\n     ++\t\treturn \"HEAD\";\n       \n       \tif (!strcmp(branch, \".\")) {\n       \t\tconst char *refname = resolve_ref_unsafe(\"HEAD\", 0, NULL, NULL);\n     @@ t/t7406-submodule-update.sh: test_expect_success 'setup a submodule tree' '\n       \t)\n       '\n       \n     -+test_expect_success 'update --remote uses configured default main branch' '\n     -+\tgit clone super main-branch &&\n     -+\ttest_must_fail git -C main-branch -c init.defaultBranch=hello \\\n     -+\t\tsubmodule update --init --remote submodule 2>err &&\n     -+\ttest_i18ngrep origin/hello err\n     ++test_expect_success 'update --remote falls back to using HEAD' '\n     ++\ttest_create_repo main-branch-submodule &&\n     ++\ttest_commit -C main-branch-submodule initial &&\n     ++\n     ++\ttest_create_repo main-branch &&\n     ++\tgit -C main-branch submodule add ../main-branch-submodule &&\n     ++\tgit -C main-branch commit -m add-submodule &&\n     ++\n     ++\tgit -C main-branch-submodule switch -c hello &&\n     ++\ttest_commit -C main-branch-submodule world &&\n     ++\n     ++\tgit clone --recursive main-branch main-branch-clone &&\n     ++\tgit -C main-branch-clone submodule update --remote main-branch-submodule &&\n     ++\ttest_path_exists main-branch-clone/main-branch-submodule/world.t\n      +'\n      +\n       test_expect_success 'submodule update detaching the HEAD ' '\n       \t(cd super/submodule &&\n       \t git reset --hard HEAD~1\n     +\n     + ## t/t7419-submodule-set-branch.sh ##\n     +@@ t/t7419-submodule-set-branch.sh: test_expect_success 'test submodule set-branch --branch' '\n     + '\n     + \n     + test_expect_success 'test submodule set-branch --default' '\n     ++\ttest_commit -C submodule c &&\n     + \t(cd super &&\n     + \t\tgit submodule set-branch --default submodule &&\n     + \t\t! grep branch .gitmodules &&\n     + \t\tgit submodule update --remote &&\n     + \t\tcat <<-\\EOF >expect &&\n     +-\t\ta\n     ++\t\tc\n     + \t\tEOF\n     + \t\tgit -C submodule show -s --pretty=%s >actual &&\n     + \t\ttest_cmp expect actual\n     +@@ t/t7419-submodule-set-branch.sh: test_expect_success 'test submodule set-branch --default' '\n     + '\n     + \n     + test_expect_success 'test submodule set-branch -b' '\n     ++\ttest_commit -C submodule b &&\n     + \t(cd super &&\n     + \t\tgit submodule set-branch -b topic submodule &&\n     + \t\tgrep \"branch = topic\" .gitmodules &&\n     +@@ t/t7419-submodule-set-branch.sh: test_expect_success 'test submodule set-branch -b' '\n     + '\n     + \n     + test_expect_success 'test submodule set-branch -d' '\n     ++\ttest_commit -C submodule d &&\n     + \t(cd super &&\n     + \t\tgit submodule set-branch -d submodule &&\n     + \t\t! grep branch .gitmodules &&\n     + \t\tgit submodule update --remote &&\n     + \t\tcat <<-\\EOF >expect &&\n     +-\t\ta\n     ++\t\td\n     + \t\tEOF\n     + \t\tgit -C submodule show -s --pretty=%s >actual &&\n     + \t\ttest_cmp expect actual\n  7:  0ec04b2086 !  4:  e8a6587c1a init: allow specifying the main branch name for the new repository\n     @@ Metadata\n      Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n      \n       ## Commit message ##\n     -    init: allow specifying the main branch name for the new repository\n     +    init: allow specifying the initial branch name for the new repository\n      \n     -    There is a growing number of projects trying to avoid the non-inclusive\n     -    name `master` in their repositories: The `master`/`slave` terminology is\n     -    insensitive and perpetuates injustice. This `master`/`slave` idea is\n     -    actually where Git's naming comes from, as it was inherited from\n     -    BitKeeper which uses the term in exactly this way, see\n     -    https://mail.gnome.org/archives/desktop-devel-list/2019-May/msg00066.html\n     +    There is a growing number of projects and companies desiring to change\n     +    the main branch name of their repositories (see e.g.\n     +    https://twitter.com/mislav/status/1270388510684598272 for background on\n     +    this).\n      \n          To change that branch name for new repositories, currently the only way\n          to do that automatically is by copying all of Git's template directory,\n     @@ Commit message\n          template files.\n      \n          To make this process much less cumbersome, let's introduce a new option:\n     -    `--main-branch=<branch-name>`.\n     -\n     -    This will not only initialize the repository with the specified initial\n     -    branch; It will also record that branch name in `core.mainBranch`.\n     +    `--initial-branch=<branch-name>`.\n      \n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n     @@ Documentation/git-init.txt: SYNOPSIS\n       [verse]\n       'git init' [-q | --quiet] [--bare] [--template=<template_directory>]\n       \t  [--separate-git-dir <git dir>] [--object-format=<format]\n     -+\t  [-b <branch-name> | --main-branch=<branch-name>]\n     ++\t  [-b <branch-name> | --initial-branch=<branch-name>]\n       \t  [--shared[=<permissions>]] [directory]\n       \n       \n     @@ Documentation/git-init.txt: repository.\n       If this is reinitialization, the repository will be moved to the specified path.\n       \n      +-b <branch-name::\n     -+--main-branch=<branch-name>::\n     ++--initial-branch=<branch-name>::\n      +\n     -+Use the specified name for the main (or: initial) branch in the newly created\n     -+repository. If not specified, fall back to the default name: `master`.\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      +\n       --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::\n       \n     @@ builtin/init-db.c: void initialize_repository_version(int hash_algo)\n       \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 *main_branch,\n     ++\t\t\t\tconst char *initial_branch,\n       \t\t\t\tconst struct repository_format *fmt)\n       {\n       \tstruct stat st1;\n     @@ builtin/init-db.c: static int create_default_files(const char *template_path,\n      -\t\tif (create_symref(\"HEAD\", \"refs/heads/master\", NULL) < 0)\n      +\t\tchar *ref;\n      +\n     -+\t\tif (!main_branch)\n     -+\t\t\tmain_branch = \"master\";\n     ++\t\tif (!initial_branch)\n     ++\t\t\tinitial_branch = \"master\";\n      +\n     -+\t\tref = xstrfmt(\"refs/heads/%s\", main_branch);\n     ++\t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n      +\t\tif (check_refname_format(ref, 0) < 0)\n     -+\t\t\tdie(_(\"invalid main branch name: '%s'\"), main_branch);\n     ++\t\t\tdie(_(\"invalid initial branch name: '%s'\"),\n     ++\t\t\t    initial_branch);\n      +\n      +\t\tif (create_symref(\"HEAD\", ref, NULL) < 0)\n       \t\t\texit(1);\n      -\t}\n      +\t\tfree(ref);\n     -+\n     -+\t\tgit_config_set(\"core.mainbranch\", main_branch);\n     -+\t} else if (main_branch)\n     -+\t\twarning(_(\"re-init: ignoring --main-branch=%s\"), main_branch);\n     ++\t} else if (initial_branch)\n     ++\t\twarning(_(\"re-init: ignoring --initial-branch=%s\"),\n     ++\t\t\tinitial_branch);\n       \n       \tinitialize_repository_version(fmt->hash_algo);\n       \n     @@ builtin/init-db.c: static void validate_hash_algorithm(struct repository_format\n       \n       int init_db(const char *git_dir, const char *real_git_dir,\n      -\t    const char *template_dir, int hash, unsigned int flags)\n     -+\t    const char *template_dir, int hash, const char *main_branch,\n     ++\t    const char *template_dir, int hash, const char *initial_branch,\n      +\t    unsigned int flags)\n       {\n       \tint reinit;\n     @@ builtin/init-db.c: int init_db(const char *git_dir, const char *real_git_dir,\n       \n      -\treinit = create_default_files(template_dir, original_git_dir, &repo_fmt);\n      +\treinit = create_default_files(template_dir, original_git_dir,\n     -+\t\t\t\t      main_branch, &repo_fmt);\n     ++\t\t\t\t      initial_branch, &repo_fmt);\n       \n       \tcreate_object_directory();\n       \n     @@ builtin/init-db.c: int cmd_init_db(int argc, const char **argv, const char *pref\n       \tconst char *template_dir = NULL;\n       \tunsigned int flags = 0;\n       \tconst char *object_format = NULL;\n     -+\tconst char *main_branch = NULL;\n     ++\tconst char *initial_branch = NULL;\n       \tint hash_algo = GIT_HASH_UNKNOWN;\n       \tconst struct option init_db_options[] = {\n       \t\tOPT_STRING(0, \"template\", &template_dir, N_(\"template-directory\"),\n     @@ builtin/init-db.c: int cmd_init_db(int argc, const char **argv, const char *pref\n       \t\tOPT_BIT('q', \"quiet\", &flags, N_(\"be quiet\"), INIT_DB_QUIET),\n       \t\tOPT_STRING(0, \"separate-git-dir\", &real_git_dir, N_(\"gitdir\"),\n       \t\t\t   N_(\"separate git dir from working tree\")),\n     -+\t\tOPT_STRING('b', \"main-branch\", &main_branch, N_(\"name\"),\n     -+\t\t\t   N_(\"override the name of the main branch\")),\n     ++\t\tOPT_STRING('b', \"initial-branch\", &initial_branch, N_(\"name\"),\n     ++\t\t\t   N_(\"override the name of the initial branch\")),\n       \t\tOPT_STRING(0, \"object-format\", &object_format, N_(\"hash\"),\n       \t\t\t   N_(\"specify the hash algorithm to use\")),\n       \t\tOPT_END()\n     @@ builtin/init-db.c: int cmd_init_db(int argc, const char **argv, const char *pref\n       \tflags |= INIT_DB_EXIST_OK;\n      -\treturn init_db(git_dir, real_git_dir, template_dir, hash_algo, flags);\n      +\treturn init_db(git_dir, real_git_dir, template_dir, hash_algo,\n     -+\t\t       main_branch, flags);\n     ++\t\t       initial_branch, flags);\n       }\n      \n       ## cache.h ##\n     @@ cache.h: int path_inside_repo(const char *prefix, const char *path);\n       int init_db(const char *git_dir, const char *real_git_dir,\n       \t    const char *template_dir, int hash_algo,\n      -\t    unsigned int flags);\n     -+\t    const char *main_branch, unsigned int flags);\n     ++\t    const char *initial_branch, unsigned int flags);\n       void initialize_repository_version(int hash_algo);\n       \n       void sanitize_stdfds(void);\n     @@ t/t0001-init.sh: test_expect_success MINGW 'redirect std handles' '\n       \tgrep \"Needed a single revision\" output.txt\n       '\n       \n     -+test_expect_success '--main-branch' '\n     -+\tgit init --main-branch=hello main-branch-option &&\n     -+\tgit -C main-branch-option symbolic-ref HEAD >actual &&\n     ++test_expect_success '--initial-branch' '\n     ++\tgit init --initial-branch=hello initial-branch-option &&\n     ++\tgit -C initial-branch-option symbolic-ref HEAD >actual &&\n      +\techo refs/heads/hello >expect &&\n      +\ttest_cmp expect actual &&\n      +\n     -+\t: re-initializing should not change the main branch name &&\n     -+\tgit init --main-branch=ignore main-branch-option 2>err &&\n     -+\ttest_i18ngrep \"ignoring --main-branch\" err &&\n     -+\tgit -C main-branch-option symbolic-ref HEAD >actual &&\n     -+\tgrep hello actual &&\n     -+\tgit -C main-branch-option config core.mainBranch >actual &&\n     ++\t: re-initializing should not change the branch name &&\n     ++\tgit init --initial-branch=ignore initial-branch-option 2>err &&\n     ++\ttest_i18ngrep \"ignoring --initial-branch\" err &&\n     ++\tgit -C initial-branch-option symbolic-ref HEAD >actual &&\n      +\tgrep hello actual\n      +'\n      +\n  2:  f4d5473915 !  5:  a500e0f214 fmt-merge-msg: introduce a way to override the main branch name\n     @@\n       ## Metadata ##\n     -Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n     +Author: Don Goodman-Wilson <don@goodman-wilson.com>\n      \n       ## Commit message ##\n     -    fmt-merge-msg: introduce a way to override the main branch name\n     +    init: allow setting the default for the initial branch name via the config\n      \n     -    There is a growing number of projects and companies desiring to change\n     -    the main branch name of their repositories (see e.g.\n     -    https://twitter.com/mislav/status/1270388510684598272 for background on\n     -    this).\n     +    We just introduced the command-line option\n     +    `--initial-branch=<branch-name>` to allow initializing a new repository\n     +    with a different initial branch than the hard-coded one.\n      \n     -    However, there are a couple of hard-coded spots in Git's source code\n     -    that make this endeavor harder than necessary. For example, when\n     -    formatting the commit message for merge commits, Git appends \"into\n     -    <branch-name>\" unless the current branch is the `master` branch.\n     +    To allow users to override the initial branch name more permanently\n     +    (i.e. without having to specify the name manually for each and every\n     +    `git init` invocation), let's introduce the `init.defaultBranch` config\n     +    setting.\n      \n     -    Clearly, this is not what one wants when already having gone through all\n     -    the steps to manually rename the main branch (and taking care of all the\n     -    fall-out such as re-targeting existing Pull Requests).\n     +    Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n     +    Helped-by: Derrick Stolee <dstolee@microsoft.com>\n     +    Signed-off-by: Don Goodman-Wilson <don@goodman-wilson.com>\n      \n     -    Let's introduce a way to override Git's hard-coded default:\n     -    `core.mainBranch`.\n     -\n     -    We will start supporting this config option in the `git fmt-merge-msg`\n     -    command and successively adjust all other places where the main branch\n     -    name is hard-coded.\n     -\n     -    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n     -\n     - ## Documentation/config/core.txt ##\n     -@@ Documentation/config/core.txt: core.abbrev::\n     - \tin your repository, which hopefully is enough for\n     - \tabbreviated object names to stay unique for some time.\n     - \tThe minimum length is 4.\n     + ## Documentation/config/init.txt ##\n     +@@\n     + init.templateDir::\n     + \tSpecify the directory from which templates will be copied.\n     + \t(See the \"TEMPLATE DIRECTORY\" section of linkgit:git-init[1].)\n      +\n     -+core.mainBranch::\n     -+\tThe name of the main (or: primary) branch in the current repository.\n     -+\tFor historical reasons, `master` is used as the fall-back for this\n     -+\tsetting.\n     ++init.defaultBranch::\n     ++\tAllows overriding the default branch name when initializing\n     ++\ta new repository.\n      \n     - ## fmt-merge-msg.c ##\n     -@@ fmt-merge-msg.c: static void fmt_merge_msg_title(struct strbuf *out,\n     - \t\t\t\tconst char *current_branch)\n     - {\n     - \tint i = 0;\n     --\tchar *sep = \"\";\n     -+\tchar *sep = \"\", *main_branch;\n     + ## builtin/init-db.c ##\n     +@@ builtin/init-db.c: static int create_default_files(const char *template_path,\n     + \t\tchar *ref;\n       \n     - \tstrbuf_addstr(out, \"Merge \");\n     - \tfor (i = 0; i < srcs.nr; i++) {\n     -@@ fmt-merge-msg.c: static void fmt_merge_msg_title(struct strbuf *out,\n     - \t\t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n     - \t}\n     + \t\tif (!initial_branch)\n     +-\t\t\tinitial_branch = \"master\";\n     ++\t\t\tinitial_branch = git_default_branch_name();\n       \n     --\tif (!strcmp(\"master\", current_branch))\n     -+\tmain_branch = git_main_branch_name();\n     -+\tif (!strcmp(main_branch, current_branch))\n     - \t\tstrbuf_addch(out, '\\n');\n     - \telse\n     - \t\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n     -+\tfree(main_branch);\n     - }\n     - \n     - static void fmt_tag_signature(struct strbuf *tagbuf,\n     + \t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n     + \t\tif (check_refname_format(ref, 0) < 0)\n      \n       ## refs.c ##\n      @@ refs.c: void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n       \t\targv_array_pushf(prefixes, *p, len, prefix);\n       }\n       \n     -+char *repo_main_branch_name(struct repository *r)\n     ++char *repo_default_branch_name(struct repository *r)\n      +{\n     -+\tconst char *config_key = \"core.mainbranch\";\n     -+\tconst char *config_display_key = \"core.mainBranch\";\n     -+\tconst char *fall_back = \"master\";\n     -+\tchar *name = NULL, *ret;\n     ++\tconst char *config_key = \"init.defaultbranch\";\n     ++\tconst char *config_display_key = \"init.defaultBranch\";\n     ++\tchar *ret = NULL, *full_ref;\n      +\n     -+\tif (repo_config_get_string(r, config_key, &name) < 0)\n     ++\tif (repo_config_get_string(r, config_key, &ret) < 0)\n      +\t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n      +\n     -+\tret = name ? name : xstrdup(fall_back);\n     -+\n     -+\tif (check_refname_format(ret, REFNAME_ALLOW_ONELEVEL))\n     -+\t\tdie(_(\"invalid branch name: %s = %s\"),\n     -+\t\t    config_display_key, name);\n     ++\tif (!ret)\n     ++\t\tret = xstrdup(\"master\");\n      +\n     -+\tif (name != ret)\n     -+\t\tfree(name);\n     ++\tfull_ref = xstrfmt(\"refs/heads/%s\", ret);\n     ++\tif (check_refname_format(full_ref, 0))\n     ++\t\tdie(_(\"invalid branch name: %s = %s\"), config_display_key, ret);\n     ++\tfree(full_ref);\n      +\n      +\treturn ret;\n      +}\n      +\n     -+char *git_main_branch_name(void)\n     ++const char *git_default_branch_name(void)\n      +{\n     -+\treturn repo_main_branch_name(the_repository);\n     ++\tstatic char *ret;\n     ++\n     ++\tif (!ret)\n     ++\t\tret = repo_default_branch_name(the_repository);\n     ++\n     ++\treturn ret;\n      +}\n      +\n       /*\n     @@ refs.h: int repo_dwim_log(struct repository *r, const char *str, int len, struct\n       int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n       \n      +/*\n     -+ * Retrieves the name of the main (or: primary) branch of the given\n     -+ * repository.\n     ++ * Retrieves the default branch name for newly-initialized repositories.\n     ++ *\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     -+char *git_main_branch_name(void);\n     -+char *repo_main_branch_name(struct repository *r);\n     ++const char *git_default_branch_name(void);\n     ++char *repo_default_branch_name(struct repository *r);\n      +\n       /*\n        * A ref_transaction represents a collection of reference updates that\n        * should succeed or fail together.\n      \n     - ## t/t6200-fmt-merge-msg.sh ##\n     -@@ t/t6200-fmt-merge-msg.sh: test_expect_success 'setup FETCH_HEAD' '\n     - \tgit fetch . left\n     + ## t/t0001-init.sh ##\n     +@@ t/t0001-init.sh: test_expect_success '--initial-branch' '\n     + \tgrep hello actual\n       '\n       \n     -+test_expect_success 'with overridden default branch name' '\n     -+\ttest_when_finished \"git switch master\" &&\n     -+\tgit switch -c default &&\n     -+\tgit -c core.mainBranch=default fmt-merge-msg <.git/FETCH_HEAD >actual &&\n     -+\t! grep \"into default\" actual\n     ++test_expect_success 'overridden default initial branch name (config)' '\n     ++\ttest_config_global init.defaultBranch nmb &&\n     ++\tgit init initial-branch-config &&\n     ++\tgit -C initial-branch-config symbolic-ref HEAD >actual &&\n     ++\tgrep nmb actual\n     ++'\n     ++\n     ++test_expect_success 'invalid default branch name' '\n     ++\ttest_config_global init.defaultBranch \"with space\" &&\n     ++\ttest_must_fail git init initial-branch-invalid 2>err &&\n     ++\ttest_i18ngrep \"invalid branch name\" err\n      +'\n      +\n     - test_expect_success 'merge.log=3 limits shortlog length' '\n     - \tcat >expected <<-EOF &&\n     - \tMerge branch ${apos}left${apos}\n     + test_done\n  4:  ca1c63c3e0 <  -:  ---------- git_main_branch_name(): optionally report the full ref name\n  5:  a3be4f39aa <  -:  ---------- fast-export: handle overridden main branch names correctly\n  6:  933e314813 <  -:  ---------- branch -m: adjust `core.mainBranch` if necessary\n  8:  c711eba7e7 <  -:  ---------- init: allow overriding the default main branch name via the config\n  9:  0e59b61816 !  6:  c0d74cedd1 clone: handle overridden main branch names\n     @@ Metadata\n      Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n      \n       ## Commit message ##\n     -    clone: handle overridden main branch names\n     +    clone: use configured default branch name when appropriate\n      \n          When cloning a repository without any branches, Git chooses a default\n          branch name for the as-yet unborn branch.\n      \n     -    As part of the implicit initialization of the local repository, Git\n     -    just learned to respect `init.defaultBranch` to choose a different main\n     +    As part of the implicit initialization of the local repository, Git just\n     +    learned to respect `init.defaultBranch` to choose a different initial\n          branch name. We now really want that branch name to be used as a\n          fall-back.\n      \n     -    At the same time, we also want to make sure that `core.mainBranch` is\n     -    set correctly, reflecting the name of the main branch. In case we detect\n     -    a main branch, we do have to do that explicitly, otherwise `init_db()`\n     -    will already have done that for us.\n     -\n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n       ## Documentation/config/init.txt ##\n     @@ Documentation/config/init.txt: init.templateDir::\n      +\ta new repository or when cloning an empty repository.\n      \n       ## builtin/clone.c ##\n     -@@ builtin/clone.c: static void update_head(const struct ref *our, const struct ref *remote,\n     - \t\t/* Local default branch link */\n     - \t\tif (create_symref(\"HEAD\", our->name, NULL) < 0)\n     - \t\t\tdie(_(\"unable to update HEAD\"));\n     -+\t\tgit_config_set(\"core.mainbranch\", head);\n     - \t\tif (!option_bare) {\n     - \t\t\tupdate_ref(msg, \"HEAD\", &our->old_oid, NULL, 0,\n     - \t\t\t\t   UPDATE_REFS_DIE_ON_ERR);\n      @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)\n       \t\tremote_head_points_at = NULL;\n       \t\tremote_head = NULL;\n     @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)\n      -\t\t\tinstall_branch_config(0, \"master\", option_origin,\n      -\t\t\t\t\t      \"refs/heads/master\");\n      +\t\tif (!option_bare) {\n     -+\t\t\tchar *main_branch =\n     -+\t\t\t\tgit_main_branch_name(MAIN_BRANCH_FULL_NAME);\n     -+\t\t\tconst char *nick;\n     ++\t\t\tconst char *branch = git_default_branch_name();\n     ++\t\t\tchar *ref = xstrfmt(\"refs/heads/%s\", branch);\n      +\n     -+\t\t\tif (!skip_prefix(main_branch, \"refs/heads/\", &nick))\n     -+\t\t\t\tBUG(\"unexpected default branch '%s'\",\n     -+\t\t\t\t    main_branch);\n     -+\t\t\tinstall_branch_config(0, nick, option_origin,\n     -+\t\t\t\t\t      main_branch);\n     -+\t\t\tfree(main_branch);\n     ++\t\t\tinstall_branch_config(0, branch, option_origin, ref);\n     ++\t\t\tfree(ref);\n      +\t\t}\n       \t}\n       \n     @@ t/t5606-clone-options.sh: test_expect_success 'redirected clone -v does show pro\n       \n       '\n       \n     -+test_expect_success 'chooses correct default main branch name' '\n     ++test_expect_success 'chooses correct default initial branch name' '\n      +\tgit init --bare empty &&\n      +\tgit -c init.defaultBranch=up clone empty whats-up &&\n      +\ttest refs/heads/up = $(git -C whats-up symbolic-ref HEAD) &&\n     -+\ttest up = $(git -C whats-up config core.mainBranch) &&\n      +\ttest refs/heads/up = $(git -C whats-up config branch.up.merge)\n      +'\n      +\n     -+test_expect_success 'guesses main branch name correctly' '\n     -+\tgit init --main-branch=guess main-branch &&\n     -+\ttest_commit -C main-branch no-spoilers &&\n     -+\tgit -C main-branch branch abc guess &&\n     -+\tgit clone main-branch is-it &&\n     -+\ttest guess = $(git -C is-it config core.mainBranch) &&\n     ++test_expect_success 'guesses initial branch name correctly' '\n     ++\tgit init --initial-branch=guess initial-branch &&\n     ++\ttest_commit -C initial-branch no-spoilers &&\n     ++\tgit -C initial-branch branch abc guess &&\n     ++\tgit clone initial-branch is-it &&\n      +\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD)\n      +'\n      +\n 10:  59b8f4cfbb !  7:  00a1b281e5 remote: learn about the possibly-overridden default main branch name\n     @@ Metadata\n      Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n      \n       ## Commit message ##\n     -    remote: learn about the possibly-overridden default main branch name\n     +    remote: use the configured default branch name when appropriate\n      \n          When guessing the default branch name of a remote, and there are no refs\n          to guess from, we want to go with the preference specified by the user\n     -    for the fall-back, i.e. the default name to be used for the main branch\n     -    of new repositories (because as far as the user is concerned, a remote\n     -    that has no branches yet is a new repository).\n     +    for the fall-back, i.e. the default name to be used for the initial\n     +    branch of new repositories (because as far as the user is concerned, a\n     +    remote that has no branches yet is a new repository).\n     +\n     +    At the same time, when talking to an older Git server that does not\n     +    report a symref for `HEAD` (but instead reports a commit hash), let's\n     +    try to guess the configured default branch name first. If it does not\n     +    match the reported commit hash, let's fall back to `master` as before.\n      \n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n       ## remote.c ##\n     -@@ remote.c: static void read_remotes_file(struct remote *remote)\n     - \n     - static void read_branches_file(struct remote *remote)\n     - {\n     --\tchar *frag;\n     -+\tchar *frag, *main_branch = NULL;\n     - \tstruct strbuf buf = STRBUF_INIT;\n     - \tFILE *f = fopen_or_warn(git_path(\"branches/%s\", remote->name), \"r\");\n     - \n      @@ remote.c: static void read_branches_file(struct remote *remote)\n       \n       \t/*\n     @@ remote.c: static void read_branches_file(struct remote *remote)\n       \t\t*(frag++) = '\\0';\n       \telse\n      -\t\tfrag = \"master\";\n     -+\t\tfrag = main_branch = git_main_branch_name(MAIN_BRANCH_FOR_INIT);\n     ++\t\tfrag = (char *)git_default_branch_name();\n       \n       \tadd_url_alias(remote, strbuf_detach(&buf, NULL));\n       \tstrbuf_addf(&buf, \"refs/heads/%s:refs/heads/%s\",\n     -@@ remote.c: static void read_branches_file(struct remote *remote)\n     - \tstrbuf_addf(&buf, \"HEAD:refs/heads/%s\", frag);\n     - \trefspec_append(&remote->push, buf.buf);\n     - \tremote->fetch_tags = 1; /* always auto-follow */\n     -+\tfree(main_branch);\n     - \tstrbuf_release(&buf);\n     - }\n     - \n      @@ remote.c: struct ref *guess_remote_head(const struct ref *head,\n       \tif (head->symref)\n       \t\treturn copy_ref(find_ref_by_name(refs, head->symref));\n       \n      -\t/* If refs/heads/master could be right, it is. */\n     -+\t/* If a remote branch exists with the main branch name, let's use it. */\n     ++\t/* If a remote branch exists with the default branch name, let's use it. */\n       \tif (!all) {\n     --\t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n     -+\t\tchar *name = git_main_branch_name(MAIN_BRANCH_FULL_NAME |\n     -+\t\t\t\t\t\t  MAIN_BRANCH_FOR_INIT);\n     ++\t\tchar *ref = xstrfmt(\"refs/heads/%s\", git_default_branch_name());\n     ++\n     ++\t\tr = find_ref_by_name(refs, ref);\n     ++\t\tfree(ref);\n     ++\t\tif (r && oideq(&r->old_oid, &head->old_oid))\n     ++\t\t\treturn copy_ref(r);\n      +\n     -+\t\tr = find_ref_by_name(refs, name);\n     -+\t\tfree(name);\n     ++\t\t/* Fall back to the hard-coded historical default */\n     + \t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n       \t\tif (r && oideq(&r->old_oid, &head->old_oid))\n       \t\t\treturn copy_ref(r);\n     - \t}\n      \n       ## t/t5606-clone-options.sh ##\n     -@@ t/t5606-clone-options.sh: test_expect_success 'guesses main branch name correctly' '\n     - \tgit -C main-branch branch abc guess &&\n     - \tgit clone main-branch is-it &&\n     - \ttest guess = $(git -C is-it config core.mainBranch) &&\n     +@@ t/t5606-clone-options.sh: test_expect_success 'guesses initial branch name correctly' '\n     + \ttest_commit -C initial-branch no-spoilers &&\n     + \tgit -C initial-branch branch abc guess &&\n     + \tgit clone initial-branch is-it &&\n      -\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD)\n      +\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD) &&\n      +\n      +\tgit -c init.defaultBranch=none init --bare no-head &&\n     -+\tgit -C main-branch push ../no-head guess abc &&\n     ++\tgit -C initial-branch push ../no-head guess abc &&\n      +\tgit clone no-head is-it2 &&\n      +\ttest_must_fail git -C is-it2 symbolic-ref refs/remotes/origin/HEAD &&\n      +\tgit -C no-head update-ref --no-deref HEAD refs/heads/guess &&\n 12:  e09f857f06 !  8:  1aa0e63785 testsvn: respect `init.defaultBranch`\n     @@ Metadata\n       ## Commit message ##\n          testsvn: respect `init.defaultBranch`\n      \n     -    The default name of the main branch in new repositories can now be\n     +    The default name of the initial branch in new repositories can now be\n          configured. The `testsvn` remote helper translates the remote Subversion\n          repository's branch name `trunk` to the hard-coded name `master`.\n     -    Clearly, the intention was to make the name align with Git's detaults.\n     +    Clearly, the intention was to make the name align with Git's defaults.\n      \n          So while we are not talking about a newly-created repository in the\n     -    `testsvn` context, it _still_ makes sense to use the overridden default\n     -    name for the main branch whenever users configured it.\n     +    `testsvn` context, it is a newly-created _Git_ repository, si it _still_\n     +    makes sense to use the overridden default name for the initial branch\n     +    whenever users configured it.\n      \n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n     @@ remote-testsvn.c: int cmd_main(int argc, const char **argv)\n       \t\treturn 1;\n       \t}\n       \n     -+\tremote_ref = git_main_branch_name(MAIN_BRANCH_FULL_NAME |\n     -+\t\t\t\t\t  MAIN_BRANCH_FOR_INIT);\n     -+\tif (!skip_prefix(remote_ref, \"refs/heads/\", &remote_ref_short))\n     -+\t\tBUG(\"unexpected remote_ref '%s'\", remote_ref);\n     ++\tremote_ref_short = git_default_branch_name();\n     ++\tremote_ref = xstrfmt(\"refs/heads/%s\", remote_ref_short);\n      +\n       \tremote = remote_get(argv[1]);\n       \turl_in = (argc == 3) ? argv[2] : remote->url[0];\n     @@ t/t9020-remote-svn.sh: test_expect_success REMOTE_SVN 'incremental imports must\n       \ttest_cmp master.good .git/refs/remotes/svnsim/master\n       '\n       \n     -+test_expect_success REMOTE_SVN 'respects configured default main branch' '\n     ++test_expect_success REMOTE_SVN 'respects configured default initial branch' '\n      +\tgit -c init.defaultBranch=trunk remote add -f trunk \\\n      +\t\t\"testsvn::file://$TEST_DIRECTORY/t9154/svn.dump\" &&\n      +\tgit rev-parse --verify refs/remotes/trunk/trunk\n\n-- \ngitgitgadget\n"},{"id":"400476","messageId":"xmqqr1u59u5f.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"a29943d7bbc11a524089348a4abbd33c7514eee9.1592951611.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 2/8] send-pack/transport-helper: avoid mentioning a particular branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-24T00:36:44Z","receivedAt":"2020-06-24T00:36:52Z","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> @@ -1046,7 +1046,7 @@ static int push_refs(struct transport *transport,\n>  \tif (!remote_refs) {\n>  \t\tfprintf(stderr,\n>  \t\t\t_(\"No refs in common and none specified; doing nothing.\\n\"\n> -\t\t\t  \"Perhaps you should specify a branch such as 'master'.\\n\"));\n> +\t\t\t  \"Perhaps you should specify a specific branch.\\n\"));\n\nHmph, not just \"specify a branch.\"?  Maybe it is just me, but\n\"specify a specific branch\" did not roll well on my tongue.\n"},{"id":"400478","messageId":"xmqqmu4t9t57.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"e8a6587c1a783476413277296c6ce3db74e217e6.1592951611.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 4/8] init: allow specifying the initial branch name for the new repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-24T00:58:28Z","receivedAt":"2020-06-24T00:58:37Z","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>  [verse]\n>  'git init' [-q | --quiet] [--bare] [--template=<template_directory>]\n>  \t  [--separate-git-dir <git dir>] [--object-format=<format]\n\nCompletely offtopic.  We lack the closing ket> here.\n\n> +\t  [-b <branch-name> | --initial-branch=<branch-name>]\n>  \t  [--shared[=<permissions>]] [directory]\n>  \n>  \n> @@ -67,6 +68,12 @@ repository.\n>  +\n>  If this is reinitialization, the repository will be moved to the specified path.\n>  \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\nOK.\n\n> diff --git a/builtin/clone.c b/builtin/clone.c\n> index 2a8e3aaaed..b751bdf13e 100644\n> --- a/builtin/clone.c\n> +++ b/builtin/clone.c\n> @@ -1111,7 +1111,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n>  \t\t}\n>  \t}\n>  \n> -\tinit_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, INIT_DB_QUIET);\n> +\tinit_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,\n> +\t\tINIT_DB_QUIET);\n>  \n>  \tif (real_git_dir)\n>  \t\tgit_dir = real_git_dir;\n> diff --git a/builtin/init-db.c b/builtin/init-db.c\n> index 0b7222e718..a898153901 100644\n> --- a/builtin/init-db.c\n> +++ b/builtin/init-db.c\n> @@ -203,6 +203,7 @@ void initialize_repository_version(int hash_algo)\n>  \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>  {\n>  \tstruct stat st1;\n> @@ -258,16 +259,29 @@ static int create_default_files(const char *template_path,\n>  \t\tdie(\"failed to set up refs db: %s\", err.buf);\n>  \n>  \t/*\n> -\t * Create the default symlink from \".git/HEAD\" to the \"master\"\n> -\t * branch, if it does not exist yet.\n> +\t * Create the default symlink from \".git/HEAD\" to the default\n> +\t * branch name, if it does not exist yet.\n>  \t */\n\nTo the caller of this helper, it may be \"the default\", but as far as\nthis helper is concerned, it is not \"default\" but the initial branch\nthat was given by the caller.  How about...\n\n\t/*\n\t * Point the initial branch with HEAD symref, if HEAD does\n\t * not exist yet.\n\t */\n\n... to modernize the reference to symlink and replace it with\nsymref?\n\n> +\t\tif (!initial_branch)\n> +\t\t\tinitial_branch = \"master\";\n> +\n> +\t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n> +\t\tif (check_refname_format(ref, 0) < 0)\n> +\t\t\tdie(_(\"invalid initial branch name: '%s'\"),\n> +\t\t\t    initial_branch);\n\nGood.  We make sure to prefix with \"refs/heads/\" so the callers\ncannot abuse us to point HEAD outside the local branches.\n\n> +\t\tif (create_symref(\"HEAD\", ref, NULL) < 0)\n>  \t\t\texit(1);\n> -\t}\n> +\t\tfree(ref);\n> +\t} else if (initial_branch)\n> +\t\twarning(_(\"re-init: ignoring --initial-branch=%s\"),\n> +\t\t\tinitial_branch);\n\nSomehow the error checking convention feels uneven in this API.  It\nis a warning-worthy offense for the caller to give initial_branch\nwhen we are re-initializing, but it is not an error for the caller\nnot to supply the initial branch name on the other side of if/else.\nWorse yet, this helper function even knows the command line option\nname that resulted in the parameter coming to it.\n\nThat unevenness ultimately comes from the fact that the caller does\nnot know if we are dealing with a repository that already has HEAD\nbefore calling, but at least we should be able to tell the caller\nif we initialized or not with our return value and allow the caller\nto issue this warning---that way we can lose the warning from here\nand get rid of the uneven feeling.  Oh, and ...\n\n> @@ -383,7 +397,8 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash\n>  }\n>  \n>  int init_db(const char *git_dir, const char *real_git_dir,\n> -\t    const char *template_dir, int hash, unsigned int flags)\n> +\t    const char *template_dir, int hash, const char *initial_branch,\n> +\t    unsigned int flags)\n>  {\n>  \tint reinit;\n>  \tint exist_ok = flags & INIT_DB_EXIST_OK;\n> @@ -425,7 +440,8 @@ int init_db(const char *git_dir, const char *real_git_dir,\n>  \n>  \tvalidate_hash_algorithm(&repo_fmt, hash);\n>  \n> -\treinit = create_default_files(template_dir, original_git_dir, &repo_fmt);\n> +\treinit = create_default_files(template_dir, original_git_dir,\n> +\t\t\t\t      initial_branch, &repo_fmt);\n\n... we are telling the caller if we are in reinit situation, so we\ncan afford to do exactly that.  \n\n\treinit = create_default_files...\n \tif (reinit && initial_branch)\n\t\twarning(_(\"re-init: ignored --initial-branch\"));\n\nThat's much better ;-)\n\nOther than that, looks good to me.\n\nThanks.\n\n"},{"id":"400479","messageId":"xmqqftal9su2.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"a500e0f214a0ea4bf5cf4e26f688ae68a0b84bcd.1592951611.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 5/8] init: allow setting the default for the initial branch name via the config","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-24T01:05:09Z","receivedAt":"2020-06-24T01:05:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Don Goodman-Wilson via GitGitGadget\" <gitgitgadget@gmail.com>\nwrites:\n\n> diff --git a/builtin/init-db.c b/builtin/init-db.c\n> index a898153901..b8634b5f35 100644\n> --- a/builtin/init-db.c\n> +++ b/builtin/init-db.c\n> @@ -269,7 +269,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 = \"master\";\n> +\t\t\tinitial_branch = git_default_branch_name();\n>  \n>  \t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n>  \t\tif (check_refname_format(ref, 0) < 0)\n\nContinuing with the division of labor between this helper and its\ncaller, I had this funny dislike of falling back here and not in the\ncaller.  But with the same idea of using \"reinit\", we could get rid\nof this \"if the caller didn't give us initial_branch, fall back\nto...\" logic from the function.  The caller may do\n\n\treinit = create_default_files(...\n\t\t\tinitial_branch ? initial_branch : \"master\",\n\t\t\t...);\n\tif (reinit || initial_branch)\n\t\twarning(_(...));\n\t\nin the previous step and then we can teach the caller to use the\nconfigured value instead of the hardcoded \"master\".\n\nThat's much better ;-)\n\nOther than that, looks good to me.\n\nThanks.\n"},{"id":"400480","messageId":"xmqqbll99sl5.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"00a1b281e5ae4cf14435a6745cc55fc248f378a5.1592951611.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 7/8] remote: use the configured default branch name when appropriate","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-24T01:10:30Z","receivedAt":"2020-06-24T01:10: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> diff --git a/remote.c b/remote.c\n> index 534c6426f1..965129adc3 100644\n> --- a/remote.c\n> +++ b/remote.c\n> @@ -276,7 +276,7 @@ static void read_branches_file(struct remote *remote)\n>  \n>  \t/*\n>  \t * The branches file would have URL and optionally\n> -\t * #branch specified.  The \"master\" (or specified) branch is\n> +\t * #branch specified.  The main (or specified) branch is\n>  \t * fetched and stored in the local branch matching the\n>  \t * remote name.\n>  \t */\n\nIsn't this a bit premature here?\n\n"},{"id":"400486","messageId":"D2ED942B-9397-472A-B017-190016531547@gmail.com","threadId":"53651","inReplyTo":"6bda69541b12e93cfcf7b841b8691296dc82eeba.1592951611.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 3/8] submodule: use a better fall-back for missing remote.<name>.branch","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2020-06-24T02:18:15Z","receivedAt":"2020-06-24T02:18:24Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Dscho,\n\n> Le 23 juin 2020 à 18:33, Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com> a écrit :\n> \n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> \n> When `remote.<name>.branch` is not configured, `git submodule update`\n> currently falls back to using the branch name `master`. A much better\n> idea, however, is to use `HEAD`: on all Git servers running reasonably\n> recent Git versions, the symref `HEAD` points to the main branch.\n\nTo be pedantic, it is up to the maintainer/developers to make sure that \nHEAD on the canonic repository indeed points to the branch that is considered\nthe 'main' branch of the project; the Git version does not really matter IMO...\nI've seen plenty of repos at work that have HEAD pointing to `master` but `master` \nis not used, or not anymore...\n\n> Note: t7419 demonstrates that there _might_ be use cases out there that\n> _expect_ `git submodule update --remote` to update submodules to the\n> remote `master` branch even if the remote `HEAD` points to another\n> branch. Arguably, this patch makes the behavior more intuitive, but\n> there is a slight possibility that this might cause regressions in\n> obscure setups.\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nI think that's an excellent idea. However I'd be more explicit in the commit message title:\nsubmodule: fall back to remote's HEAD for missing remote.<name>.branch\n\nmeta comment: I never know where is the best place to make suggestions\nabout changing the commit message title, since I can't quote it in my replies!\n\n> ---\n> Documentation/git-submodule.txt |  4 ++--\n> builtin/submodule--helper.c     |  2 +-\n> t/t7406-submodule-update.sh     | 16 ++++++++++++++++\n> t/t7419-submodule-set-branch.sh |  7 +++++--\n> 4 files changed, 24 insertions(+), 5 deletions(-)\n\nI think Documentation/gitmodules.txt (`submodule.<name>.branch` header)\n should also be changed to reflect the behaviour change: \n\ndiff --git a/Documentation/gitmodules.txt b/Documentation/gitmodules.txt\nindex 67275fd187..539b4e1997 100644\n--- a/Documentation/gitmodules.txt\n+++ b/Documentation/gitmodules.txt\n@@ -49,9 +49,9 @@ submodule.<name>.update::\n \n submodule.<name>.branch::\n \tA remote branch name for tracking updates in the upstream submodule.\n-\tIf the option is not specified, it defaults to 'master'.  A special\n-\tvalue of `.` is used to indicate that the name of the branch in the\n-\tsubmodule should be the same name as the current branch in the\n+\tIf the option is not specified, it defaults to the remote 'HEAD'.\n+\tA special value of `.` is used to indicate that the name of the branch\n+\tin the submodule should be the same name as the current branch in the\n \tcurrent repository.  See the `--remote` documentation in\n \tlinkgit:git-submodule[1] for details.\n\n> diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\n> index c9ed2bf3d5..b20f85e622 100644\n> --- a/Documentation/git-submodule.txt\n> +++ b/Documentation/git-submodule.txt\n> @@ -284,7 +284,7 @@ OPTIONS\n> \t`.gitmodules` for `update --remote`.  A special value of `.` is used to\n> \tindicate that the name of the branch in the submodule should be the\n> \tsame name as the current branch in the current repository.  If the\n> -\toption is not specified, it defaults to 'master'.\n> +\toption is not specified, it defaults to 'HEAD'.\n\nJust to be extra clear (it's easy to get confused with submodules!) I'd say explicitly:\n\nIf the option is not specified, it defaults to the remote 'HEAD'.\n\n> \n> -f::\n> --force::\n> @@ -322,7 +322,7 @@ OPTIONS\n> \tthe superproject's recorded SHA-1 to update the submodule, use the\n> \tstatus of the submodule's remote-tracking branch.  The remote used\n> \tis branch's remote (`branch.<name>.remote`), defaulting to `origin`.\n> -\tThe remote branch used defaults to `master`, but the branch name may\n> +\tThe remote branch used defaults to `HEAD`, but the branch name may\n\nSame thing here:\n\nThe remote branch used defaults to the remote `HEAD`.\n\n> \tbe overridden by setting the `submodule.<name>.branch` option in\n> \teither `.gitmodules` or `.git/config` (with `.git/config` taking\n> \tprecedence).\n\nAlso, you seem to have missed the `master` reference in the description of \nthe 'set-branch' subcommand. Something like this would do, I think:\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex c9ed2bf3d5..8cf5831a72 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -183,7 +183,7 @@ set-branch (-d|--default) [--] <path>::\n \tSets the default remote tracking branch for the submodule. The\n \t`--branch` option allows the remote branch to be specified. The\n \t`--default` option removes the submodule.<name>.branch configuration\n-\tkey, which causes the tracking branch to default to 'master'.\n+\tkey, which causes the tracking branch to default to the remote 'HEAD'.\n \n set-url [--] <path> <newurl>::\n \tSets the URL of the specified submodule to <newurl>. Then, it will\n\n\nThe rest of the patch looks good.\n\nCheers,\nPhilippe.\n\n"},{"id":"400494","messageId":"nycvar.QRO.7.76.6.2006241443200.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqr1u59u5f.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v3 2/8] send-pack/transport-helper: avoid mentioning a particular branch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-24T12:44:20Z","receivedAt":"2020-06-24T12:44:50Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Tue, 23 Jun 2020, Junio C Hamano wrote:\n\n> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> > @@ -1046,7 +1046,7 @@ static int push_refs(struct transport *transport,\n> >  \tif (!remote_refs) {\n> >  \t\tfprintf(stderr,\n> >  \t\t\t_(\"No refs in common and none specified; doing nothing.\\n\"\n> > -\t\t\t  \"Perhaps you should specify a branch such as 'master'.\\n\"));\n> > +\t\t\t  \"Perhaps you should specify a specific branch.\\n\"));\n>\n> Hmph, not just \"specify a branch.\"?  Maybe it is just me, but\n> \"specify a specific branch\" did not roll well on my tongue.\n\nOh well. \"Perhaps you should specify a branch\" sounded too judgmental to\nme, but I'm not a native speaker, so I simply removed the word \"specific\".\n\nCiao,\nDscho\n"},{"id":"400495","messageId":"nycvar.QRO.7.76.6.2006241444280.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"D2ED942B-9397-472A-B017-190016531547@gmail.com","subject":"Re: [PATCH v3 3/8] submodule: use a better fall-back for missing remote.<name>.branch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-24T12:51:08Z","receivedAt":"2020-06-24T12:51:25Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Philippe,\n\nOn Tue, 23 Jun 2020, Philippe Blain wrote:\n\n> > Le 23 juin 2020 à 18:33, Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com> a écrit :\n> >\n> > From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> >\n> > When `remote.<name>.branch` is not configured, `git submodule update`\n> > currently falls back to using the branch name `master`. A much better\n> > idea, however, is to use `HEAD`: on all Git servers running reasonably\n> > recent Git versions, the symref `HEAD` points to the main branch.\n>\n> To be pedantic, it is up to the maintainer/developers to make sure that\n> HEAD on the canonic repository indeed points to the branch that is\n> considered the 'main' branch of the project; the Git version does not\n> really matter IMO... I've seen plenty of repos at work that have HEAD\n> pointing to `master` but `master` is not used, or not anymore...\n\nOh, but in this case, my main concern was servers that are so old that\n`HEAD` is not a symref, in which case it can be a bit tricky to figure out\nthe default branch.\n\nIn any case, I feel this is such a minor point that I don't really want to\nspend a lot of time on this paragraph.\n\n> > Note: t7419 demonstrates that there _might_ be use cases out there that\n> > _expect_ `git submodule update --remote` to update submodules to the\n> > remote `master` branch even if the remote `HEAD` points to another\n> > branch. Arguably, this patch makes the behavior more intuitive, but\n> > there is a slight possibility that this might cause regressions in\n> > obscure setups.\n> >\n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n>\n> I think that's an excellent idea. However I'd be more explicit in the\n> commit message title:\n>\n> submodule: fall back to remote's HEAD for missing remote.<name>.branch\n\nGreat!\n\n> meta comment: I never know where is the best place to make suggestions\n> about changing the commit message title, since I can't quote it in my\n> replies!\n\nTrue. You could copy it, but that's not the same.\n\n> > ---\n> > Documentation/git-submodule.txt |  4 ++--\n> > builtin/submodule--helper.c     |  2 +-\n> > t/t7406-submodule-update.sh     | 16 ++++++++++++++++\n> > t/t7419-submodule-set-branch.sh |  7 +++++--\n> > 4 files changed, 24 insertions(+), 5 deletions(-)\n>\n> I think Documentation/gitmodules.txt (`submodule.<name>.branch` header)\n>  should also be changed to reflect the behaviour change:\n>\n> diff --git a/Documentation/gitmodules.txt b/Documentation/gitmodules.txt\n> index 67275fd187..539b4e1997 100644\n> --- a/Documentation/gitmodules.txt\n> +++ b/Documentation/gitmodules.txt\n> @@ -49,9 +49,9 @@ submodule.<name>.update::\n>\n>  submodule.<name>.branch::\n>  \tA remote branch name for tracking updates in the upstream submodule.\n> -\tIf the option is not specified, it defaults to 'master'.  A special\n> -\tvalue of `.` is used to indicate that the name of the branch in the\n> -\tsubmodule should be the same name as the current branch in the\n> +\tIf the option is not specified, it defaults to the remote 'HEAD'.\n> +\tA special value of `.` is used to indicate that the name of the branch\n> +\tin the submodule should be the same name as the current branch in the\n>  \tcurrent repository.  See the `--remote` documentation in\n>  \tlinkgit:git-submodule[1] for details.\n\nExcellent, I used that verbatim. Thank you!\n\n> > diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\n> > index c9ed2bf3d5..b20f85e622 100644\n> > --- a/Documentation/git-submodule.txt\n> > +++ b/Documentation/git-submodule.txt\n> > @@ -284,7 +284,7 @@ OPTIONS\n> > \t`.gitmodules` for `update --remote`.  A special value of `.` is used to\n> > \tindicate that the name of the branch in the submodule should be the\n> > \tsame name as the current branch in the current repository.  If the\n> > -\toption is not specified, it defaults to 'master'.\n> > +\toption is not specified, it defaults to 'HEAD'.\n>\n> Just to be extra clear (it's easy to get confused with submodules!) I'd\n> say explicitly:\n>\n> If the option is not specified, it defaults to the remote 'HEAD'.\n\nGood idea. I incorporated that, too.\n\n> > -f::\n> > --force::\n> > @@ -322,7 +322,7 @@ OPTIONS\n> > \tthe superproject's recorded SHA-1 to update the submodule, use the\n> > \tstatus of the submodule's remote-tracking branch.  The remote used\n> > \tis branch's remote (`branch.<name>.remote`), defaulting to `origin`.\n> > -\tThe remote branch used defaults to `master`, but the branch name may\n> > +\tThe remote branch used defaults to `HEAD`, but the branch name may\n>\n> Same thing here:\n>\n> The remote branch used defaults to the remote `HEAD`.\n\nAnd that.\n\n> > \tbe overridden by setting the `submodule.<name>.branch` option in\n> > \teither `.gitmodules` or `.git/config` (with `.git/config` taking\n> > \tprecedence).\n>\n> Also, you seem to have missed the `master` reference in the description of\n> the 'set-branch' subcommand. Something like this would do, I think:\n>\n> diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\n> index c9ed2bf3d5..8cf5831a72 100644\n> --- a/Documentation/git-submodule.txt\n> +++ b/Documentation/git-submodule.txt\n> @@ -183,7 +183,7 @@ set-branch (-d|--default) [--] <path>::\n>  \tSets the default remote tracking branch for the submodule. The\n>  \t`--branch` option allows the remote branch to be specified. The\n>  \t`--default` option removes the submodule.<name>.branch configuration\n> -\tkey, which causes the tracking branch to default to 'master'.\n> +\tkey, which causes the tracking branch to default to the remote 'HEAD'.\n>\n>  set-url [--] <path> <newurl>::\n>  \tSets the URL of the specified submodule to <newurl>. Then, it will\n\nAnd that.\n\n> The rest of the patch looks good.\n\nAwesome. Thank you for helping me improve this patch series!\n\nCiao,\nDscho\n"},{"id":"400496","messageId":"nycvar.QRO.7.76.6.2006241452540.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqmu4t9t57.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v3 4/8] init: allow specifying the initial branch name for the new repository","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-24T12:55:13Z","receivedAt":"2020-06-24T12:55:39Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Tue, 23 Jun 2020, Junio C Hamano wrote:\n\n> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> >  [verse]\n> >  'git init' [-q | --quiet] [--bare] [--template=<template_directory>]\n> >  \t  [--separate-git-dir <git dir>] [--object-format=<format]\n>\n> Completely offtopic.  We lack the closing ket> here.\n\nNot so off-topic: the fix for this would cause conflicts. In the interest\nof avoiding merge conflicts, I incorporated a patch to fix that (`git\ngrep` found two more instances, which I fixed \"while at it\").\n\n> > +\t  [-b <branch-name> | --initial-branch=<branch-name>]\n> >  \t  [--shared[=<permissions>]] [directory]\n> >\n> >\n> > @@ -67,6 +68,12 @@ repository.\n> >  +\n> >  If this is reinitialization, the repository will be moved to the specified path.\n> >\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>\n> OK.\n>\n> > diff --git a/builtin/clone.c b/builtin/clone.c\n> > index 2a8e3aaaed..b751bdf13e 100644\n> > --- a/builtin/clone.c\n> > +++ b/builtin/clone.c\n> > @@ -1111,7 +1111,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n> >  \t\t}\n> >  \t}\n> >\n> > -\tinit_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, INIT_DB_QUIET);\n> > +\tinit_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,\n> > +\t\tINIT_DB_QUIET);\n> >\n> >  \tif (real_git_dir)\n> >  \t\tgit_dir = real_git_dir;\n> > diff --git a/builtin/init-db.c b/builtin/init-db.c\n> > index 0b7222e718..a898153901 100644\n> > --- a/builtin/init-db.c\n> > +++ b/builtin/init-db.c\n> > @@ -203,6 +203,7 @@ void initialize_repository_version(int hash_algo)\n> >\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> >  {\n> >  \tstruct stat st1;\n> > @@ -258,16 +259,29 @@ static int create_default_files(const char *template_path,\n> >  \t\tdie(\"failed to set up refs db: %s\", err.buf);\n> >\n> >  \t/*\n> > -\t * Create the default symlink from \".git/HEAD\" to the \"master\"\n> > -\t * branch, if it does not exist yet.\n> > +\t * Create the default symlink from \".git/HEAD\" to the default\n> > +\t * branch name, if it does not exist yet.\n> >  \t */\n>\n> To the caller of this helper, it may be \"the default\", but as far as\n> this helper is concerned, it is not \"default\" but the initial branch\n> that was given by the caller.  How about...\n>\n> \t/*\n> \t * Point the initial branch with HEAD symref, if HEAD does\n> \t * not exist yet.\n> \t */\n>\n> ... to modernize the reference to symlink and replace it with\n> symref?\n\nGood point. I massaged your proposed comment and replaced the old one with\nit.\n\n> > +\t\tif (!initial_branch)\n> > +\t\t\tinitial_branch = \"master\";\n> > +\n> > +\t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n> > +\t\tif (check_refname_format(ref, 0) < 0)\n> > +\t\t\tdie(_(\"invalid initial branch name: '%s'\"),\n> > +\t\t\t    initial_branch);\n>\n> Good.  We make sure to prefix with \"refs/heads/\" so the callers\n> cannot abuse us to point HEAD outside the local branches.\n\nYes, Peff offered that concern, and I agree.\n\n> > +\t\tif (create_symref(\"HEAD\", ref, NULL) < 0)\n> >  \t\t\texit(1);\n> > -\t}\n> > +\t\tfree(ref);\n> > +\t} else if (initial_branch)\n> > +\t\twarning(_(\"re-init: ignoring --initial-branch=%s\"),\n> > +\t\t\tinitial_branch);\n>\n> Somehow the error checking convention feels uneven in this API.  It\n> is a warning-worthy offense for the caller to give initial_branch\n> when we are re-initializing, but it is not an error for the caller\n> not to supply the initial branch name on the other side of if/else.\n> Worse yet, this helper function even knows the command line option\n> name that resulted in the parameter coming to it.\n>\n> That unevenness ultimately comes from the fact that the caller does\n> not know if we are dealing with a repository that already has HEAD\n> before calling, but at least we should be able to tell the caller\n> if we initialized or not with our return value and allow the caller\n> to issue this warning---that way we can lose the warning from here\n> and get rid of the uneven feeling.  Oh, and ...\n>\n> > @@ -383,7 +397,8 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash\n> >  }\n> >\n> >  int init_db(const char *git_dir, const char *real_git_dir,\n> > -\t    const char *template_dir, int hash, unsigned int flags)\n> > +\t    const char *template_dir, int hash, const char *initial_branch,\n> > +\t    unsigned int flags)\n> >  {\n> >  \tint reinit;\n> >  \tint exist_ok = flags & INIT_DB_EXIST_OK;\n> > @@ -425,7 +440,8 @@ int init_db(const char *git_dir, const char *real_git_dir,\n> >\n> >  \tvalidate_hash_algorithm(&repo_fmt, hash);\n> >\n> > -\treinit = create_default_files(template_dir, original_git_dir, &repo_fmt);\n> > +\treinit = create_default_files(template_dir, original_git_dir,\n> > +\t\t\t\t      initial_branch, &repo_fmt);\n>\n> ... we are telling the caller if we are in reinit situation, so we\n> can afford to do exactly that.\n>\n> \treinit = create_default_files...\n>  \tif (reinit && initial_branch)\n> \t\twarning(_(\"re-init: ignored --initial-branch\"));\n\nI changed it accordingly.\n\nThanks,\nDscho\n\n>\n> That's much better ;-)\n>\n> Other than that, looks good to me.\n>\n> Thanks.\n>\n>\n"},{"id":"400497","messageId":"nycvar.QRO.7.76.6.2006241455210.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqftal9su2.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v3 5/8] init: allow setting the default for the initial branch name via the config","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-24T12:56:46Z","receivedAt":"2020-06-24T12:57:13Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Tue, 23 Jun 2020, Junio C Hamano wrote:\n\n> \"Don Goodman-Wilson via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> > diff --git a/builtin/init-db.c b/builtin/init-db.c\n> > index a898153901..b8634b5f35 100644\n> > --- a/builtin/init-db.c\n> > +++ b/builtin/init-db.c\n> > @@ -269,7 +269,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 = \"master\";\n> > +\t\t\tinitial_branch = git_default_branch_name();\n> >\n> >  \t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n> >  \t\tif (check_refname_format(ref, 0) < 0)\n>\n> Continuing with the division of labor between this helper and its\n> caller, I had this funny dislike of falling back here and not in the\n> caller.  But with the same idea of using \"reinit\", we could get rid\n> of this \"if the caller didn't give us initial_branch, fall back\n> to...\" logic from the function.  The caller may do\n>\n> \treinit = create_default_files(...\n> \t\t\tinitial_branch ? initial_branch : \"master\",\n> \t\t\t...);\n> \tif (reinit || initial_branch)\n> \t\twarning(_(...));\n>\n> in the previous step and then we can teach the caller to use the\n> configured value instead of the hardcoded \"master\".\n\nWhile that is really tempting, there is another called of `init_db()`\n(which calls `create_default_files()`): `builtin/clone.c`. And I do not\nwish to duplicate the logic there.\n\nSo I left this as-is.\n\nCiao,\nDscho\n\n>\n> That's much better ;-)\n>\n> Other than that, looks good to me.\n>\n> Thanks.\n>\n"},{"id":"400498","messageId":"nycvar.QRO.7.76.6.2006241459000.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqbll99sl5.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v3 7/8] remote: use the configured default branch name when appropriate","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-24T13:00:29Z","receivedAt":"2020-06-24T13:00:43Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Tue, 23 Jun 2020, Junio C Hamano wrote:\n\n> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> > diff --git a/remote.c b/remote.c\n> > index 534c6426f1..965129adc3 100644\n> > --- a/remote.c\n> > +++ b/remote.c\n> > @@ -276,7 +276,7 @@ static void read_branches_file(struct remote *remote)\n> >\n> >  \t/*\n> >  \t * The branches file would have URL and optionally\n> > -\t * #branch specified.  The \"master\" (or specified) branch is\n> > +\t * #branch specified.  The main (or specified) branch is\n> >  \t * fetched and stored in the local branch matching the\n> >  \t * remote name.\n> >  \t */\n>\n> Isn't this a bit premature here?\n\nActually, it is just wrong. It should talk about the default branch\ninstead.\n\nCiao,\nDscho\n"},{"id":"400506","messageId":"pull.656.v4.git.1593009996.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v3.git.1592951611.gitgitgadget@gmail.com","subject":"[PATCH v4 0/9] Allow overriding the default name of the default branch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-24T14:46:27Z","receivedAt":"2020-06-24T14:46:43Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"A growing number of open source projects aims to avoid the branch name \nmaster due to its negative connotation. See [1] for an existing discussion\non this. The links [2], [3], and [4] describe community-driven ways for\nusers to rename their default branches or use template edits to set a new\ndefault branch name.\n\n[1] \nhttps://lore.kernel.org/git/CAOAHyQwyXC1Z3v7BZAC+Bq6JBaM7FvBenA-1fcqeDV==apdWDg@mail.gmail.com/\n\n[2] https://twitter.com/mislav/status/1270388510684598272\n\n[3] \nhttps://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx\n\n[4] https://github.com/ethomson/retarget_prs\n\nBy necessity, existing repositories require a lot of manual work to move\naway from that branch name, but it should be much easier for new\nrepositories.\n\nThis patch series allows overriding the branch name being used for new\nrepositories' main branch. This can be configured via init.defaultBranch.\n\nThe initial patch was started by newcomer Don Goodman-Wilson, as well as the\nbigger change that morphed into #655, where we demonstrate how to change\nGit's hard-coded default branch name for new repositories to main based on\nthis here patch series, verifying the approach. Thanks for the contribution!\n\nThis series DOES NOT change the default automatically, but only provides an\nopt-in mechanism for interested users. The plan for that is to convert the\ntest scripts incrementally (by introducing GIT_TEST_DEFAULT_MAIN_BRANCH_NAME\n, which overrides init.defaultBranch, and then converting the tricky test\nscripts first, one by one, using that environment variable).\n\nChanges since v3:\n\n * We now avoid the phrasing \"specify a specific\" in the messages.\n   \n   \n * The git submodule patch has a better commit title now, and it also\n   adjusts the documentation more completely now (thanks, Philippe!).\n   \n   \n * A code comment in builtin/init-db.c was updated to no longer talk about a \n   symlink when it comes to HEAD.\n   \n   \n * Made it the responsibility of the caller to warn about reinit &&\n   initial_branch.\n   \n   \n\nChanges since v2:\n\n * Dropped the fast-export patches, as they have been superseded by Peff's \n   jk/fast-export-anonym\n   [https://github.com/gitgitgadget/git/commits/jk/fast-export-anonym].\n   \n   \n * Adjusted the fmt-merge-msg patch so as to not special-case master anymore\n   (instead of special-casing a specific \"main\" branch).\n   \n   \n * Modified the git submodule patch so that it uses origin/HEAD instead of\n   trying to look for a remote branch with the name indicated by \n   init.defaultBranch.\n   \n   \n\nChanges since v1:\n\n * The modifications to respect GIT_TEST_DEFAULT_BRANCH_NAME have been\n   backed out from this patch series, as they are only relevant once we\n   start converting the test suite to accommodate for a new default main\n   branch name.\n   \n   \n * An error message that started with an upper-case letter was downcased.\n   \n   \n * git_default_branch_name()'s logic was simplified by replacing an if ...\n   else ... by a ternary assignment.\n   \n   \n * The git_default_branch_name() function was renamed to \n   git_main_branch_name() and a corresponding repo_main_branch_name() was\n   introduced.\n   \n   \n * The \"init\" commit message's first paragraph now elaborates a little bit\n   on the reasoning why projects want to move away from the current default\n   branch name.\n   \n   \n * The \"init\" commit was split into two.\n   \n   \n * There are now two config settings: init.defaultBranch (defining the\n   branch name to use when initializing new repositories) and \n   core.mainBranch (which is now configured by init_db(), declaring what the\n   name of the main branch is in this repository).\n   \n   \n * The commits were re-ordered to introduce the concept of core.mainBranch \n   first because technically, this is something that we could do even\n   without changing git init at all.\n   \n   \n * git fast-export --anonymize now always uses the ref name ref0 for the\n   main branch, no matter whether it was overridden or whether the fall-back\n   is in effect.\n   \n   \n * The code comment regarding anonymizing the main branch to ref0 in git\n   fast-export --anonymize was enhanced.\n   \n   \n * A new patch was added to rename core.mainBranch if the main branch is\n   renamed via git branch -m.\n   \n   \n * Added a patch that introduces support for git init\n   --main-branch=<branch-name>.\n   \n   \n * Where possible, I added tests (although I did not try to extend test\n   coverage to all changes: the send-pack.c/transport-helper.c patch only\n   adds a test for the send-pack.c adjustment, for example).\n\nDon Goodman-Wilson (1):\n  init: allow setting the default for the initial branch name via the\n    config\n\nJohannes Schindelin (8):\n  fmt-merge-msg: stop treating `master` specially\n  send-pack/transport-helper: avoid mentioning a particular branch\n  submodule: fall back to remote's HEAD for missing remote.<name>.branch\n  docs: add missing diamond brackets\n  init: allow specifying the initial branch name for the new repository\n  clone: use configured default branch name when appropriate\n  remote: use the configured default branch name when appropriate\n  testsvn: respect `init.defaultBranch`\n\n Documentation/config/init.txt                 |  4 ++\n Documentation/git-branch.txt                  |  2 +-\n Documentation/git-clone.txt                   |  2 +-\n Documentation/git-init.txt                    |  9 ++-\n Documentation/git-submodule.txt               | 12 ++--\n Documentation/gitmodules.txt                  |  6 +-\n builtin/clone.c                               | 13 ++--\n builtin/init-db.c                             | 33 +++++++--\n builtin/submodule--helper.c                   |  2 +-\n cache.h                                       |  2 +-\n fmt-merge-msg.c                               |  5 +-\n refs.c                                        | 30 ++++++++\n refs.h                                        |  9 +++\n remote-testsvn.c                              | 10 ++-\n remote.c                                      | 14 +++-\n send-pack.c                                   |  2 +-\n t/t0001-init.sh                               | 26 +++++++\n t/t1507-rev-parse-upstream.sh                 |  2 +-\n t/t4013-diff-various.sh                       |  4 +-\n t/t4013/diff.log_--decorate=full_--all        |  2 +-\n t/t4013/diff.log_--decorate_--all             |  2 +-\n ...--patch-with-stat_--summary_master_--_dir_ |  2 +-\n t/t4013/diff.log_--patch-with-stat_master     |  2 +-\n .../diff.log_--patch-with-stat_master_--_dir_ |  2 +-\n ...ot_--cc_--patch-with-stat_--summary_master |  2 +-\n ..._--root_--patch-with-stat_--summary_master |  2 +-\n .../diff.log_--root_--patch-with-stat_master  |  2 +-\n ...root_-c_--patch-with-stat_--summary_master |  2 +-\n t/t4013/diff.log_--root_-p_master             |  2 +-\n t/t4013/diff.log_--root_master                |  2 +-\n t/t4013/diff.log_-m_-p_--first-parent_master  |  2 +-\n t/t4013/diff.log_-m_-p_master                 |  4 +-\n t/t4013/diff.log_-p_--first-parent_master     |  2 +-\n t/t4013/diff.log_-p_master                    |  2 +-\n t/t4013/diff.log_master                       |  2 +-\n t/t4013/diff.show_--first-parent_master       |  2 +-\n t/t4013/diff.show_-c_master                   |  2 +-\n t/t4013/diff.show_-m_master                   |  4 +-\n t/t4013/diff.show_master                      |  2 +-\n ...ot_--cc_--patch-with-stat_--summary_master |  2 +-\n ...root_-c_--patch-with-stat_--summary_master |  2 +-\n t/t4202-log.sh                                | 72 +++++++++----------\n t/t5528-push-default.sh                       |  6 ++\n t/t5606-clone-options.sh                      | 24 +++++++\n t/t6200-fmt-merge-msg.sh                      | 36 +++++-----\n t/t7406-submodule-update.sh                   | 16 +++++\n t/t7419-submodule-set-branch.sh               |  7 +-\n t/t7600-merge.sh                              | 14 ++--\n t/t7608-merge-messages.sh                     | 10 +--\n t/t9020-remote-svn.sh                         |  6 ++\n transport-helper.c                            |  2 +-\n 51 files changed, 297 insertions(+), 131 deletions(-)\n\n\nbase-commit: c9c318d6bf26bcecdca5b6f31683b9d5887a83ee\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-656%2Fdscho%2Fdefault-branch-name-option-v4\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-656/dscho/default-branch-name-option-v4\nPull-Request: https://github.com/gitgitgadget/git/pull/656\n\nRange-diff vs v3:\n\n  1:  fffdb9944f =  1:  fffdb9944f fmt-merge-msg: stop treating `master` specially\n  2:  a29943d7bb !  2:  1216de51ab send-pack/transport-helper: avoid mentioning a particular branch\n     @@ send-pack.c: int send_pack(struct send_pack_args *args,\n       \tif (!remote_refs) {\n       \t\tfprintf(stderr, \"No refs in common and none specified; doing nothing.\\n\"\n      -\t\t\t\"Perhaps you should specify a branch such as 'master'.\\n\");\n     -+\t\t\t\"Perhaps you should specify a specific branch.\\n\");\n     ++\t\t\t\"Perhaps you should specify a branch.\\n\");\n       \t\treturn 0;\n       \t}\n       \tif (args->atomic && !atomic_supported)\n     @@ t/t5528-push-default.sh: test_expect_success 'push from/to new branch with upstr\n      +test_expect_success '\"matching\" fails if none match' '\n      +\tgit init --bare empty &&\n      +\ttest_must_fail git push empty : 2>actual &&\n     -+\ttest_i18ngrep \"Perhaps you should specify a specific branch\" actual\n     ++\ttest_i18ngrep \"Perhaps you should specify a branch\" actual\n      +'\n      +\n       test_expect_success 'push ambiguously named branch with upstream, matching and simple' '\n     @@ transport-helper.c: static int push_refs(struct transport *transport,\n       \t\tfprintf(stderr,\n       \t\t\t_(\"No refs in common and none specified; doing nothing.\\n\"\n      -\t\t\t  \"Perhaps you should specify a branch such as 'master'.\\n\"));\n     -+\t\t\t  \"Perhaps you should specify a specific branch.\\n\"));\n     ++\t\t\t  \"Perhaps you should specify a branch.\\n\"));\n       \t\treturn 0;\n       \t}\n       \n  3:  6bda69541b !  3:  54563642db submodule: use a better fall-back for missing remote.<name>.branch\n     @@ Metadata\n      Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n      \n       ## Commit message ##\n     -    submodule: use a better fall-back for missing remote.<name>.branch\n     +    submodule: fall back to remote's HEAD for missing remote.<name>.branch\n      \n          When `remote.<name>.branch` is not configured, `git submodule update`\n          currently falls back to using the branch name `master`. A much better\n     -    idea, however, is to use `HEAD`: on all Git servers running reasonably\n     -    recent Git versions, the symref `HEAD` points to the main branch.\n     +    idea, however, is to use the remote `HEAD`: on all Git servers running\n     +    reasonably recent Git versions, the symref `HEAD` points to the main\n     +    branch.\n      \n          Note: t7419 demonstrates that there _might_ be use cases out there that\n          _expect_ `git submodule update --remote` to update submodules to the\n     @@ Commit message\n          there is a slight possibility that this might cause regressions in\n          obscure setups.\n      \n     +    Even so, it should be okay to fix this behavior without anything like a\n     +    longer transition period:\n     +\n     +    - The `git submodule update --remote` command is not really common.\n     +\n     +    - Current Git's behavior when running this command is outright\n     +      confusing, unless the remote repository's current branch _is_ `master`\n     +      (in which case the proposed behavior matches the old behavior).\n     +\n     +    - If a user encounters a regression due to the changed behavior, the fix\n     +      is actually trivial: setting `submodule.<name>.branch` to `master`\n     +      will reinstate the old behavior.\n     +\n     +    Helped-by: Philippe Blain <levraiphilippeblain@gmail.com>\n          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n      \n       ## Documentation/git-submodule.txt ##\n     +@@ Documentation/git-submodule.txt: set-branch (-d|--default) [--] <path>::\n     + \tSets the default remote tracking branch for the submodule. The\n     + \t`--branch` option allows the remote branch to be specified. The\n     + \t`--default` option removes the submodule.<name>.branch configuration\n     +-\tkey, which causes the tracking branch to default to 'master'.\n     ++\tkey, which causes the tracking branch to default to the remote 'HEAD'.\n     + \n     + set-url [--] <path> <newurl>::\n     + \tSets the URL of the specified submodule to <newurl>. Then, it will\n      @@ Documentation/git-submodule.txt: OPTIONS\n       \t`.gitmodules` for `update --remote`.  A special value of `.` is used to\n       \tindicate that the name of the branch in the submodule should be the\n       \tsame name as the current branch in the current repository.  If the\n      -\toption is not specified, it defaults to 'master'.\n     -+\toption is not specified, it defaults to 'HEAD'.\n     ++\toption is not specified, it defaults to the remote 'HEAD'.\n       \n       -f::\n       --force::\n     @@ Documentation/git-submodule.txt: OPTIONS\n       \tstatus of the submodule's remote-tracking branch.  The remote used\n       \tis branch's remote (`branch.<name>.remote`), defaulting to `origin`.\n      -\tThe remote branch used defaults to `master`, but the branch name may\n     -+\tThe remote branch used defaults to `HEAD`, but the branch name may\n     - \tbe overridden by setting the `submodule.<name>.branch` option in\n     - \teither `.gitmodules` or `.git/config` (with `.git/config` taking\n     - \tprecedence).\n     +-\tbe overridden by setting the `submodule.<name>.branch` option in\n     +-\teither `.gitmodules` or `.git/config` (with `.git/config` taking\n     +-\tprecedence).\n     ++\tThe remote branch used defaults to the remote `HEAD`, but the branch\n     ++\tname may be overridden by setting the `submodule.<name>.branch`\n     ++\toption in either `.gitmodules` or `.git/config` (with `.git/config`\n     ++\ttaking precedence).\n     + +\n     + This works for any of the supported update procedures (`--checkout`,\n     + `--rebase`, etc.).  The only change is the source of the target SHA-1.\n     +\n     + ## Documentation/gitmodules.txt ##\n     +@@ Documentation/gitmodules.txt: submodule.<name>.update::\n     + \n     + submodule.<name>.branch::\n     + \tA remote branch name for tracking updates in the upstream submodule.\n     +-\tIf the option is not specified, it defaults to 'master'.  A special\n     +-\tvalue of `.` is used to indicate that the name of the branch in the\n     +-\tsubmodule should be the same name as the current branch in the\n     ++\tIf the option is not specified, it defaults to the remote 'HEAD'.\n     ++\tA special value of `.` is used to indicate that the name of the branch\n     ++\tin the submodule should be the same name as the current branch in the\n     + \tcurrent repository.  See the `--remote` documentation in\n     + \tlinkgit:git-submodule[1] for details.\n     + \n      \n       ## builtin/submodule--helper.c ##\n      @@ builtin/submodule--helper.c: static const char *remote_submodule_branch(const char *path)\n  -:  ---------- >  4:  1d723d35ed docs: add missing diamond brackets\n  4:  e8a6587c1a !  5:  9edd4fd3b2 init: allow specifying the initial branch name for the new repository\n     @@ Documentation/git-init.txt\n      @@ Documentation/git-init.txt: SYNOPSIS\n       [verse]\n       'git init' [-q | --quiet] [--bare] [--template=<template_directory>]\n     - \t  [--separate-git-dir <git dir>] [--object-format=<format]\n     + \t  [--separate-git-dir <git dir>] [--object-format=<format>]\n      +\t  [-b <branch-name> | --initial-branch=<branch-name>]\n       \t  [--shared[=<permissions>]] [directory]\n       \n     @@ builtin/init-db.c: static int create_default_files(const char *template_path,\n       \t/*\n      -\t * Create the default symlink from \".git/HEAD\" to the \"master\"\n      -\t * branch, if it does not exist yet.\n     -+\t * Create the default symlink from \".git/HEAD\" to the default\n     -+\t * branch name, if it does not exist yet.\n     ++\t * Point the HEAD symref to the initial branch with if HEAD does\n     ++\t * not yet exist.\n       \t */\n       \tpath = git_path_buf(&buf, \"HEAD\");\n       \treinit = (!access(path, R_OK)\n     @@ builtin/init-db.c: static int create_default_files(const char *template_path,\n      +\n      +\t\tif (create_symref(\"HEAD\", ref, NULL) < 0)\n       \t\t\texit(1);\n     --\t}\n      +\t\tfree(ref);\n     -+\t} else if (initial_branch)\n     -+\t\twarning(_(\"re-init: ignoring --initial-branch=%s\"),\n     -+\t\t\tinitial_branch);\n     + \t}\n       \n       \tinitialize_repository_version(fmt->hash_algo);\n     - \n      @@ builtin/init-db.c: static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash\n       }\n       \n     @@ builtin/init-db.c: int init_db(const char *git_dir, const char *real_git_dir,\n      -\treinit = create_default_files(template_dir, original_git_dir, &repo_fmt);\n      +\treinit = create_default_files(template_dir, original_git_dir,\n      +\t\t\t\t      initial_branch, &repo_fmt);\n     ++\tif (reinit && initial_branch)\n     ++\t\twarning(_(\"re-init: ignored --initial-branch=%s\"),\n     ++\t\t\tinitial_branch);\n       \n       \tcreate_object_directory();\n       \n     @@ t/t0001-init.sh: test_expect_success MINGW 'redirect std handles' '\n      +\n      +\t: re-initializing should not change the branch name &&\n      +\tgit init --initial-branch=ignore initial-branch-option 2>err &&\n     -+\ttest_i18ngrep \"ignoring --initial-branch\" err &&\n     ++\ttest_i18ngrep \"ignored --initial-branch\" err &&\n      +\tgit -C initial-branch-option symbolic-ref HEAD >actual &&\n      +\tgrep hello actual\n      +'\n  5:  a500e0f214 =  6:  7747eaa57d init: allow setting the default for the initial branch name via the config\n  6:  c0d74cedd1 =  7:  1cff7705e4 clone: use configured default branch name when appropriate\n  7:  00a1b281e5 !  8:  0a7c0bdfda remote: use the configured default branch name when appropriate\n     @@ remote.c: static void read_branches_file(struct remote *remote)\n       \t/*\n       \t * The branches file would have URL and optionally\n      -\t * #branch specified.  The \"master\" (or specified) branch is\n     -+\t * #branch specified.  The main (or specified) branch is\n     ++\t * #branch specified.  The default (or specified) branch is\n       \t * fetched and stored in the local branch matching the\n       \t * remote name.\n       \t */\n  8:  1aa0e63785 =  9:  6c72abf677 testsvn: respect `init.defaultBranch`\n\n-- \ngitgitgadget\n"},{"id":"400507","messageId":"1216de51abee7f5614c4d639e42fce3308100830.1593009996.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v4.git.1593009996.gitgitgadget@gmail.com","subject":"[PATCH v4 2/9] send-pack/transport-helper: avoid mentioning a particular branch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-24T14:46:29Z","receivedAt":"2020-06-24T14:46:45Z","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\nWhen trying to push all matching branches, but none match, we offer a\nmessage suggesting to push the `master` branch.\n\nHowever, we want to step away from making that branch any more special\nthan any other branch, so let's reword that message to mention no branch\nin particular.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n send-pack.c             | 2 +-\n t/t5528-push-default.sh | 6 ++++++\n transport-helper.c      | 2 +-\n 3 files changed, 8 insertions(+), 2 deletions(-)\n\ndiff --git a/send-pack.c b/send-pack.c\nindex 0abee22283..19eb9b04e4 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -406,7 +406,7 @@ int send_pack(struct send_pack_args *args,\n \n \tif (!remote_refs) {\n \t\tfprintf(stderr, \"No refs in common and none specified; doing nothing.\\n\"\n-\t\t\t\"Perhaps you should specify a branch such as 'master'.\\n\");\n+\t\t\t\"Perhaps you should specify a branch.\\n\");\n \t\treturn 0;\n \t}\n \tif (args->atomic && !atomic_supported)\ndiff --git a/t/t5528-push-default.sh b/t/t5528-push-default.sh\nindex 4d1e0c363e..f0a287d97d 100755\n--- a/t/t5528-push-default.sh\n+++ b/t/t5528-push-default.sh\n@@ -98,6 +98,12 @@ test_expect_success 'push from/to new branch with upstream, matching and simple'\n \ttest_push_failure upstream\n '\n \n+test_expect_success '\"matching\" fails if none match' '\n+\tgit init --bare empty &&\n+\ttest_must_fail git push empty : 2>actual &&\n+\ttest_i18ngrep \"Perhaps you should specify a branch\" actual\n+'\n+\n test_expect_success 'push ambiguously named branch with upstream, matching and simple' '\n \tgit checkout -b ambiguous &&\n \ttest_config branch.ambiguous.remote parent1 &&\ndiff --git a/transport-helper.c b/transport-helper.c\nindex a46afcb69d..8a711cda29 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -1046,7 +1046,7 @@ static int push_refs(struct transport *transport,\n \tif (!remote_refs) {\n \t\tfprintf(stderr,\n \t\t\t_(\"No refs in common and none specified; doing nothing.\\n\"\n-\t\t\t  \"Perhaps you should specify a branch such as 'master'.\\n\"));\n+\t\t\t  \"Perhaps you should specify a branch.\\n\"));\n \t\treturn 0;\n \t}\n \n-- \ngitgitgadget\n\n"},{"id":"400508","messageId":"1cff7705e43ef79902e03f1420d611c53429ea11.1593009996.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v4.git.1593009996.gitgitgadget@gmail.com","subject":"[PATCH v4 7/9] clone: use configured default branch name when appropriate","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-24T14:46:34Z","receivedAt":"2020-06-24T14:46:50Z","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\nWhen cloning a repository without any branches, Git chooses a default\nbranch name for the as-yet unborn branch.\n\nAs part of the implicit initialization of the local repository, Git just\nlearned to respect `init.defaultBranch` to choose a different initial\nbranch name. We now really want that branch name to be used as a\nfall-back.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/config/init.txt |  4 ++--\n builtin/clone.c               | 10 +++++++---\n t/t5606-clone-options.sh      | 15 +++++++++++++++\n 3 files changed, 24 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/config/init.txt b/Documentation/config/init.txt\nindex 6ae4a38416..dc77f8c844 100644\n--- a/Documentation/config/init.txt\n+++ b/Documentation/config/init.txt\n@@ -3,5 +3,5 @@ init.templateDir::\n \t(See the \"TEMPLATE DIRECTORY\" section of linkgit:git-init[1].)\n \n init.defaultBranch::\n-\tAllows overriding the default branch name when initializing\n-\ta new repository.\n+\tAllows overriding the default branch name e.g. when initializing\n+\ta new repository or when cloning an empty repository.\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex b751bdf13e..9a3f91b268 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -1267,9 +1267,13 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\tremote_head_points_at = NULL;\n \t\tremote_head = NULL;\n \t\toption_no_checkout = 1;\n-\t\tif (!option_bare)\n-\t\t\tinstall_branch_config(0, \"master\", option_origin,\n-\t\t\t\t\t      \"refs/heads/master\");\n+\t\tif (!option_bare) {\n+\t\t\tconst char *branch = git_default_branch_name();\n+\t\t\tchar *ref = xstrfmt(\"refs/heads/%s\", branch);\n+\n+\t\t\tinstall_branch_config(0, branch, option_origin, ref);\n+\t\t\tfree(ref);\n+\t\t}\n \t}\n \n \twrite_refspec_config(src_ref_prefix, our_head_points_at,\ndiff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh\nindex 9e24ec88e6..286bfd93ac 100755\n--- a/t/t5606-clone-options.sh\n+++ b/t/t5606-clone-options.sh\n@@ -35,4 +35,19 @@ test_expect_success 'redirected clone -v does show progress' '\n \n '\n \n+test_expect_success 'chooses correct default initial branch name' '\n+\tgit init --bare empty &&\n+\tgit -c init.defaultBranch=up clone empty whats-up &&\n+\ttest refs/heads/up = $(git -C whats-up symbolic-ref HEAD) &&\n+\ttest refs/heads/up = $(git -C whats-up config branch.up.merge)\n+'\n+\n+test_expect_success 'guesses initial branch name correctly' '\n+\tgit init --initial-branch=guess initial-branch &&\n+\ttest_commit -C initial-branch no-spoilers &&\n+\tgit -C initial-branch branch abc guess &&\n+\tgit clone initial-branch is-it &&\n+\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD)\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"400509","messageId":"6c72abf677db0776a124a34f3e58ec58c36dd93f.1593009996.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v4.git.1593009996.gitgitgadget@gmail.com","subject":"[PATCH v4 9/9] testsvn: respect `init.defaultBranch`","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-24T14:46:36Z","receivedAt":"2020-06-24T14:46:51Z","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\nThe default name of the initial branch in new repositories can now be\nconfigured. The `testsvn` remote helper translates the remote Subversion\nrepository's branch name `trunk` to the hard-coded name `master`.\nClearly, the intention was to make the name align with Git's defaults.\n\nSo while we are not talking about a newly-created repository in the\n`testsvn` context, it is a newly-created _Git_ repository, si it _still_\nmakes sense to use the overridden default name for the initial branch\nwhenever users configured it.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n remote-testsvn.c      | 10 +++++++---\n t/t9020-remote-svn.sh |  6 ++++++\n 2 files changed, 13 insertions(+), 3 deletions(-)\n\ndiff --git a/remote-testsvn.c b/remote-testsvn.c\nindex 3af708c5b6..cde39b94fb 100644\n--- a/remote-testsvn.c\n+++ b/remote-testsvn.c\n@@ -13,7 +13,7 @@\n static const char *url;\n static int dump_from_file;\n static const char *private_ref;\n-static const char *remote_ref = \"refs/heads/master\";\n+static char *remote_ref;\n static const char *marksfilename, *notes_ref;\n struct rev_note { unsigned int rev_nr; };\n \n@@ -286,7 +286,7 @@ int cmd_main(int argc, const char **argv)\n \t\t\tprivate_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT,\n \t\t\tnotes_ref_sb = STRBUF_INIT;\n \tstatic struct remote *remote;\n-\tconst char *url_in;\n+\tconst char *url_in, *remote_ref_short;\n \n \tsetup_git_directory();\n \tif (argc < 2 || argc > 3) {\n@@ -294,6 +294,9 @@ int cmd_main(int argc, const char **argv)\n \t\treturn 1;\n \t}\n \n+\tremote_ref_short = git_default_branch_name();\n+\tremote_ref = xstrfmt(\"refs/heads/%s\", remote_ref_short);\n+\n \tremote = remote_get(argv[1]);\n \turl_in = (argc == 3) ? argv[2] : remote->url[0];\n \n@@ -306,7 +309,8 @@ int cmd_main(int argc, const char **argv)\n \t\turl = url_sb.buf;\n \t}\n \n-\tstrbuf_addf(&private_ref_sb, \"refs/svn/%s/master\", remote->name);\n+\tstrbuf_addf(&private_ref_sb, \"refs/svn/%s/%s\",\n+\t\t    remote->name, remote_ref_short);\n \tprivate_ref = private_ref_sb.buf;\n \n \tstrbuf_addf(&notes_ref_sb, \"refs/notes/%s/revs\", remote->name);\ndiff --git a/t/t9020-remote-svn.sh b/t/t9020-remote-svn.sh\nindex 9fcfa969a9..754c4a3284 100755\n--- a/t/t9020-remote-svn.sh\n+++ b/t/t9020-remote-svn.sh\n@@ -84,6 +84,12 @@ test_expect_success REMOTE_SVN 'incremental imports must lead to the same head'\n \ttest_cmp master.good .git/refs/remotes/svnsim/master\n '\n \n+test_expect_success REMOTE_SVN 'respects configured default initial branch' '\n+\tgit -c init.defaultBranch=trunk remote add -f trunk \\\n+\t\t\"testsvn::file://$TEST_DIRECTORY/t9154/svn.dump\" &&\n+\tgit rev-parse --verify refs/remotes/trunk/trunk\n+'\n+\n test_debug 'git branch -a'\n \n test_done\n-- \ngitgitgadget\n"},{"id":"400510","messageId":"0a7c0bdfda0bd7af284d317531d0f3985a4077e5.1593009996.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v4.git.1593009996.gitgitgadget@gmail.com","subject":"[PATCH v4 8/9] remote: use the configured default branch name when appropriate","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-24T14:46:35Z","receivedAt":"2020-06-24T14:46:54Z","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\nWhen guessing the default branch name of a remote, and there are no refs\nto guess from, we want to go with the preference specified by the user\nfor the fall-back, i.e. the default name to be used for the initial\nbranch of new repositories (because as far as the user is concerned, a\nremote that has no branches yet is a new repository).\n\nAt the same time, when talking to an older Git server that does not\nreport a symref for `HEAD` (but instead reports a commit hash), let's\ntry to guess the configured default branch name first. If it does not\nmatch the reported commit hash, let's fall back to `master` as before.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n remote.c                 | 14 +++++++++++---\n t/t5606-clone-options.sh | 11 ++++++++++-\n 2 files changed, 21 insertions(+), 4 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex 534c6426f1..bc46413e6a 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -276,7 +276,7 @@ static void read_branches_file(struct remote *remote)\n \n \t/*\n \t * The branches file would have URL and optionally\n-\t * #branch specified.  The \"master\" (or specified) branch is\n+\t * #branch specified.  The default (or specified) branch is\n \t * fetched and stored in the local branch matching the\n \t * remote name.\n \t */\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 = \"master\";\n+\t\tfrag = (char *)git_default_branch_name();\n \n \tadd_url_alias(remote, strbuf_detach(&buf, NULL));\n \tstrbuf_addf(&buf, \"refs/heads/%s:refs/heads/%s\",\n@@ -2097,8 +2097,16 @@ struct ref *guess_remote_head(const struct ref *head,\n \tif (head->symref)\n \t\treturn copy_ref(find_ref_by_name(refs, head->symref));\n \n-\t/* If refs/heads/master could be right, it is. */\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+\n+\t\tr = find_ref_by_name(refs, ref);\n+\t\tfree(ref);\n+\t\tif (r && oideq(&r->old_oid, &head->old_oid))\n+\t\t\treturn copy_ref(r);\n+\n+\t\t/* Fall back to the hard-coded historical default */\n \t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n \t\tif (r && oideq(&r->old_oid, &head->old_oid))\n \t\t\treturn copy_ref(r);\ndiff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh\nindex 286bfd93ac..e69427f881 100755\n--- a/t/t5606-clone-options.sh\n+++ b/t/t5606-clone-options.sh\n@@ -47,7 +47,16 @@ test_expect_success 'guesses initial branch name correctly' '\n \ttest_commit -C initial-branch no-spoilers &&\n \tgit -C initial-branch branch abc guess &&\n \tgit clone initial-branch is-it &&\n-\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD)\n+\ttest refs/heads/guess = $(git -C is-it symbolic-ref HEAD) &&\n+\n+\tgit -c init.defaultBranch=none init --bare no-head &&\n+\tgit -C initial-branch push ../no-head guess abc &&\n+\tgit clone no-head is-it2 &&\n+\ttest_must_fail git -C is-it2 symbolic-ref refs/remotes/origin/HEAD &&\n+\tgit -C no-head update-ref --no-deref HEAD refs/heads/guess &&\n+\tgit -c init.defaultBranch=guess clone no-head is-it3 &&\n+\ttest refs/remotes/origin/guess = \\\n+\t\t$(git -C is-it3 symbolic-ref refs/remotes/origin/HEAD)\n '\n \n test_done\n-- \ngitgitgadget\n\n"},{"id":"400511","messageId":"1d723d35ed107e084a363b5eeb2b505dbe0c21eb.1593009996.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v4.git.1593009996.gitgitgadget@gmail.com","subject":"[PATCH v4 4/9] docs: add missing diamond brackets","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-24T14:46:31Z","receivedAt":"2020-06-24T14:46:58Z","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\nThere were a couple of instances in our manual pages that had an\nopening diamond bracket without a corresponding closing one.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/git-branch.txt | 2 +-\n Documentation/git-clone.txt  | 2 +-\n Documentation/git-init.txt   | 2 +-\n 3 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex 135206ff4a..03c0824d52 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -12,7 +12,7 @@ SYNOPSIS\n \t[-v [--abbrev=<length> | --no-abbrev]]\n \t[--column[=<options>] | --no-column] [--sort=<key>]\n \t[(--merged | --no-merged) [<commit>]]\n-\t[--contains [<commit]] [--no-contains [<commit>]]\n+\t[--contains [<commit>]] [--no-contains [<commit>]]\n \t[--points-at <object>] [--format=<format>]\n \t[(-r | --remotes) | (-a | --all)]\n \t[--list] [<pattern>...]\ndiff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt\nindex 08d6045c4a..c898310099 100644\n--- a/Documentation/git-clone.txt\n+++ b/Documentation/git-clone.txt\n@@ -259,7 +259,7 @@ maintain a branch with no references other than a single cloned\n branch. This is useful e.g. to maintain minimal clones of the default\n branch of some repository for search indexing.\n \n---recurse-submodules[=<pathspec]::\n+--recurse-submodules[=<pathspec>]::\n \tAfter the clone is created, initialize and clone submodules\n \twithin based on the provided pathspec.  If no pathspec is\n \tprovided, all submodules are initialized and cloned.\ndiff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\nindex adc6adfd38..f9467cc6a4 100644\n--- a/Documentation/git-init.txt\n+++ b/Documentation/git-init.txt\n@@ -10,7 +10,7 @@ SYNOPSIS\n --------\n [verse]\n 'git init' [-q | --quiet] [--bare] [--template=<template_directory>]\n-\t  [--separate-git-dir <git dir>] [--object-format=<format]\n+\t  [--separate-git-dir <git dir>] [--object-format=<format>]\n \t  [--shared[=<permissions>]] [directory]\n \n \n-- \ngitgitgadget\n\n"},{"id":"400512","messageId":"54563642dbf96fcb36993c2c2d36ebefaf220cce.1593009996.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v4.git.1593009996.gitgitgadget@gmail.com","subject":"[PATCH v4 3/9] submodule: fall back to remote's HEAD for missing remote.<name>.branch","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-24T14:46:30Z","receivedAt":"2020-06-24T14:46:59Z","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\nWhen `remote.<name>.branch` is not configured, `git submodule update`\ncurrently falls back to using the branch name `master`. A much better\nidea, however, is to use the remote `HEAD`: on all Git servers running\nreasonably recent Git versions, the symref `HEAD` points to the main\nbranch.\n\nNote: t7419 demonstrates that there _might_ be use cases out there that\n_expect_ `git submodule update --remote` to update submodules to the\nremote `master` branch even if the remote `HEAD` points to another\nbranch. Arguably, this patch makes the behavior more intuitive, but\nthere is a slight possibility that this might cause regressions in\nobscure setups.\n\nEven so, it should be okay to fix this behavior without anything like a\nlonger transition period:\n\n- The `git submodule update --remote` command is not really common.\n\n- Current Git's behavior when running this command is outright\n  confusing, unless the remote repository's current branch _is_ `master`\n  (in which case the proposed behavior matches the old behavior).\n\n- If a user encounters a regression due to the changed behavior, the fix\n  is actually trivial: setting `submodule.<name>.branch` to `master`\n  will reinstate the old behavior.\n\nHelped-by: Philippe Blain <levraiphilippeblain@gmail.com>\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/git-submodule.txt | 12 ++++++------\n Documentation/gitmodules.txt    |  6 +++---\n builtin/submodule--helper.c     |  2 +-\n t/t7406-submodule-update.sh     | 16 ++++++++++++++++\n t/t7419-submodule-set-branch.sh |  7 +++++--\n 5 files changed, 31 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex c9ed2bf3d5..7e5f995f77 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -183,7 +183,7 @@ set-branch (-d|--default) [--] <path>::\n \tSets the default remote tracking branch for the submodule. The\n \t`--branch` option allows the remote branch to be specified. The\n \t`--default` option removes the submodule.<name>.branch configuration\n-\tkey, which causes the tracking branch to default to 'master'.\n+\tkey, which causes the tracking branch to default to the remote 'HEAD'.\n \n set-url [--] <path> <newurl>::\n \tSets the URL of the specified submodule to <newurl>. Then, it will\n@@ -284,7 +284,7 @@ OPTIONS\n \t`.gitmodules` for `update --remote`.  A special value of `.` is used to\n \tindicate that the name of the branch in the submodule should be the\n \tsame name as the current branch in the current repository.  If the\n-\toption is not specified, it defaults to 'master'.\n+\toption is not specified, it defaults to the remote 'HEAD'.\n \n -f::\n --force::\n@@ -322,10 +322,10 @@ OPTIONS\n \tthe superproject's recorded SHA-1 to update the submodule, use the\n \tstatus of the submodule's remote-tracking branch.  The remote used\n \tis branch's remote (`branch.<name>.remote`), defaulting to `origin`.\n-\tThe remote branch used defaults to `master`, but the branch name may\n-\tbe overridden by setting the `submodule.<name>.branch` option in\n-\teither `.gitmodules` or `.git/config` (with `.git/config` taking\n-\tprecedence).\n+\tThe remote branch used defaults to the remote `HEAD`, but the branch\n+\tname may be overridden by setting the `submodule.<name>.branch`\n+\toption in either `.gitmodules` or `.git/config` (with `.git/config`\n+\ttaking precedence).\n +\n This works for any of the supported update procedures (`--checkout`,\n `--rebase`, etc.).  The only change is the source of the target SHA-1.\ndiff --git a/Documentation/gitmodules.txt b/Documentation/gitmodules.txt\nindex 67275fd187..539b4e1997 100644\n--- a/Documentation/gitmodules.txt\n+++ b/Documentation/gitmodules.txt\n@@ -49,9 +49,9 @@ submodule.<name>.update::\n \n submodule.<name>.branch::\n \tA remote branch name for tracking updates in the upstream submodule.\n-\tIf the option is not specified, it defaults to 'master'.  A special\n-\tvalue of `.` is used to indicate that the name of the branch in the\n-\tsubmodule should be the same name as the current branch in the\n+\tIf the option is not specified, it defaults to the remote 'HEAD'.\n+\tA special value of `.` is used to indicate that the name of the branch\n+\tin the submodule should be the same name as the current branch in the\n \tcurrent repository.  See the `--remote` documentation in\n \tlinkgit:git-submodule[1] for details.\n \ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 46c03d2a12..f55f7b7704 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1981,7 +1981,7 @@ static const char *remote_submodule_branch(const char *path)\n \tfree(key);\n \n \tif (!branch)\n-\t\treturn \"master\";\n+\t\treturn \"HEAD\";\n \n \tif (!strcmp(branch, \".\")) {\n \t\tconst char *refname = resolve_ref_unsafe(\"HEAD\", 0, NULL, NULL);\ndiff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\nindex 4fb447a143..aa19ff3a2e 100755\n--- a/t/t7406-submodule-update.sh\n+++ b/t/t7406-submodule-update.sh\n@@ -70,6 +70,22 @@ test_expect_success 'setup a submodule tree' '\n \t)\n '\n \n+test_expect_success 'update --remote falls back to using HEAD' '\n+\ttest_create_repo main-branch-submodule &&\n+\ttest_commit -C main-branch-submodule initial &&\n+\n+\ttest_create_repo main-branch &&\n+\tgit -C main-branch submodule add ../main-branch-submodule &&\n+\tgit -C main-branch commit -m add-submodule &&\n+\n+\tgit -C main-branch-submodule switch -c hello &&\n+\ttest_commit -C main-branch-submodule world &&\n+\n+\tgit clone --recursive main-branch main-branch-clone &&\n+\tgit -C main-branch-clone submodule update --remote main-branch-submodule &&\n+\ttest_path_exists main-branch-clone/main-branch-submodule/world.t\n+'\n+\n test_expect_success 'submodule update detaching the HEAD ' '\n \t(cd super/submodule &&\n \t git reset --hard HEAD~1\ndiff --git a/t/t7419-submodule-set-branch.sh b/t/t7419-submodule-set-branch.sh\nindex fd25f786a3..3b925c302f 100755\n--- a/t/t7419-submodule-set-branch.sh\n+++ b/t/t7419-submodule-set-branch.sh\n@@ -52,12 +52,13 @@ test_expect_success 'test submodule set-branch --branch' '\n '\n \n test_expect_success 'test submodule set-branch --default' '\n+\ttest_commit -C submodule c &&\n \t(cd super &&\n \t\tgit submodule set-branch --default submodule &&\n \t\t! grep branch .gitmodules &&\n \t\tgit submodule update --remote &&\n \t\tcat <<-\\EOF >expect &&\n-\t\ta\n+\t\tc\n \t\tEOF\n \t\tgit -C submodule show -s --pretty=%s >actual &&\n \t\ttest_cmp expect actual\n@@ -65,6 +66,7 @@ test_expect_success 'test submodule set-branch --default' '\n '\n \n test_expect_success 'test submodule set-branch -b' '\n+\ttest_commit -C submodule b &&\n \t(cd super &&\n \t\tgit submodule set-branch -b topic submodule &&\n \t\tgrep \"branch = topic\" .gitmodules &&\n@@ -78,12 +80,13 @@ test_expect_success 'test submodule set-branch -b' '\n '\n \n test_expect_success 'test submodule set-branch -d' '\n+\ttest_commit -C submodule d &&\n \t(cd super &&\n \t\tgit submodule set-branch -d submodule &&\n \t\t! grep branch .gitmodules &&\n \t\tgit submodule update --remote &&\n \t\tcat <<-\\EOF >expect &&\n-\t\ta\n+\t\td\n \t\tEOF\n \t\tgit -C submodule show -s --pretty=%s >actual &&\n \t\ttest_cmp expect actual\n-- \ngitgitgadget\n\n"},{"id":"400513","messageId":"fffdb9944fc2672ccb7eac776cdd18855a1f99dc.1593009996.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v4.git.1593009996.gitgitgadget@gmail.com","subject":"[PATCH v4 1/9] fmt-merge-msg: stop treating `master` specially","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-24T14:46:28Z","receivedAt":"2020-06-24T14:46:59Z","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 the context of many projects renaming their primary branch names away\nfrom `master`, Git wants to stop treating the `master` branch specially.\n\nLet's start with `git fmt-merge-msg`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n fmt-merge-msg.c                               |  5 +-\n t/t1507-rev-parse-upstream.sh                 |  2 +-\n t/t4013-diff-various.sh                       |  4 +-\n t/t4013/diff.log_--decorate=full_--all        |  2 +-\n t/t4013/diff.log_--decorate_--all             |  2 +-\n ...--patch-with-stat_--summary_master_--_dir_ |  2 +-\n t/t4013/diff.log_--patch-with-stat_master     |  2 +-\n .../diff.log_--patch-with-stat_master_--_dir_ |  2 +-\n ...ot_--cc_--patch-with-stat_--summary_master |  2 +-\n ..._--root_--patch-with-stat_--summary_master |  2 +-\n .../diff.log_--root_--patch-with-stat_master  |  2 +-\n ...root_-c_--patch-with-stat_--summary_master |  2 +-\n t/t4013/diff.log_--root_-p_master             |  2 +-\n t/t4013/diff.log_--root_master                |  2 +-\n t/t4013/diff.log_-m_-p_--first-parent_master  |  2 +-\n t/t4013/diff.log_-m_-p_master                 |  4 +-\n t/t4013/diff.log_-p_--first-parent_master     |  2 +-\n t/t4013/diff.log_-p_master                    |  2 +-\n t/t4013/diff.log_master                       |  2 +-\n t/t4013/diff.show_--first-parent_master       |  2 +-\n t/t4013/diff.show_-c_master                   |  2 +-\n t/t4013/diff.show_-m_master                   |  4 +-\n t/t4013/diff.show_master                      |  2 +-\n ...ot_--cc_--patch-with-stat_--summary_master |  2 +-\n ...root_-c_--patch-with-stat_--summary_master |  2 +-\n t/t4202-log.sh                                | 72 +++++++++----------\n t/t6200-fmt-merge-msg.sh                      | 36 +++++-----\n t/t7600-merge.sh                              | 14 ++--\n t/t7608-merge-messages.sh                     | 10 +--\n 29 files changed, 94 insertions(+), 97 deletions(-)\n\ndiff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\nindex 72d32bd73b..cfb8ff2f33 100644\n--- a/fmt-merge-msg.c\n+++ b/fmt-merge-msg.c\n@@ -451,10 +451,7 @@ static void fmt_merge_msg_title(struct strbuf *out,\n \t\t\tstrbuf_addf(out, \" of %s\", srcs.items[i].string);\n \t}\n \n-\tif (!strcmp(\"master\", current_branch))\n-\t\tstrbuf_addch(out, '\\n');\n-\telse\n-\t\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n+\tstrbuf_addf(out, \" into %s\\n\", current_branch);\n }\n \n static void fmt_tag_signature(struct strbuf *tagbuf,\ndiff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh\nindex dfc0d96d8a..f213aa8053 100755\n--- a/t/t1507-rev-parse-upstream.sh\n+++ b/t/t1507-rev-parse-upstream.sh\n@@ -137,7 +137,7 @@ test_expect_success 'merge my-side@{u} records the correct name' '\n \tgit branch -t new my-side@{u} &&\n \tgit merge -s ours new@{u} &&\n \tgit show -s --pretty=tformat:%s >actual &&\n-\techo \"Merge remote-tracking branch ${SQ}origin/side${SQ}\" >expect &&\n+\techo \"Merge remote-tracking branch ${SQ}origin/side${SQ} into master\" >expect &&\n \ttest_cmp expect actual\n )\n '\ndiff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh\nindex 3f60f7d96c..43267d6024 100755\n--- a/t/t4013-diff-various.sh\n+++ b/t/t4013-diff-various.sh\n@@ -117,12 +117,12 @@ test_expect_success setup '\n \n : <<\\EOF\n ! [initial] Initial\n- * [master] Merge branch 'side'\n+ * [master] Merge branch 'side' into master\n   ! [rearrange] Rearranged lines in dir/sub\n    ! [side] Side\n ----\n   +  [rearrange] Rearranged lines in dir/sub\n- -   [master] Merge branch 'side'\n+ -   [master] Merge branch 'side' into master\n  * + [side] Side\n  *   [master^] Third\n  *   [master~2] Second\ndiff --git a/t/t4013/diff.log_--decorate=full_--all b/t/t4013/diff.log_--decorate=full_--all\nindex 3f9b872ece..c56783b985 100644\n--- a/t/t4013/diff.log_--decorate=full_--all\n+++ b/t/t4013/diff.log_--decorate=full_--all\n@@ -31,7 +31,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (refs/heads/side)\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--decorate_--all b/t/t4013/diff.log_--decorate_--all\nindex f5e20e1e14..1cbdc038f4 100644\n--- a/t/t4013/diff.log_--decorate_--all\n+++ b/t/t4013/diff.log_--decorate_--all\n@@ -31,7 +31,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (side)\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--patch-with-stat_--summary_master_--_dir_ b/t/t4013/diff.log_--patch-with-stat_--summary_master_--_dir_\nindex a18f1472a9..f5b1b6516b 100644\n--- a/t/t4013/diff.log_--patch-with-stat_--summary_master_--_dir_\n+++ b/t/t4013/diff.log_--patch-with-stat_--summary_master_--_dir_\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--patch-with-stat_master b/t/t4013/diff.log_--patch-with-stat_master\nindex ae425c4672..af23803cdc 100644\n--- a/t/t4013/diff.log_--patch-with-stat_master\n+++ b/t/t4013/diff.log_--patch-with-stat_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--patch-with-stat_master_--_dir_ b/t/t4013/diff.log_--patch-with-stat_master_--_dir_\nindex d5207cadf4..814098fbf8 100644\n--- a/t/t4013/diff.log_--patch-with-stat_master_--_dir_\n+++ b/t/t4013/diff.log_--patch-with-stat_master_--_dir_\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--root_--cc_--patch-with-stat_--summary_master b/t/t4013/diff.log_--root_--cc_--patch-with-stat_--summary_master\nindex 0fc1e8cd71..b927fe4a98 100644\n--- a/t/t4013/diff.log_--root_--cc_--patch-with-stat_--summary_master\n+++ b/t/t4013/diff.log_--root_--cc_--patch-with-stat_--summary_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n  dir/sub | 2 ++\n  file0   | 3 +++\ndiff --git a/t/t4013/diff.log_--root_--patch-with-stat_--summary_master b/t/t4013/diff.log_--root_--patch-with-stat_--summary_master\nindex dffc09dde9..6db3cea329 100644\n--- a/t/t4013/diff.log_--root_--patch-with-stat_--summary_master\n+++ b/t/t4013/diff.log_--root_--patch-with-stat_--summary_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--root_--patch-with-stat_master b/t/t4013/diff.log_--root_--patch-with-stat_master\nindex 55aa98012d..98e9c320c3 100644\n--- a/t/t4013/diff.log_--root_--patch-with-stat_master\n+++ b/t/t4013/diff.log_--root_--patch-with-stat_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--root_-c_--patch-with-stat_--summary_master b/t/t4013/diff.log_--root_-c_--patch-with-stat_--summary_master\nindex 019d85f7de..b61b1117ae 100644\n--- a/t/t4013/diff.log_--root_-c_--patch-with-stat_--summary_master\n+++ b/t/t4013/diff.log_--root_-c_--patch-with-stat_--summary_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n  dir/sub | 2 ++\n  file0   | 3 +++\ndiff --git a/t/t4013/diff.log_--root_-p_master b/t/t4013/diff.log_--root_-p_master\nindex b42c334439..345bd9e8a9 100644\n--- a/t/t4013/diff.log_--root_-p_master\n+++ b/t/t4013/diff.log_--root_-p_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_--root_master b/t/t4013/diff.log_--root_master\nindex e8f46159da..db56b1fe6b 100644\n--- a/t/t4013/diff.log_--root_master\n+++ b/t/t4013/diff.log_--root_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_-m_-p_--first-parent_master b/t/t4013/diff.log_-m_-p_--first-parent_master\nindex 7a0073f529..bcadb50e26 100644\n--- a/t/t4013/diff.log_-m_-p_--first-parent_master\n+++ b/t/t4013/diff.log_-m_-p_--first-parent_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --git a/dir/sub b/dir/sub\n index cead32e..992913c 100644\ndiff --git a/t/t4013/diff.log_-m_-p_master b/t/t4013/diff.log_-m_-p_master\nindex 9ca62a01ed..2acf43a9fb 100644\n--- a/t/t4013/diff.log_-m_-p_master\n+++ b/t/t4013/diff.log_-m_-p_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --git a/dir/sub b/dir/sub\n index cead32e..992913c 100644\n@@ -33,7 +33,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --git a/dir/sub b/dir/sub\n index 7289e35..992913c 100644\ndiff --git a/t/t4013/diff.log_-p_--first-parent_master b/t/t4013/diff.log_-p_--first-parent_master\nindex 3fc896d424..c6a5876d80 100644\n--- a/t/t4013/diff.log_-p_--first-parent_master\n+++ b/t/t4013/diff.log_-p_--first-parent_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_-p_master b/t/t4013/diff.log_-p_master\nindex bf1326dc36..1841cded94 100644\n--- a/t/t4013/diff.log_-p_master\n+++ b/t/t4013/diff.log_-p_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.log_master b/t/t4013/diff.log_master\nindex a8f6ce5abd..f8ec445eb3 100644\n--- a/t/t4013/diff.log_master\n+++ b/t/t4013/diff.log_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a\n Author: A U Thor <author@example.com>\ndiff --git a/t/t4013/diff.show_--first-parent_master b/t/t4013/diff.show_--first-parent_master\nindex 3dcbe473a0..94548f4598 100644\n--- a/t/t4013/diff.show_--first-parent_master\n+++ b/t/t4013/diff.show_--first-parent_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --git a/dir/sub b/dir/sub\n index cead32e..992913c 100644\ndiff --git a/t/t4013/diff.show_-c_master b/t/t4013/diff.show_-c_master\nindex 81aba8da96..1c46ed64fd 100644\n--- a/t/t4013/diff.show_-c_master\n+++ b/t/t4013/diff.show_-c_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --combined dir/sub\n index cead32e,7289e35..992913c\ndiff --git a/t/t4013/diff.show_-m_master b/t/t4013/diff.show_-m_master\nindex 4ea2ee453d..7559fc22f8 100644\n--- a/t/t4013/diff.show_-m_master\n+++ b/t/t4013/diff.show_-m_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --git a/dir/sub b/dir/sub\n index cead32e..992913c 100644\n@@ -33,7 +33,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --git a/dir/sub b/dir/sub\n index 7289e35..992913c 100644\ndiff --git a/t/t4013/diff.show_master b/t/t4013/diff.show_master\nindex fb08ce0e46..57091c5d90 100644\n--- a/t/t4013/diff.show_master\n+++ b/t/t4013/diff.show_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n diff --cc dir/sub\n index cead32e,7289e35..992913c\ndiff --git a/t/t4013/diff.whatchanged_--root_--cc_--patch-with-stat_--summary_master b/t/t4013/diff.whatchanged_--root_--cc_--patch-with-stat_--summary_master\nindex 30aae7817b..5f13a71bb5 100644\n--- a/t/t4013/diff.whatchanged_--root_--cc_--patch-with-stat_--summary_master\n+++ b/t/t4013/diff.whatchanged_--root_--cc_--patch-with-stat_--summary_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n  dir/sub | 2 ++\n  file0   | 3 +++\ndiff --git a/t/t4013/diff.whatchanged_--root_-c_--patch-with-stat_--summary_master b/t/t4013/diff.whatchanged_--root_-c_--patch-with-stat_--summary_master\nindex d1d32bd34c..8acb88267b 100644\n--- a/t/t4013/diff.whatchanged_--root_-c_--patch-with-stat_--summary_master\n+++ b/t/t4013/diff.whatchanged_--root_-c_--patch-with-stat_--summary_master\n@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9\n Author: A U Thor <author@example.com>\n Date:   Mon Jun 26 00:04:00 2006 +0000\n \n-    Merge branch 'side'\n+    Merge branch 'side' into master\n \n  dir/sub | 2 ++\n  file0   | 3 +++\ndiff --git a/t/t4202-log.sh b/t/t4202-log.sh\nindex a0930599aa..fd9af658af 100755\n--- a/t/t4202-log.sh\n+++ b/t/t4202-log.sh\n@@ -483,7 +483,7 @@ test_expect_success 'set up merge history' '\n '\n \n cat > expect <<\\EOF\n-*   Merge branch 'side'\n+*   Merge branch 'side' into master\n |\\\n | * side-2\n | * side-1\n@@ -502,7 +502,7 @@ test_expect_success 'log --graph with merge' '\n '\n \n cat > expect <<\\EOF\n-| | | *   Merge branch 'side'\n+| | | *   Merge branch 'side' into master\n | | | |\\\n | | | | * side-2\n | | | | * side-1\n@@ -521,7 +521,7 @@ test_expect_success 'log --graph --line-prefix=\"| | | \" with merge' '\n '\n \n cat > expect.colors <<\\EOF\n-*   Merge branch 'side'\n+*   Merge branch 'side' into master\n <BLUE>|<RESET><CYAN>\\<RESET>\n <BLUE>|<RESET> * side-2\n <BLUE>|<RESET> * side-1\n@@ -555,7 +555,7 @@ cat > expect <<\\EOF\n |\\  Merge: A B\n | | Author: A U Thor <author@example.com>\n | |\n-| |     Merge branch 'side'\n+| |     Merge branch 'side' into master\n | |\n | * commit tags/side-2\n | | Author: A U Thor <author@example.com>\n@@ -632,11 +632,11 @@ test_expect_success 'set up more tangled history' '\n '\n \n cat > expect <<\\EOF\n-*   Merge tag 'reach'\n+*   Merge tag 'reach' into master\n |\\\n | \\\n |  \\\n-*-. \\   Merge tags 'octopus-a' and 'octopus-b'\n+*-. \\   Merge tags 'octopus-a' and 'octopus-b' into master\n |\\ \\ \\\n * | | | seventh\n | | * | octopus-b\n@@ -646,14 +646,14 @@ cat > expect <<\\EOF\n |/ /\n | * reach\n |/\n-*   Merge branch 'tangle'\n+*   Merge branch 'tangle' into master\n |\\\n | *   Merge branch 'side' (early part) into tangle\n | |\\\n | * \\   Merge branch 'master' (early part) into tangle\n | |\\ \\\n | * | | tangle-a\n-* | | |   Merge branch 'side'\n+* | | |   Merge branch 'side' into master\n |\\ \\ \\ \\\n | * | | | side-2\n | | |_|/\n@@ -735,16 +735,16 @@ test_expect_success 'log.decorate configuration' '\n \n test_expect_success 'decorate-refs with glob' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh\n \toctopus-b (octopus-b)\n \toctopus-a (octopus-a)\n \treach\n \tEOF\n \tcat >expect.no-decorate <<-\\EOF &&\n-\tMerge-tag-reach\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh\n \toctopus-b\n \toctopus-a\n@@ -765,8 +765,8 @@ test_expect_success 'decorate-refs with glob' '\n \n test_expect_success 'decorate-refs without globs' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh\n \toctopus-b\n \toctopus-a\n@@ -779,8 +779,8 @@ test_expect_success 'decorate-refs without globs' '\n \n test_expect_success 'multiple decorate-refs' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh\n \toctopus-b (octopus-b)\n \toctopus-a (octopus-a)\n@@ -794,8 +794,8 @@ test_expect_success 'multiple decorate-refs' '\n \n test_expect_success 'decorate-refs-exclude with glob' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach (HEAD -> master)\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master (HEAD -> master)\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh (tag: seventh)\n \toctopus-b (tag: octopus-b)\n \toctopus-a (tag: octopus-a)\n@@ -811,8 +811,8 @@ test_expect_success 'decorate-refs-exclude with glob' '\n \n test_expect_success 'decorate-refs-exclude without globs' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach (HEAD -> master)\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master (HEAD -> master)\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh (tag: seventh)\n \toctopus-b (tag: octopus-b, octopus-b)\n \toctopus-a (tag: octopus-a, octopus-a)\n@@ -828,8 +828,8 @@ test_expect_success 'decorate-refs-exclude without globs' '\n \n test_expect_success 'multiple decorate-refs-exclude' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach (HEAD -> master)\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master (HEAD -> master)\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh (tag: seventh)\n \toctopus-b (tag: octopus-b)\n \toctopus-a (tag: octopus-a)\n@@ -851,8 +851,8 @@ test_expect_success 'multiple decorate-refs-exclude' '\n \n test_expect_success 'decorate-refs and decorate-refs-exclude' '\n \tcat >expect.no-decorate <<-\\EOF &&\n-\tMerge-tag-reach (master)\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master (master)\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh\n \toctopus-b\n \toctopus-a\n@@ -866,8 +866,8 @@ test_expect_success 'decorate-refs and decorate-refs-exclude' '\n \n test_expect_success 'deocrate-refs and log.excludeDecoration' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach (master)\n-\tMerge-tags-octopus-a-and-octopus-b\n+\tMerge-tag-reach-into-master (master)\n+\tMerge-tags-octopus-a-and-octopus-b-into-master\n \tseventh\n \toctopus-b (octopus-b)\n \toctopus-a (octopus-a)\n@@ -881,10 +881,10 @@ test_expect_success 'deocrate-refs and log.excludeDecoration' '\n \n test_expect_success 'decorate-refs-exclude and simplify-by-decoration' '\n \tcat >expect.decorate <<-\\EOF &&\n-\tMerge-tag-reach (HEAD -> master)\n+\tMerge-tag-reach-into-master (HEAD -> master)\n \treach (tag: reach, reach)\n \tseventh (tag: seventh)\n-\tMerge-branch-tangle\n+\tMerge-branch-tangle-into-master\n \tMerge-branch-side-early-part-into-tangle (tangle)\n \ttangle-a (tag: tangle-a)\n \tEOF\n@@ -1068,7 +1068,7 @@ cat >expect <<\\EOF\n |\\  Merge: MERGE_PARENTS\n | | Author: A U Thor <author@example.com>\n | |\n-| |     Merge branch 'tangle'\n+| |     Merge branch 'tangle' into master\n | |\n | *   commit COMMIT_OBJECT_NAME\n | |\\  Merge: MERGE_PARENTS\n@@ -1102,7 +1102,7 @@ cat >expect <<\\EOF\n |\\ \\ \\ \\  Merge: MERGE_PARENTS\n | | | | | Author: A U Thor <author@example.com>\n | | | | |\n-| | | | |     Merge branch 'side'\n+| | | | |     Merge branch 'side' into master\n | | | | |\n | * | | | commit COMMIT_OBJECT_NAME\n | | |_|/  Author: A U Thor <author@example.com>\n@@ -1343,7 +1343,7 @@ cat >expect <<\\EOF\n *** |\\  Merge: MERGE_PARENTS\n *** | | Author: A U Thor <author@example.com>\n *** | |\n-*** | |     Merge branch 'tangle'\n+*** | |     Merge branch 'tangle' into master\n *** | |\n *** | *   commit COMMIT_OBJECT_NAME\n *** | |\\  Merge: MERGE_PARENTS\n@@ -1377,7 +1377,7 @@ cat >expect <<\\EOF\n *** |\\ \\ \\ \\  Merge: MERGE_PARENTS\n *** | | | | | Author: A U Thor <author@example.com>\n *** | | | | |\n-*** | | | | |     Merge branch 'side'\n+*** | | | | |     Merge branch 'side' into master\n *** | | | | |\n *** | * | | | commit COMMIT_OBJECT_NAME\n *** | | |_|/  Author: A U Thor <author@example.com>\n@@ -1540,8 +1540,8 @@ cat >expect <<-\\EOF\n * reach\n |\n | A\treach.t\n-* Merge branch 'tangle'\n-*   Merge branch 'side'\n+* Merge branch 'tangle' into master\n+*   Merge branch 'side' into master\n |\\\n | * side-2\n |\n@@ -1562,8 +1562,8 @@ cat >expect <<-\\EOF\n * reach\n |\n | reach.t\n-* Merge branch 'tangle'\n-*   Merge branch 'side'\n+* Merge branch 'tangle' into master\n+*   Merge branch 'side' into master\n |\\\n | * side-2\n |\ndiff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh\nindex e4c2a6eca4..2b3fd498d0 100755\n--- a/t/t6200-fmt-merge-msg.sh\n+++ b/t/t6200-fmt-merge-msg.sh\n@@ -79,7 +79,7 @@ test_expect_success GPG 'set up a signed tag' '\n '\n \n test_expect_success 'message for merging local branch' '\n-\techo \"Merge branch ${apos}left${apos}\" >expected &&\n+\techo \"Merge branch ${apos}left${apos} into master\" >expected &&\n \n \tgit checkout master &&\n \tgit fetch . left &&\n@@ -107,7 +107,7 @@ test_expect_success GPG 'message for merging local tag signed by unknown key' '\n '\n \n test_expect_success 'message for merging external branch' '\n-\techo \"Merge branch ${apos}left${apos} of $(pwd)\" >expected &&\n+\techo \"Merge branch ${apos}left${apos} of $(pwd) into master\" >expected &&\n \n \tgit checkout master &&\n \tgit fetch \"$(pwd)\" left &&\n@@ -118,7 +118,7 @@ test_expect_success 'message for merging external branch' '\n \n test_expect_success '[merge] summary/log configuration' '\n \tcat >expected <<-EOF &&\n-\tMerge branch ${apos}left${apos}\n+\tMerge branch ${apos}left${apos} into master\n \n \t# By Another Author (3) and A U Thor (2)\n \t# Via Another Committer\n@@ -160,7 +160,7 @@ test_expect_success 'setup FETCH_HEAD' '\n \n test_expect_success 'merge.log=3 limits shortlog length' '\n \tcat >expected <<-EOF &&\n-\tMerge branch ${apos}left${apos}\n+\tMerge branch ${apos}left${apos} into master\n \n \t# By Another Author (3) and A U Thor (2)\n \t# Via Another Committer\n@@ -177,7 +177,7 @@ test_expect_success 'merge.log=3 limits shortlog length' '\n \n test_expect_success 'merge.log=5 shows all 5 commits' '\n \tcat >expected <<-EOF &&\n-\tMerge branch ${apos}left${apos}\n+\tMerge branch ${apos}left${apos} into master\n \n \t# By Another Author (3) and A U Thor (2)\n \t# Via Another Committer\n@@ -195,7 +195,7 @@ test_expect_success 'merge.log=5 shows all 5 commits' '\n \n test_expect_success '--log=5 with custom comment character' '\n \tcat >expected <<-EOF &&\n-\tMerge branch ${apos}left${apos}\n+\tMerge branch ${apos}left${apos} into master\n \n \tx By Another Author (3) and A U Thor (2)\n \tx Via Another Committer\n@@ -212,14 +212,14 @@ test_expect_success '--log=5 with custom comment character' '\n '\n \n test_expect_success 'merge.log=0 disables shortlog' '\n-\techo \"Merge branch ${apos}left${apos}\" >expected &&\n+\techo \"Merge branch ${apos}left${apos} into master\" >expected &&\n \tgit -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&\n \ttest_cmp expected actual\n '\n \n test_expect_success '--log=3 limits shortlog length' '\n \tcat >expected <<-EOF &&\n-\tMerge branch ${apos}left${apos}\n+\tMerge branch ${apos}left${apos} into master\n \n \t# By Another Author (3) and A U Thor (2)\n \t# Via Another Committer\n@@ -236,7 +236,7 @@ test_expect_success '--log=3 limits shortlog length' '\n \n test_expect_success '--log=5 shows all 5 commits' '\n \tcat >expected <<-EOF &&\n-\tMerge branch ${apos}left${apos}\n+\tMerge branch ${apos}left${apos} into master\n \n \t# By Another Author (3) and A U Thor (2)\n \t# Via Another Committer\n@@ -253,13 +253,13 @@ test_expect_success '--log=5 shows all 5 commits' '\n '\n \n test_expect_success '--no-log disables shortlog' '\n-\techo \"Merge branch ${apos}left${apos}\" >expected &&\n+\techo \"Merge branch ${apos}left${apos} into master\" >expected &&\n \tgit fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&\n \ttest_cmp expected actual\n '\n \n test_expect_success '--log=0 disables shortlog' '\n-\techo \"Merge branch ${apos}left${apos}\" >expected &&\n+\techo \"Merge branch ${apos}left${apos} into master\" >expected &&\n \tgit fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&\n \ttest_cmp expected actual\n '\n@@ -300,7 +300,7 @@ test_expect_success 'fmt-merge-msg -m' '\n \n test_expect_success 'setup: expected shortlog for two branches' '\n \tcat >expected <<-EOF\n-\tMerge branches ${apos}left${apos} and ${apos}right${apos}\n+\tMerge branches ${apos}left${apos} and ${apos}right${apos} into master\n \n \t# By Another Author (3) and A U Thor (2)\n \t# Via Another Committer\n@@ -397,7 +397,7 @@ test_expect_success 'merge-msg with nothing to merge' '\n \n test_expect_success 'merge-msg tag' '\n \tcat >expected <<-EOF &&\n-\tMerge tag ${apos}tag-r3${apos}\n+\tMerge tag ${apos}tag-r3${apos} into master\n \n \t* tag ${apos}tag-r3${apos}:\n \t  Right #3\n@@ -418,7 +418,7 @@ test_expect_success 'merge-msg tag' '\n \n test_expect_success 'merge-msg two tags' '\n \tcat >expected <<-EOF &&\n-\tMerge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}\n+\tMerge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos} into master\n \n \t* tag ${apos}tag-r3${apos}:\n \t  Right #3\n@@ -448,7 +448,7 @@ test_expect_success 'merge-msg two tags' '\n \n test_expect_success 'merge-msg tag and branch' '\n \tcat >expected <<-EOF &&\n-\tMerge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}\n+\tMerge branch ${apos}left${apos}, tag ${apos}tag-r3${apos} into master\n \n \t* tag ${apos}tag-r3${apos}:\n \t  Right #3\n@@ -479,7 +479,7 @@ test_expect_success 'merge-msg tag and branch' '\n test_expect_success 'merge-msg lots of commits' '\n \t{\n \t\tcat <<-EOF &&\n-\t\tMerge branch ${apos}long${apos}\n+\t\tMerge branch ${apos}long${apos} into master\n \n \t\t* long: (35 commits)\n \t\tEOF\n@@ -516,7 +516,7 @@ test_expect_success 'merge-msg with \"merging\" an annotated tag' '\n \tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n \t{\n \t\tcat <<-\\EOF\n-\t\tMerge tag '\\''annote'\\''\n+\t\tMerge tag '\\''annote'\\'' into master\n \n \t\tAn annotated one\n \n@@ -531,7 +531,7 @@ test_expect_success 'merge-msg with \"merging\" an annotated tag' '\n \tgit merge --no-commit --no-ff $annote &&\n \t{\n \t\tcat <<-EOF\n-\t\tMerge tag '\\''$annote'\\''\n+\t\tMerge tag '\\''$annote'\\'' into master\n \n \t\tAn annotated one\n \ndiff --git a/t/t7600-merge.sh b/t/t7600-merge.sh\nindex 5883a6adc3..1d45f9a4ed 100755\n--- a/t/t7600-merge.sh\n+++ b/t/t7600-merge.sh\n@@ -14,9 +14,9 @@ Testing basic merge operations/option parsing.\n     ! [c4] c4\n      ! [c5] c5\n       ! [c6] c6\n-       * [master] Merge commit 'c1'\n+       * [master] Merge commit 'c1' into master\n --------\n-       - [master] Merge commit 'c1'\n+       - [master] Merge commit 'c1' into master\n  +     * [c1] commit 1\n       +  [c6] c6\n      +   [c5] c5\n@@ -44,8 +44,8 @@ test_write_lines '1 X' 2 '3 X' 4 '5 X' 6 7 8 '9 X' >result.1-3-5-9\n test_write_lines 1 2 3 4 5 6 7 8 '9 Z' >result.9z\n \n create_merge_msgs () {\n-\techo \"Merge tag 'c2'\" >msg.1-5 &&\n-\techo \"Merge tags 'c2' and 'c3'\" >msg.1-5-9 &&\n+\techo \"Merge tag 'c2' into master\" >msg.1-5 &&\n+\techo \"Merge tags 'c2' and 'c3' into master\" >msg.1-5-9 &&\n \t{\n \t\techo \"Squashed commit of the following:\" &&\n \t\techo &&\n@@ -258,7 +258,7 @@ test_expect_success 'merge c3 with c7 with commit.cleanup = scissors' '\n \tgit commit --no-edit -a &&\n \n \tcat >expect <<-\\EOF &&\n-\tMerge tag '\"'\"'c7'\"'\"'\n+\tMerge tag '\"'\"'c7'\"'\"' into master\n \n \t# ------------------------ >8 ------------------------\n \t# Do not modify or remove the line above.\n@@ -808,10 +808,10 @@ test_expect_success 'merge with conflicted --autostash changes' '\n '\n \n cat >expected.branch <<\\EOF\n-Merge branch 'c5-branch' (early part)\n+Merge branch 'c5-branch' (early part) into master\n EOF\n cat >expected.tag <<\\EOF\n-Merge commit 'c5~1'\n+Merge commit 'c5~1' into master\n EOF\n \n test_expect_success 'merge early part of c2' '\ndiff --git a/t/t7608-merge-messages.sh b/t/t7608-merge-messages.sh\nindex 8e7e0a5865..2af33f195b 100755\n--- a/t/t7608-merge-messages.sh\n+++ b/t/t7608-merge-messages.sh\n@@ -16,7 +16,7 @@ test_expect_success 'merge local branch' '\n \tgit checkout master &&\n \ttest_commit master-2 &&\n \tgit merge local-branch &&\n-\tcheck_oneline \"Merge branch Qlocal-branchQ\"\n+\tcheck_oneline \"Merge branch Qlocal-branchQ into master\"\n '\n \n test_expect_success 'merge octopus branches' '\n@@ -26,7 +26,7 @@ test_expect_success 'merge octopus branches' '\n \ttest_commit octopus-2 &&\n \tgit checkout master &&\n \tgit merge octopus-a octopus-b &&\n-\tcheck_oneline \"Merge branches Qoctopus-aQ and Qoctopus-bQ\"\n+\tcheck_oneline \"Merge branches Qoctopus-aQ and Qoctopus-bQ into master\"\n '\n \n test_expect_success 'merge tag' '\n@@ -35,7 +35,7 @@ test_expect_success 'merge tag' '\n \tgit checkout master &&\n \ttest_commit master-3 &&\n \tgit merge tag-1 &&\n-\tcheck_oneline \"Merge tag Qtag-1Q\"\n+\tcheck_oneline \"Merge tag Qtag-1Q into master\"\n '\n \n test_expect_success 'ambiguous tag' '\n@@ -44,7 +44,7 @@ test_expect_success 'ambiguous tag' '\n \tgit checkout master &&\n \ttest_commit master-4 &&\n \tgit merge ambiguous &&\n-\tcheck_oneline \"Merge tag QambiguousQ\"\n+\tcheck_oneline \"Merge tag QambiguousQ into master\"\n '\n \n test_expect_success 'remote-tracking branch' '\n@@ -54,7 +54,7 @@ test_expect_success 'remote-tracking branch' '\n \tgit checkout master &&\n \ttest_commit master-5 &&\n \tgit merge origin/master &&\n-\tcheck_oneline \"Merge remote-tracking branch Qorigin/masterQ\"\n+\tcheck_oneline \"Merge remote-tracking branch Qorigin/masterQ into master\"\n '\n \n test_done\n-- \ngitgitgadget\n\n"},{"id":"400514","messageId":"7747eaa57de9324b7f7a46f86d1179ce751f76c9.1593009996.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v4.git.1593009996.gitgitgadget@gmail.com","subject":"[PATCH v4 6/9] init: allow setting the default for the initial branch name via the config","fromName":"Don Goodman-Wilson via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-24T14:46:33Z","receivedAt":"2020-06-24T14:47:01Z","isPatch":true,"sender":{"key":"don@goodman-wilson.com","avatar":"https://gravatar.com/avatar/9819ec326d55ea4c398b8ff018dcf63b4e9603b00db9cc019c725bffc9c05d17?d=mp&s=160"},"body":"From: Don Goodman-Wilson <don@goodman-wilson.com>\n\nWe just introduced the command-line option\n`--initial-branch=<branch-name>` to allow initializing a new repository\nwith a different initial branch than the hard-coded one.\n\nTo allow users to override the initial branch name more permanently\n(i.e. without having to specify the name manually for each and every\n`git init` invocation), let's introduce the `init.defaultBranch` config\nsetting.\n\nHelped-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nHelped-by: Derrick Stolee <dstolee@microsoft.com>\nSigned-off-by: Don Goodman-Wilson <don@goodman-wilson.com>\n---\n Documentation/config/init.txt |  4 ++++\n builtin/init-db.c             |  2 +-\n refs.c                        | 30 ++++++++++++++++++++++++++++++\n refs.h                        |  9 +++++++++\n t/t0001-init.sh               | 13 +++++++++++++\n 5 files changed, 57 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/config/init.txt b/Documentation/config/init.txt\nindex 46fa8c6a08..6ae4a38416 100644\n--- a/Documentation/config/init.txt\n+++ b/Documentation/config/init.txt\n@@ -1,3 +1,7 @@\n init.templateDir::\n \tSpecify the directory from which templates will be copied.\n \t(See the \"TEMPLATE DIRECTORY\" section of linkgit:git-init[1].)\n+\n+init.defaultBranch::\n+\tAllows overriding the default branch name when initializing\n+\ta new repository.\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 8fdfc334ac..cee64823cb 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -269,7 +269,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 = \"master\";\n+\t\t\tinitial_branch = git_default_branch_name();\n \n \t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n \t\tif (check_refname_format(ref, 0) < 0)\ndiff --git a/refs.c b/refs.c\nindex 224ff66c7b..b98dea5217 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -560,6 +560,36 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n \t\targv_array_pushf(prefixes, *p, len, prefix);\n }\n \n+char *repo_default_branch_name(struct repository *r)\n+{\n+\tconst char *config_key = \"init.defaultbranch\";\n+\tconst char *config_display_key = \"init.defaultBranch\";\n+\tchar *ret = NULL, *full_ref;\n+\n+\tif (repo_config_get_string(r, config_key, &ret) < 0)\n+\t\tdie(_(\"could not retrieve `%s`\"), config_display_key);\n+\n+\tif (!ret)\n+\t\tret = xstrdup(\"master\");\n+\n+\tfull_ref = xstrfmt(\"refs/heads/%s\", ret);\n+\tif (check_refname_format(full_ref, 0))\n+\t\tdie(_(\"invalid branch name: %s = %s\"), config_display_key, ret);\n+\tfree(full_ref);\n+\n+\treturn ret;\n+}\n+\n+const char *git_default_branch_name(void)\n+{\n+\tstatic char *ret;\n+\n+\tif (!ret)\n+\t\tret = repo_default_branch_name(the_repository);\n+\n+\treturn ret;\n+}\n+\n /*\n  * *string and *len will only be substituted, and *string returned (for\n  * later free()ing) if the string passed in is a magic short-hand form\ndiff --git a/refs.h b/refs.h\nindex e010f8aec2..f212f8945e 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -154,6 +154,15 @@ int repo_dwim_log(struct repository *r, const char *str, int len, struct object_\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \n+/*\n+ * Retrieves the default branch name for newly-initialized repositories.\n+ *\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+\n /*\n  * A ref_transaction represents a collection of reference updates that\n  * should succeed or fail together.\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 386c06b5dd..6d2467995e 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -477,4 +477,17 @@ test_expect_success '--initial-branch' '\n \tgrep hello actual\n '\n \n+test_expect_success 'overridden default initial branch name (config)' '\n+\ttest_config_global init.defaultBranch nmb &&\n+\tgit init initial-branch-config &&\n+\tgit -C initial-branch-config symbolic-ref HEAD >actual &&\n+\tgrep nmb actual\n+'\n+\n+test_expect_success 'invalid default branch name' '\n+\ttest_config_global init.defaultBranch \"with space\" &&\n+\ttest_must_fail git init initial-branch-invalid 2>err &&\n+\ttest_i18ngrep \"invalid branch name\" err\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"400515","messageId":"9edd4fd3b26cef4ff8ffb99be6647055ebb76ed6.1593009996.git.gitgitgadget@gmail.com","threadId":"53651","inReplyTo":"pull.656.v4.git.1593009996.gitgitgadget@gmail.com","subject":"[PATCH v4 5/9] init: allow specifying the initial branch name for the new repository","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-06-24T14:46:32Z","receivedAt":"2020-06-24T14:47: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\nThere is a growing number of projects and companies desiring to change\nthe main branch name of their repositories (see e.g.\nhttps://twitter.com/mislav/status/1270388510684598272 for background on\nthis).\n\nTo change that branch name for new repositories, currently the only way\nto do that automatically is by copying all of Git's template directory,\nthen hard-coding the desired default branch name into the `.git/HEAD`\nfile, and then configuring `init.templateDir` to point to those copied\ntemplate files.\n\nTo make this process much less cumbersome, let's introduce a new option:\n`--initial-branch=<branch-name>`.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n Documentation/git-init.txt |  7 +++++++\n builtin/clone.c            |  3 ++-\n builtin/init-db.c          | 33 +++++++++++++++++++++++++++------\n cache.h                    |  2 +-\n t/t0001-init.sh            | 13 +++++++++++++\n 5 files changed, 50 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\nindex f9467cc6a4..ddfe265da5 100644\n--- a/Documentation/git-init.txt\n+++ b/Documentation/git-init.txt\n@@ -11,6 +11,7 @@ SYNOPSIS\n [verse]\n 'git init' [-q | --quiet] [--bare] [--template=<template_directory>]\n \t  [--separate-git-dir <git dir>] [--object-format=<format>]\n+\t  [-b <branch-name> | --initial-branch=<branch-name>]\n \t  [--shared[=<permissions>]] [directory]\n \n \n@@ -67,6 +68,12 @@ repository.\n +\n If this is reinitialization, the repository will be moved to the specified path.\n \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+\n --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::\n \n Specify that the Git repository is to be shared amongst several users.  This\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 2a8e3aaaed..b751bdf13e 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -1111,7 +1111,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \n-\tinit_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, INIT_DB_QUIET);\n+\tinit_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,\n+\t\tINIT_DB_QUIET);\n \n \tif (real_git_dir)\n \t\tgit_dir = real_git_dir;\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 0b7222e718..8fdfc334ac 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -203,6 +203,7 @@ void initialize_repository_version(int hash_algo)\n \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 {\n \tstruct stat st1;\n@@ -258,15 +259,26 @@ static int create_default_files(const char *template_path,\n \t\tdie(\"failed to set up refs db: %s\", err.buf);\n \n \t/*\n-\t * Create the default symlink from \".git/HEAD\" to the \"master\"\n-\t * branch, if it does not exist yet.\n+\t * Point the HEAD symref to the initial branch with if HEAD does\n+\t * not yet exist.\n \t */\n \tpath = git_path_buf(&buf, \"HEAD\");\n \treinit = (!access(path, R_OK)\n \t\t  || readlink(path, junk, sizeof(junk)-1) != -1);\n \tif (!reinit) {\n-\t\tif (create_symref(\"HEAD\", \"refs/heads/master\", NULL) < 0)\n+\t\tchar *ref;\n+\n+\t\tif (!initial_branch)\n+\t\t\tinitial_branch = \"master\";\n+\n+\t\tref = xstrfmt(\"refs/heads/%s\", initial_branch);\n+\t\tif (check_refname_format(ref, 0) < 0)\n+\t\t\tdie(_(\"invalid initial branch name: '%s'\"),\n+\t\t\t    initial_branch);\n+\n+\t\tif (create_symref(\"HEAD\", ref, NULL) < 0)\n \t\t\texit(1);\n+\t\tfree(ref);\n \t}\n \n \tinitialize_repository_version(fmt->hash_algo);\n@@ -383,7 +395,8 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash\n }\n \n int init_db(const char *git_dir, const char *real_git_dir,\n-\t    const char *template_dir, int hash, unsigned int flags)\n+\t    const char *template_dir, int hash, const char *initial_branch,\n+\t    unsigned int flags)\n {\n \tint reinit;\n \tint exist_ok = flags & INIT_DB_EXIST_OK;\n@@ -425,7 +438,11 @@ int init_db(const char *git_dir, const char *real_git_dir,\n \n \tvalidate_hash_algorithm(&repo_fmt, hash);\n \n-\treinit = create_default_files(template_dir, original_git_dir, &repo_fmt);\n+\treinit = create_default_files(template_dir, original_git_dir,\n+\t\t\t\t      initial_branch, &repo_fmt);\n+\tif (reinit && initial_branch)\n+\t\twarning(_(\"re-init: ignored --initial-branch=%s\"),\n+\t\t\tinitial_branch);\n \n \tcreate_object_directory();\n \n@@ -528,6 +545,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \tconst char *template_dir = NULL;\n \tunsigned int flags = 0;\n \tconst char *object_format = NULL;\n+\tconst char *initial_branch = NULL;\n \tint hash_algo = GIT_HASH_UNKNOWN;\n \tconst struct option init_db_options[] = {\n \t\tOPT_STRING(0, \"template\", &template_dir, N_(\"template-directory\"),\n@@ -541,6 +559,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \t\tOPT_BIT('q', \"quiet\", &flags, N_(\"be quiet\"), INIT_DB_QUIET),\n \t\tOPT_STRING(0, \"separate-git-dir\", &real_git_dir, N_(\"gitdir\"),\n \t\t\t   N_(\"separate git dir from working tree\")),\n+\t\tOPT_STRING('b', \"initial-branch\", &initial_branch, N_(\"name\"),\n+\t\t\t   N_(\"override the name of the initial branch\")),\n \t\tOPT_STRING(0, \"object-format\", &object_format, N_(\"hash\"),\n \t\t\t   N_(\"specify the hash algorithm to use\")),\n \t\tOPT_END()\n@@ -652,5 +672,6 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \tUNLEAK(work_tree);\n \n \tflags |= INIT_DB_EXIST_OK;\n-\treturn init_db(git_dir, real_git_dir, template_dir, hash_algo, flags);\n+\treturn init_db(git_dir, real_git_dir, template_dir, hash_algo,\n+\t\t       initial_branch, flags);\n }\ndiff --git a/cache.h b/cache.h\nindex 0f0485ecfe..654426460c 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -628,7 +628,7 @@ int path_inside_repo(const char *prefix, const char *path);\n \n int init_db(const char *git_dir, const char *real_git_dir,\n \t    const char *template_dir, int hash_algo,\n-\t    unsigned int flags);\n+\t    const char *initial_branch, unsigned int flags);\n void initialize_repository_version(int hash_algo);\n \n void sanitize_stdfds(void);\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 1edd5aeb8f..386c06b5dd 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -464,4 +464,17 @@ test_expect_success MINGW 'redirect std handles' '\n \tgrep \"Needed a single revision\" output.txt\n '\n \n+test_expect_success '--initial-branch' '\n+\tgit init --initial-branch=hello initial-branch-option &&\n+\tgit -C initial-branch-option symbolic-ref HEAD >actual &&\n+\techo refs/heads/hello >expect &&\n+\ttest_cmp expect actual &&\n+\n+\t: re-initializing should not change the branch name &&\n+\tgit init --initial-branch=ignore initial-branch-option 2>err &&\n+\ttest_i18ngrep \"ignored --initial-branch\" err &&\n+\tgit -C initial-branch-option symbolic-ref HEAD >actual &&\n+\tgrep hello actual\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"400529","messageId":"xmqqlfkc8o57.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006241443200.54@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v3 2/8] send-pack/transport-helper: avoid mentioning a particular branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-24T15:44:04Z","receivedAt":"2020-06-24T15:44:12Z","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> Hi Junio,\n>\n> On Tue, 23 Jun 2020, Junio C Hamano wrote:\n>\n>> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n>> writes:\n>>\n>> > @@ -1046,7 +1046,7 @@ static int push_refs(struct transport *transport,\n>> >  \tif (!remote_refs) {\n>> >  \t\tfprintf(stderr,\n>> >  \t\t\t_(\"No refs in common and none specified; doing nothing.\\n\"\n>> > -\t\t\t  \"Perhaps you should specify a branch such as 'master'.\\n\"));\n>> > +\t\t\t  \"Perhaps you should specify a specific branch.\\n\"));\n>>\n>> Hmph, not just \"specify a branch.\"?  Maybe it is just me, but\n>> \"specify a specific branch\" did not roll well on my tongue.\n>\n> Oh well. \"Perhaps you should specify a branch\" sounded too judgmental to\n> me, but I'm not a native speaker, so I simply removed the word \"specific\".\n\nI'm not either.  Note that when I say \"maybe it is just me\", I\nusually am not asking to change anything.\n"},{"id":"400542","messageId":"xmqqzh8s7838.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"fffdb9944fc2672ccb7eac776cdd18855a1f99dc.1592951611.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 1/8] fmt-merge-msg: stop treating `master` specially","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-24T16:16:11Z","receivedAt":"2020-06-24T16:16:18Z","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> In the context of many projects renaming their primary branch names away\n> from `master`, Git wants to stop treating the `master` branch specially.\n>\n> Let's start with `git fmt-merge-msg`.\n>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>  fmt-merge-msg.c                               |  5 +-\n>  t/t1507-rev-parse-upstream.sh                 |  2 +-\n>  t/t4013-diff-various.sh                       |  4 +-\n>  t/t4013/diff.log_--decorate=full_--all        |  2 +-\n>  t/t4013/diff.log_--decorate_--all             |  2 +-\n>  ...--patch-with-stat_--summary_master_--_dir_ |  2 +-\n>  t/t4013/diff.log_--patch-with-stat_master     |  2 +-\n>  .../diff.log_--patch-with-stat_master_--_dir_ |  2 +-\n>  ...ot_--cc_--patch-with-stat_--summary_master |  2 +-\n>  ..._--root_--patch-with-stat_--summary_master |  2 +-\n>  .../diff.log_--root_--patch-with-stat_master  |  2 +-\n>  ...root_-c_--patch-with-stat_--summary_master |  2 +-\n>  t/t4013/diff.log_--root_-p_master             |  2 +-\n>  t/t4013/diff.log_--root_master                |  2 +-\n>  t/t4013/diff.log_-m_-p_--first-parent_master  |  2 +-\n>  t/t4013/diff.log_-m_-p_master                 |  4 +-\n>  t/t4013/diff.log_-p_--first-parent_master     |  2 +-\n>  t/t4013/diff.log_-p_master                    |  2 +-\n>  t/t4013/diff.log_master                       |  2 +-\n>  t/t4013/diff.show_--first-parent_master       |  2 +-\n>  t/t4013/diff.show_-c_master                   |  2 +-\n>  t/t4013/diff.show_-m_master                   |  4 +-\n>  t/t4013/diff.show_master                      |  2 +-\n>  ...ot_--cc_--patch-with-stat_--summary_master |  2 +-\n>  ...root_-c_--patch-with-stat_--summary_master |  2 +-\n>  t/t4202-log.sh                                | 72 +++++++++----------\n>  t/t6200-fmt-merge-msg.sh                      | 36 +++++-----\n>  t/t7600-merge.sh                              | 14 ++--\n>  t/t7608-merge-messages.sh                     | 10 +--\n>  29 files changed, 94 insertions(+), 97 deletions(-)\n\nThis must have been tedious as the tests with merge commits are all\nover the place (I know updating t4013 would not have been too much\nof the work as it has its own self-update knob, but it still is a\nlot of work to verify that the changes make sense).\n\nThanks.\n\n\n"},{"id":"400543","messageId":"xmqqv9jg780w.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"54563642dbf96fcb36993c2c2d36ebefaf220cce.1593009996.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v4 3/9] submodule: fall back to remote's HEAD for missing remote.<name>.branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-24T16:17:35Z","receivedAt":"2020-06-24T16:17:40Z","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> Even so, it should be okay to fix this behavior without anything like a\n> longer transition period:\n>\n> - The `git submodule update --remote` command is not really common.\n>\n> - Current Git's behavior when running this command is outright\n>   confusing, unless the remote repository's current branch _is_ `master`\n>   (in which case the proposed behavior matches the old behavior).\n>\n> - If a user encounters a regression due to the changed behavior, the fix\n>   is actually trivial: setting `submodule.<name>.branch` to `master`\n>   will reinstate the old behavior.\n>\n> Helped-by: Philippe Blain <levraiphilippeblain@gmail.com>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n\nWell explained.  Thanks.\n"},{"id":"400544","messageId":"xmqqo8p877o1.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006241455210.54@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v3 5/8] init: allow setting the default for the initial branch name via the config","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-24T16:25:18Z","receivedAt":"2020-06-24T16:25:27Z","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>> \treinit = create_default_files(...\n>> \t\t\tinitial_branch ? initial_branch : \"master\",\n>> \t\t\t...);\n>> \tif (reinit || initial_branch)\n>> \t\twarning(_(...));\n>>\n>> in the previous step and then we can teach the caller to use the\n>> configured value instead of the hardcoded \"master\".\n>\n> While that is really tempting, there is another called of `init_db()`\n> (which calls `create_default_files()`): `builtin/clone.c`. And I do not\n> wish to duplicate the logic there.\n>\n> So I left this as-is.\n\nI am still on the fence after seeing v4, but let's leave it as is.\nThe reason why I wanted to leave the \"default to\" logic out of the\nhelper was to make sure it implements little or no policy, which\nwould leave the door open to let other callers of the helper to use\ntheir own and different default, but we can revisit when we acquire\nthe third caller.  I do not see an immediate need to make the\nclone's fallback default configurable separately from what init uses\nfor the default initial branch name, and with modern servers it is\ndoubtful that the fallback default by clone is ever used anyway.\n\nThanks.\n\n"},{"id":"400545","messageId":"xmqqk0zw77li.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"pull.656.v4.git.1593009996.gitgitgadget@gmail.com","subject":"Re: [PATCH v4 0/9] Allow overriding the default name of the default branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-24T16:26:49Z","receivedAt":"2020-06-24T16:26:54Z","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> Changes since v3:\n>\n>  * We now avoid the phrasing \"specify a specific\" in the messages.\n>    \n>    \n>  * The git submodule patch has a better commit title now, and it also\n>    adjusts the documentation more completely now (thanks, Philippe!).\n>    \n>    \n>  * A code comment in builtin/init-db.c was updated to no longer talk about a \n>    symlink when it comes to HEAD.\n>    \n>    \n>  * Made it the responsibility of the caller to warn about reinit &&\n>    initial_branch.\n\nIt looked all good to me.  Will replace.\n\nThanks.  Hopefully we can go 'next' with this round---knock wood...\n"},{"id":"400602","messageId":"nycvar.QRO.7.76.6.2006251503350.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqk0zw77li.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v4 0/9] Allow overriding the default name of the default branch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-25T13:03:52Z","receivedAt":"2020-06-25T13:04:18Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Wed, 24 Jun 2020, Junio C Hamano wrote:\n\n> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> > Changes since v3:\n> >\n> >  * We now avoid the phrasing \"specify a specific\" in the messages.\n> >\n> >\n> >  * The git submodule patch has a better commit title now, and it also\n> >    adjusts the documentation more completely now (thanks, Philippe!).\n> >\n> >\n> >  * A code comment in builtin/init-db.c was updated to no longer talk about a\n> >    symlink when it comes to HEAD.\n> >\n> >\n> >  * Made it the responsibility of the caller to warn about reinit &&\n> >    initial_branch.\n>\n> It looked all good to me.  Will replace.\n>\n> Thanks.  Hopefully we can go 'next' with this round---knock wood...\n\nI concur!\n\nCiao,\nDscho\n"},{"id":"400603","messageId":"nycvar.QRO.7.76.6.2006251504120.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqlfkc8o57.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v3 2/8] send-pack/transport-helper: avoid mentioning a particular branch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-25T13:05:53Z","receivedAt":"2020-06-25T13:06:09Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Wed, 24 Jun 2020, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n>\n> > On Tue, 23 Jun 2020, Junio C Hamano wrote:\n> >\n> >> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> >> writes:\n> >>\n> >> > @@ -1046,7 +1046,7 @@ static int push_refs(struct transport *transport,\n> >> >  \tif (!remote_refs) {\n> >> >  \t\tfprintf(stderr,\n> >> >  \t\t\t_(\"No refs in common and none specified; doing nothing.\\n\"\n> >> > -\t\t\t  \"Perhaps you should specify a branch such as 'master'.\\n\"));\n> >> > +\t\t\t  \"Perhaps you should specify a specific branch.\\n\"));\n> >>\n> >> Hmph, not just \"specify a branch.\"?  Maybe it is just me, but\n> >> \"specify a specific branch\" did not roll well on my tongue.\n> >\n> > Oh well. \"Perhaps you should specify a branch\" sounded too judgmental to\n> > me, but I'm not a native speaker, so I simply removed the word \"specific\".\n>\n> I'm not either.\n\nWe should start a society or something ;-)\n\n> Note that when I say \"maybe it is just me\", I usually am not asking to\n> change anything.\n\nOf course! In this instance, your suggestion made me think and prefer the\nnon-repetitive version (because let's face it, taking out that word did\nnot make it any more or less judgemental).\n\nCiao,\nDscho\n"},{"id":"400604","messageId":"nycvar.QRO.7.76.6.2006251506020.54@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"xmqqzh8s7838.fsf@gitster.c.googlers.com","subject":"Re: [PATCH v3 1/8] fmt-merge-msg: stop treating `master` specially","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-25T13:07:03Z","receivedAt":"2020-06-25T13:07:18Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Wed, 24 Jun 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> > In the context of many projects renaming their primary branch names away\n> > from `master`, Git wants to stop treating the `master` branch specially.\n> >\n> > Let's start with `git fmt-merge-msg`.\n> >\n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> > ---\n> >  fmt-merge-msg.c                               |  5 +-\n> >  t/t1507-rev-parse-upstream.sh                 |  2 +-\n> >  t/t4013-diff-various.sh                       |  4 +-\n> >  t/t4013/diff.log_--decorate=full_--all        |  2 +-\n> >  t/t4013/diff.log_--decorate_--all             |  2 +-\n> >  ...--patch-with-stat_--summary_master_--_dir_ |  2 +-\n> >  t/t4013/diff.log_--patch-with-stat_master     |  2 +-\n> >  .../diff.log_--patch-with-stat_master_--_dir_ |  2 +-\n> >  ...ot_--cc_--patch-with-stat_--summary_master |  2 +-\n> >  ..._--root_--patch-with-stat_--summary_master |  2 +-\n> >  .../diff.log_--root_--patch-with-stat_master  |  2 +-\n> >  ...root_-c_--patch-with-stat_--summary_master |  2 +-\n> >  t/t4013/diff.log_--root_-p_master             |  2 +-\n> >  t/t4013/diff.log_--root_master                |  2 +-\n> >  t/t4013/diff.log_-m_-p_--first-parent_master  |  2 +-\n> >  t/t4013/diff.log_-m_-p_master                 |  4 +-\n> >  t/t4013/diff.log_-p_--first-parent_master     |  2 +-\n> >  t/t4013/diff.log_-p_master                    |  2 +-\n> >  t/t4013/diff.log_master                       |  2 +-\n> >  t/t4013/diff.show_--first-parent_master       |  2 +-\n> >  t/t4013/diff.show_-c_master                   |  2 +-\n> >  t/t4013/diff.show_-m_master                   |  4 +-\n> >  t/t4013/diff.show_master                      |  2 +-\n> >  ...ot_--cc_--patch-with-stat_--summary_master |  2 +-\n> >  ...root_-c_--patch-with-stat_--summary_master |  2 +-\n> >  t/t4202-log.sh                                | 72 +++++++++----------\n> >  t/t6200-fmt-merge-msg.sh                      | 36 +++++-----\n> >  t/t7600-merge.sh                              | 14 ++--\n> >  t/t7608-merge-messages.sh                     | 10 +--\n> >  29 files changed, 94 insertions(+), 97 deletions(-)\n>\n> This must have been tedious as the tests with merge commits are all\n> over the place (I know updating t4013 would not have been too much\n> of the work as it has its own self-update knob, but it still is a\n> lot of work to verify that the changes make sense).\n\nI missed the self-update knob, but in any case, I would not have used it,\nanyway, to make sure that I do look closely at all the sites.\n\nCiao,\nDscho\n"},{"id":"400742","messageId":"20200629162003.GD20303@danh.dev","threadId":"53651","inReplyTo":"fffdb9944fc2672ccb7eac776cdd18855a1f99dc.1593009996.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v4 1/9] fmt-merge-msg: stop treating `master` specially","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2020-06-29T16:20:03Z","receivedAt":"2020-06-29T18:49:14Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"On 2020-06-24 14:46:28+0000, Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com> wrote:\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> \n> In the context of many projects renaming their primary branch names away\n> from `master`, Git wants to stop treating the `master` branch specially.\n> \n> Let's start with `git fmt-merge-msg`.\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n\nHi Dscho,\n\nThis change will also affect git-subtree test.\nWe'll need this patch for subtree:\n----------------8<-------------------\nFrom: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=\n <congdanhqx@gmail.com>\nDate: Mon, 29 Jun 2020 22:56:37 +0700\nSubject: [PATCH] contrib: subtree: adjust test to change in fmt-merge-msg\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n\nWe're starting to stop treating `master' specially in fmt-merge-msg.\nAdjust the test to reflect that change.\n\nSigned-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n---\n contrib/subtree/t/t7900-subtree.sh | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh\nindex 57ff4b25c1..53d7accf94 100755\n--- a/contrib/subtree/t/t7900-subtree.sh\n+++ b/contrib/subtree/t/t7900-subtree.sh\n@@ -196,7 +196,8 @@ test_expect_success 'merge new subproj history into sub dir/ with --prefix' '\n \t\tcd \"$subtree_test_count\" &&\n \t\tgit fetch ./\"sub proj\" master &&\n \t\tgit subtree merge --prefix=\"sub dir\" FETCH_HEAD &&\n-\t\tcheck_equal \"$(last_commit_message)\" \"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\''\"\n+\t\tcheck_equal \"$(last_commit_message)\" \\\n+\t\t\t\"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\'' into master\"\n \t)\n '\n \n@@ -273,7 +274,8 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende\n \t\tcd \"$test_count\" &&\n \t\tgit fetch ./subproj master &&\n \t\tgit subtree merge --prefix=subdir/ FETCH_HEAD &&\n-\t\tcheck_equal \"$(last_commit_message)\" \"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\''\"\n+\t\tcheck_equal \"$(last_commit_message)\" \\\n+\t\t\t\"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\'' into master\"\n \t)\n '\n \n-- \n2.27.0.111.gc72c7da667\nDanh\n"},{"id":"400783","messageId":"20200629224113.GC9782@camp.crustytoothpaste.net","threadId":"53651","inReplyTo":"pull.656.v4.git.1593009996.gitgitgadget@gmail.com","subject":"Re: [PATCH v4 0/9] Allow overriding the default name of the default branch","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2020-06-29T22:41:13Z","receivedAt":"2020-06-29T22:42:08Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2020-06-24 at 14:46:27, Johannes Schindelin via GitGitGadget wrote:\n> A growing number of open source projects aims to avoid the branch name \n> master due to its negative connotation. See [1] for an existing discussion\n> on this. The links [2], [3], and [4] describe community-driven ways for\n> users to rename their default branches or use template edits to set a new\n> default branch name.\n> \n> [1] \n> https://lore.kernel.org/git/CAOAHyQwyXC1Z3v7BZAC+Bq6JBaM7FvBenA-1fcqeDV==apdWDg@mail.gmail.com/\n> \n> [2] https://twitter.com/mislav/status/1270388510684598272\n> \n> [3] \n> https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx\n> \n> [4] https://github.com/ethomson/retarget_prs\n> \n> By necessity, existing repositories require a lot of manual work to move\n> away from that branch name, but it should be much easier for new\n> repositories.\n> \n> This patch series allows overriding the branch name being used for new\n> repositories' main branch. This can be configured via init.defaultBranch.\n> \n> The initial patch was started by newcomer Don Goodman-Wilson, as well as the\n> bigger change that morphed into #655, where we demonstrate how to change\n> Git's hard-coded default branch name for new repositories to main based on\n> this here patch series, verifying the approach. Thanks for the contribution!\n> \n> This series DOES NOT change the default automatically, but only provides an\n> opt-in mechanism for interested users. The plan for that is to convert the\n> test scripts incrementally (by introducing GIT_TEST_DEFAULT_MAIN_BRANCH_NAME\n> , which overrides init.defaultBranch, and then converting the tricky test\n> scripts first, one by one, using that environment variable).\n\nI'm very happy with this and the way it's progressed since v1.  This\nseems simpler than earlier designs, and I appreciate the improved focus\non avoiding special-casing branches, since I think that will make it\neasier for folks to choose branch naming that suits them.\n\nThanks for working on this.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"400809","messageId":"nycvar.QRO.7.76.6.2006291520220.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200629162003.GD20303@danh.dev","subject":"Re: [PATCH v4 1/9] fmt-merge-msg: stop treating `master` specially","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-29T13:27:44Z","receivedAt":"2020-06-30T13:17:16Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Danh,\n\nOn Mon, 29 Jun 2020, Đoàn Trần Công Danh wrote:\n\n> On 2020-06-24 14:46:28+0000, Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com> wrote:\n> > From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> >\n> > In the context of many projects renaming their primary branch names away\n> > from `master`, Git wants to stop treating the `master` branch specially.\n> >\n> > Let's start with `git fmt-merge-msg`.\n> >\n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> > ---\n>\n> Hi Dscho,\n>\n> This change will also affect git-subtree test.\n\nGood point. The patch looks good. I wonder whether we should also address\nthese:\n\nDocumentation/git-rebase.txt:*   Merge branch 'report-a-bug'\nDocumentation/git-rebase.txt:* | Merge branch 'refactor-button'\nDocumentation/git-switch.txt:HEAD is now at 9fc9555312 Merge branch 'cc/shared-index-permbits'\nDocumentation/howto/using-signed-tag-in-pull-request.txt: Merge tag 'frotz-for-xyzzy' of example.com:/git/froboz.git/\nDocumentation/howto/using-signed-tag-in-pull-request.txt:     Merge tag 'frotz-for-xyzzy' of example.com:/git/froboz.git/\nt/t7606-merge-custom.sh:*   (HEAD, master) Merge commit 'c3'\n\nThe first three matches are in manual pages, the next two in technical\ndocumentation, and the last one in a comment in one of the test scripts.\nSo none of them are super critical, but maybe there are different\nopinions?\n\nCiao,\nDscho\n\n> We'll need this patch for subtree:\n> ----------------8<-------------------\n> From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=\n>  <congdanhqx@gmail.com>\n> Date: Mon, 29 Jun 2020 22:56:37 +0700\n> Subject: [PATCH] contrib: subtree: adjust test to change in fmt-merge-msg\n> MIME-Version: 1.0\n> Content-Type: text/plain; charset=UTF-8\n> Content-Transfer-Encoding: 8bit\n>\n> We're starting to stop treating `master' specially in fmt-merge-msg.\n> Adjust the test to reflect that change.\n>\n> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n> ---\n>  contrib/subtree/t/t7900-subtree.sh | 6 ++++--\n>  1 file changed, 4 insertions(+), 2 deletions(-)\n>\n> diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh\n> index 57ff4b25c1..53d7accf94 100755\n> --- a/contrib/subtree/t/t7900-subtree.sh\n> +++ b/contrib/subtree/t/t7900-subtree.sh\n> @@ -196,7 +196,8 @@ test_expect_success 'merge new subproj history into sub dir/ with --prefix' '\n>  \t\tcd \"$subtree_test_count\" &&\n>  \t\tgit fetch ./\"sub proj\" master &&\n>  \t\tgit subtree merge --prefix=\"sub dir\" FETCH_HEAD &&\n> -\t\tcheck_equal \"$(last_commit_message)\" \"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\''\"\n> +\t\tcheck_equal \"$(last_commit_message)\" \\\n> +\t\t\t\"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\'' into master\"\n>  \t)\n>  '\n>\n> @@ -273,7 +274,8 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende\n>  \t\tcd \"$test_count\" &&\n>  \t\tgit fetch ./subproj master &&\n>  \t\tgit subtree merge --prefix=subdir/ FETCH_HEAD &&\n> -\t\tcheck_equal \"$(last_commit_message)\" \"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\''\"\n> +\t\tcheck_equal \"$(last_commit_message)\" \\\n> +\t\t\t\"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\'' into master\"\n>  \t)\n>  '\n>\n> --\n> 2.27.0.111.gc72c7da667\n> Danh\n>\n"},{"id":"400822","messageId":"20200630150533.GF20303@danh.dev","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2006291520220.56@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v4 1/9] fmt-merge-msg: stop treating `master` specially","fromName":"Đoàn Trần Công Danh","fromEmail":"congdanhqx@gmail.com","sentAt":"2020-06-30T15:05:33Z","receivedAt":"2020-06-30T15:05:39Z","isPatch":true,"sender":{"key":"congdanhqx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42673067?v=4"},"body":"Hi Dscho,\n\nOn 2020-06-29 15:27:44+0200, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> > This change will also affect git-subtree test.\n> \n> Good point. The patch looks good. I wonder whether we should also address\n> these:\n> \n> Documentation/git-rebase.txt:*   Merge branch 'report-a-bug'\n> Documentation/git-rebase.txt:* | Merge branch 'refactor-button'\n> Documentation/git-switch.txt:HEAD is now at 9fc9555312 Merge branch 'cc/shared-index-permbits'\n> Documentation/howto/using-signed-tag-in-pull-request.txt: Merge tag 'frotz-for-xyzzy' of example.com:/git/froboz.git/\n> Documentation/howto/using-signed-tag-in-pull-request.txt:     Merge tag 'frotz-for-xyzzy' of example.com:/git/froboz.git/\n> t/t7606-merge-custom.sh:*   (HEAD, master) Merge commit 'c3'\n> \n> The first three matches are in manual pages, the next two in technical\n> documentation, and the last one in a comment in one of the test scripts.\n> So none of them are super critical, but maybe there are different\n> opinions?\n\nIn _my very opinion_, I don't think it's that critical.\nWe allow git merge --edit and git fmt-merge-msg -m.\nSomeone may have configured their Git to remove branch name already.\nAnd some others may always remove the target branch manually.\nWe probably don't want to introduce another master occurence.\n(For sideline watcher: Please not argue on this,\nI don't have any opinions about the word: master.)\n\nIf there're a consensus on changing those documentation,\nI won't mind to do that manual work ;)\n\nThe test is a different story, since some (or most?) distro enable\ncheck (or test) phase for their build infrastructure.\nAnd, we shouldn't break their infrastructures.\n\n> \n> Ciao,\n> Dscho\n> \n> > We'll need this patch for subtree:\n> > ----------------8<-------------------\n> > From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=\n> >  <congdanhqx@gmail.com>\n> > Date: Mon, 29 Jun 2020 22:56:37 +0700\n> > Subject: [PATCH] contrib: subtree: adjust test to change in fmt-merge-msg\n> > MIME-Version: 1.0\n> > Content-Type: text/plain; charset=UTF-8\n> > Content-Transfer-Encoding: 8bit\n> >\n> > We're starting to stop treating `master' specially in fmt-merge-msg.\n> > Adjust the test to reflect that change.\n> >\n> > Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n> > ---\n> >  contrib/subtree/t/t7900-subtree.sh | 6 ++++--\n> >  1 file changed, 4 insertions(+), 2 deletions(-)\n> >\n> > diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh\n> > index 57ff4b25c1..53d7accf94 100755\n> > --- a/contrib/subtree/t/t7900-subtree.sh\n> > +++ b/contrib/subtree/t/t7900-subtree.sh\n> > @@ -196,7 +196,8 @@ test_expect_success 'merge new subproj history into sub dir/ with --prefix' '\n> >  \t\tcd \"$subtree_test_count\" &&\n> >  \t\tgit fetch ./\"sub proj\" master &&\n> >  \t\tgit subtree merge --prefix=\"sub dir\" FETCH_HEAD &&\n> > -\t\tcheck_equal \"$(last_commit_message)\" \"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\''\"\n> > +\t\tcheck_equal \"$(last_commit_message)\" \\\n> > +\t\t\t\"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\'' into master\"\n> >  \t)\n> >  '\n> >\n> > @@ -273,7 +274,8 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende\n> >  \t\tcd \"$test_count\" &&\n> >  \t\tgit fetch ./subproj master &&\n> >  \t\tgit subtree merge --prefix=subdir/ FETCH_HEAD &&\n> > -\t\tcheck_equal \"$(last_commit_message)\" \"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\''\"\n> > +\t\tcheck_equal \"$(last_commit_message)\" \\\n> > +\t\t\t\"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\'' into master\"\n> >  \t)\n> >  '\n> >\n> > --\n> > 2.27.0.111.gc72c7da667\n> > Danh\n> >\n\n\n-- \nDanh\n"},{"id":"400887","messageId":"nycvar.QRO.7.76.6.2007011237330.56@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"20200630150533.GF20303@danh.dev","subject":"Re: [PATCH v4 1/9] fmt-merge-msg: stop treating `master` specially","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-07-01T10:39:07Z","receivedAt":"2020-07-01T10:39:29Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Danh,\n\nOn Tue, 30 Jun 2020, Đoàn Trần Công Danh wrote:\n\n> On 2020-06-29 15:27:44+0200, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> > > This change will also affect git-subtree test.\n> >\n> > Good point. The patch looks good. I wonder whether we should also address\n> > these:\n> >\n> > Documentation/git-rebase.txt:*   Merge branch 'report-a-bug'\n> > Documentation/git-rebase.txt:* | Merge branch 'refactor-button'\n> > Documentation/git-switch.txt:HEAD is now at 9fc9555312 Merge branch 'cc/shared-index-permbits'\n> > Documentation/howto/using-signed-tag-in-pull-request.txt: Merge tag 'frotz-for-xyzzy' of example.com:/git/froboz.git/\n> > Documentation/howto/using-signed-tag-in-pull-request.txt:     Merge tag 'frotz-for-xyzzy' of example.com:/git/froboz.git/\n> > t/t7606-merge-custom.sh:*   (HEAD, master) Merge commit 'c3'\n> >\n> > The first three matches are in manual pages, the next two in technical\n> > documentation, and the last one in a comment in one of the test scripts.\n> > So none of them are super critical, but maybe there are different\n> > opinions?\n>\n> In _my very opinion_, I don't think it's that critical.\n> We allow git merge --edit and git fmt-merge-msg -m.\n> Someone may have configured their Git to remove branch name already.\n> And some others may always remove the target branch manually.\n> We probably don't want to introduce another master occurence.\n> (For sideline watcher: Please not argue on this,\n> I don't have any opinions about the word: master.)\n\nTrue.\n\n> If there're a consensus on changing those documentation,\n> I won't mind to do that manual work ;)\n\nI actually agree that it is not _really_ necessary.\n\n> The test is a different story, since some (or most?) distro enable\n> check (or test) phase for their build infrastructure.\n> And, we shouldn't break their infrastructures.\n\n\nActually, the hit in t7606 is in the initial _comment_. So I highly doubt\nthat it would break any build infrastructure to leave it alone.\n\nCiao,\nDscho\n\n> >\n> > Ciao,\n> > Dscho\n> >\n> > > We'll need this patch for subtree:\n> > > ----------------8<-------------------\n> > > From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=\n> > >  <congdanhqx@gmail.com>\n> > > Date: Mon, 29 Jun 2020 22:56:37 +0700\n> > > Subject: [PATCH] contrib: subtree: adjust test to change in fmt-merge-msg\n> > > MIME-Version: 1.0\n> > > Content-Type: text/plain; charset=UTF-8\n> > > Content-Transfer-Encoding: 8bit\n> > >\n> > > We're starting to stop treating `master' specially in fmt-merge-msg.\n> > > Adjust the test to reflect that change.\n> > >\n> > > Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>\n> > > ---\n> > >  contrib/subtree/t/t7900-subtree.sh | 6 ++++--\n> > >  1 file changed, 4 insertions(+), 2 deletions(-)\n> > >\n> > > diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh\n> > > index 57ff4b25c1..53d7accf94 100755\n> > > --- a/contrib/subtree/t/t7900-subtree.sh\n> > > +++ b/contrib/subtree/t/t7900-subtree.sh\n> > > @@ -196,7 +196,8 @@ test_expect_success 'merge new subproj history into sub dir/ with --prefix' '\n> > >  \t\tcd \"$subtree_test_count\" &&\n> > >  \t\tgit fetch ./\"sub proj\" master &&\n> > >  \t\tgit subtree merge --prefix=\"sub dir\" FETCH_HEAD &&\n> > > -\t\tcheck_equal \"$(last_commit_message)\" \"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\''\"\n> > > +\t\tcheck_equal \"$(last_commit_message)\" \\\n> > > +\t\t\t\"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\'' into master\"\n> > >  \t)\n> > >  '\n> > >\n> > > @@ -273,7 +274,8 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende\n> > >  \t\tcd \"$test_count\" &&\n> > >  \t\tgit fetch ./subproj master &&\n> > >  \t\tgit subtree merge --prefix=subdir/ FETCH_HEAD &&\n> > > -\t\tcheck_equal \"$(last_commit_message)\" \"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\''\"\n> > > +\t\tcheck_equal \"$(last_commit_message)\" \\\n> > > +\t\t\t\"Merge commit '\\''$(git rev-parse FETCH_HEAD)'\\'' into master\"\n> > >  \t)\n> > >  '\n> > >\n> > > --\n> > > 2.27.0.111.gc72c7da667\n> > > Danh\n> > >\n>\n>\n> --\n> Danh\n>\n"},{"id":"400942","messageId":"xmqq366bdn9d.fsf@gitster.c.googlers.com","threadId":"53651","inReplyTo":"nycvar.QRO.7.76.6.2007011237330.56@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v4 1/9] fmt-merge-msg: stop treating `master` specially","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-07-01T19:54:38Z","receivedAt":"2020-07-01T19:54:45Z","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>> In _my very opinion_, I don't think it's that critical.\n>> We allow git merge --edit and git fmt-merge-msg -m.\n>> ...\n>\n> True.\n>\n>> If there're a consensus on changing those documentation,\n>> I won't mind to do that manual work ;)\n>\n> I actually agree that it is not _really_ necessary.\n>\n>> The test is a different story, since some (or most?) distro enable\n>> check (or test) phase for their build infrastructure.\n>> And, we shouldn't break their infrastructures.\n>\n> Actually, the hit in t7606 is in the initial _comment_. So I highly doubt\n> that it would break any build infrastructure to leave it alone.\n\nI guess it's settled, then.\n\nThank you to all for being extra careful.\n\n"},{"id":"401411","messageId":"CA+WKDT2DV6ymu-AG9B2h34=K+4KW7tcCpAfTV-rTdifqfS7R=g@mail.gmail.com","threadId":"53651","inReplyTo":"20200629224113.GC9782@camp.crustytoothpaste.net","subject":"Re: [PATCH v4 0/9] Allow overriding the default name of the default branch","fromName":"Edward Thomson","fromEmail":"ethomson@edwardthomson.com","sentAt":"2020-07-12T13:03:38Z","receivedAt":"2020-07-12T13:03:52Z","isPatch":true,"sender":{"key":"ethomson@edwardthomson.com","avatar":"https://avatars.githubusercontent.com/u/1130014?v=4"},"body":"On Mon, Jun 29, 2020 at 11:42 PM brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n>\n> I'm very happy with this and the way it's progressed since v1.  This\n> seems simpler than earlier designs, and I appreciate the improved focus\n> on avoiding special-casing branches, since I think that will make it\n> easier for folks to choose branch naming that suits them.\n>\n> Thanks for working on this.\n\nI agree, this is an improvement.\n\nOne thing that isn't obvious to me, though, is why templates take\nprecedence over the command-line option.  I would expect the command-line\noption to be the highest priority option given, just like configuration\nvalues specified on the command-line override values from configuration\nfiles.\n\nCheers-\n-ed\n"},{"id":"401503","messageId":"nycvar.QRO.7.76.6.2007121007440.50@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"CA+WKDT2DV6ymu-AG9B2h34=K+4KW7tcCpAfTV-rTdifqfS7R=g@mail.gmail.com","subject":"Re: [PATCH v4 0/9] Allow overriding the default name of the default branch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-07-12T08:19:40Z","receivedAt":"2020-07-13T19:38:39Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Ed,\n\nOn Sun, 12 Jul 2020, Edward Thomson wrote:\n\n> On Mon, Jun 29, 2020 at 11:42 PM brian m. carlson\n> <sandals@crustytoothpaste.net> wrote:\n> >\n> > I'm very happy with this and the way it's progressed since v1.  This\n> > seems simpler than earlier designs, and I appreciate the improved focus\n> > on avoiding special-casing branches, since I think that will make it\n> > easier for folks to choose branch naming that suits them.\n> >\n> > Thanks for working on this.\n>\n> I agree, this is an improvement.\n>\n> One thing that isn't obvious to me, though, is why templates take\n> precedence over the command-line option.  I would expect the command-line\n> option to be the highest priority option given, just like configuration\n> values specified on the command-line override values from configuration\n> files.\n\nSide note: I have not tested this, but I trust you did, and my reading of\nthe code agrees that it does this.\n\nThe reason why it works that way is that while the `copy_templates()`\nfunction is called before the `create_symref()` call that creates the\n`HEAD` symref, the latter call is guarded by the condition that `HEAD`\ndoes not yet exist. Here is a link that highlights both calls (and the\ncode in between):\nhttps://github.com/git/git/blob/v2.27.0/builtin/init-db.c#L229-L270\n\nNow, it is probably not the intention of the code to prohibit the\nconfig setting from overriding the template files, but instead it intends\nto guard against overwriting files by running `git init` in an\n_already-initialized_ repository. And I don't think that it possible,\nreally, to change the logic without making the effect quite hard to\nexplain.\n\nThe truth is that overriding the default name via editing the templates is\njust not a very good strategy, it is fraught with peril, as e.g.\n`init.templateDir` is a thing that can be easily specified via the\ncommand-line (`git -c init.templateDir=/tmp/my-templates init`).\n\nCiao,\nDscho\n"},{"id":"401550","messageId":"nycvar.QRO.7.76.6.2007141640430.52@tvgsbejvaqbjf.bet","threadId":"53651","inReplyTo":"CA+WKDT1GMNTY5N862-7ui70D6-b1u6fuUkvctEYo+57aJGbjmw@mail.gmail.com","subject":"Re: [PATCH v4 0/9] Allow overriding the default name of the default branch","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-07-14T14:55:39Z","receivedAt":"2020-07-14T14:55:44Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Ed,\n\n[re-Cc:ing the list, I hope you don't mind]\n\nOn Mon, 13 Jul 2020, Edward Thomson wrote:\n\n> On Mon, Jul 13, 2020 at 8:38 PM Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> > On Sun, 12 Jul 2020, Edward Thomson wrote:\n> > > One thing that isn't obvious to me, though, is why templates take\n> > > precedence over the command-line option.  I would expect the\n> > > command-line option to be the highest priority option given, just\n> > > like configuration values specified on the command-line override\n> > > values from configuration files.\n> >\n> > Side note: I have not tested this, but I trust you did, and my reading\n> > of the code agrees that it does this.\n>\n> I was speaking about the notion of configuration options specified with\n> `-c` on the command line overridding things in configuration files.\n> Like how you override `init.templateDir` on the command line:\n>\n> > The truth is that overriding the default name via editing the templates is\n> > just not a very good strategy, it is fraught with peril, as e.g.\n> > `init.templateDir` is a thing that can be easily specified via the\n> > command-line (`git -c init.templateDir=/tmp/my-templates init`).\n>\n> I agree that setting a template that contains `HEAD` is perilous.  But\n> it's an established and supported bit of peril.  I think that the question\n> of configuration specificity is _also_ an established one (and not nearly\n> so perilous).  Just like `-cinit.defaultBranch` overrides the global\n> configuration, I would expect it to override the templates as well.\n\nIs it really well-established? If so, it might really be worth doing\nsomething like this:\n\n-- snip --\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex cee64823cbb..9149f9e51f5 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -210,7 +210,7 @@ static int create_default_files(const char *template_path,\n \tstruct strbuf buf = STRBUF_INIT;\n \tchar *path;\n \tchar junk[2];\n-\tint reinit;\n+\tint reinit, override_HEAD_in_templates = 0;\n \tint filemode;\n \tstruct strbuf err = STRBUF_INIT;\n\n@@ -218,6 +218,12 @@ static int create_default_files(const char *template_path,\n \tinit_db_template_dir = NULL; /* re-set in case it was set before */\n \tgit_config(git_init_db_config, NULL);\n\n+\tif (initial_branch) {\n+\t\tpath = git_path_buf(&buf, \"HEAD\");\n+\t\toverride_HEAD_in_templates = access(path, R_OK) ||\n+\t\t\treadlink(path, junk, sizeof(junk)-1) < 0;\n+\t}\n+\n \t/*\n \t * First copy the templates -- we might have the default\n \t * config file there, in which case we would want to read\n@@ -265,7 +271,7 @@ static int create_default_files(const char *template_path,\n \tpath = git_path_buf(&buf, \"HEAD\");\n \treinit = (!access(path, R_OK)\n \t\t  || readlink(path, junk, sizeof(junk)-1) != -1);\n-\tif (!reinit) {\n+\tif (!reinit || override_HEAD_in_templates) {\n \t\tchar *ref;\n\n \t\tif (!initial_branch)\n-- snap --\n\nNote that I initially considered moving the `reinit = [...]` part to before\nthe `copy_templates()` call, but `reinit` actually does quite a bit more\nthan just guard the symref creation of `HEAD`: it also guards the\n`core.filemode` test, the `core.symlinks` test and the `core.ignoreCase`\ntest. There _might_ be legitimate use cases to side-step those by\ndelivering a `HEAD` in the templates (which is, just as setting the\ninitial branch using templates, a relatively awkward and fragile way to\noverride it, but hey, we're trying to address exactly such a scenario).\n\nHowever, even having written the patch (which would still lack a\nregression test), I am not 100% certain that we would want to risk\nincluding it in v2.28.0. It strikes me as such a fringe use case (with\nrelatively obvious ways out) while the patch is not completely risk free\n(I _think_ it should be safe, of course, but it touches a relatively\ncentral part of Git).\n\nCiao,\nDscho\n"}]}