{"thread":{"id":"66581","subject":"[PATCH v1] remote.c: defer remote.<name>.followRemoteHEAD validation","startedAt":"2026-10-18T23:55:07Z","lastAt":"2026-11-08T21:45:16Z","messageCount":19,"participants":["Colin Hinton","Junio C Hamano","Matt Hunter"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"555369","messageId":"20261018235508.848-1-colinlewishinton@gmail.com","threadId":"66581","inReplyTo":null,"subject":"[PATCH v1] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Colin Hinton","fromEmail":"colinlewishinton@gmail.com","sentAt":"2026-10-18T23:55:07Z","receivedAt":"2026-10-18T23:55:07Z","isPatch":true,"sender":{"key":"colinlewishinton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128193236?v=4"},"body":"Continuing from 86129fd (fetch.c: defer fetch.followRemoteHEAD\nvalidation), apply the same treatment to\nremote.<name>.followRemoteHEAD, which is still validated in\nhandle_config(). That emits a warning for any command that loads the\nremote configuration, such as \"git push\" or \"git remote -v\", even\nthough only \"git fetch\" ever consults the value.\n\nStore the raw string in struct remote instead, and resolve it lazily\nin do_fetch() through the get_follow_remote_head() helper introduced\nby 86129fd. This replaces the parsed follow_remote_head and\nno_warn_branch members, and the NEEDSWORK comment left behind by\n86129fd is removed. \"git remote set-head\" now compares against the\nraw string to decide whether to rewrite \"always\" to \"warn\".\n\nBecause both settings now go through the same parser,\nfetch.followRemoteHEAD accepts \"warn-if-not-<branch>\", which\npreviously was only recognized for remote.<name>.followRemoteHEAD.\nDocument it under fetch.followRemoteHEAD, drop the remote-specific\nparagraph, and add tests for the new fetch-level form.\n\nMessages for an unrecognized or missing value no longer name the\nfetch. prefix, as the helper now serves both the fetch-level and\nthe remote-level setting.\n\nSigned-off-by: Colin Hinton <colinlewishinton@gmail.com>\n---\n Documentation/config/fetch.adoc  |  3 +++\n Documentation/config/remote.adoc |  4 ----\n builtin/fetch.c                  | 26 +++++++++++++-------------\n builtin/remote.c                 |  2 +-\n remote.c                         | 28 ++++------------------------\n remote.h                         |  4 ++--\n t/t5510-fetch.sh                 | 28 ++++++++++++++++++++++++++++\n 7 files changed, 51 insertions(+), 44 deletions(-)\n\ndiff --git a/Documentation/config/fetch.adoc b/Documentation/config/fetch.adoc\nindex 00435e9a16..5e70949c2b 100644\n--- a/Documentation/config/fetch.adoc\n+++ b/Documentation/config/fetch.adoc\n@@ -139,6 +139,9 @@ remove the value for the `fetch.bundleCreationToken` value before fetching.\n `warn`;;\n \tDisplay a warning if the remote advertises a different `HEAD` than what is\n \tset locally.  Behaves like \"create\" if the local symbolic-ref doesn't exist.\n+`warn-if-not-<branch>`;;\n+\tLike \"warn\", but do not display the warning if the remote's `HEAD`\n+\tis `remotes/<name>/<branch>`.\n `always`;;\n \tSilently update `remotes/<name>/HEAD` whenever the remote advertises a new\n \tvalue.\ndiff --git a/Documentation/config/remote.adoc b/Documentation/config/remote.adoc\nindex 3a20d0f752..56b036fc98 100644\n--- a/Documentation/config/remote.adoc\n+++ b/Documentation/config/remote.adoc\n@@ -171,7 +171,3 @@ remote.<name>.followRemoteHEAD::\n \t`remotes/<name>/HEAD` symbolic-ref.  Overrides the value of\n \t`fetch.followRemoteHEAD`.  See `fetch.followRemoteHEAD` for a description of\n \taccepted values.\n-+\n-In addition to the values supported by `fetch.followRemoteHEAD`, this setting\n-may also take on the value \"warn-if-not-`$branch`\", which behaves like \"warn\",\n-but ignores the warning if the remote's `HEAD` is `remotes/<name>/$branch`.\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 1f76ae6242..aa112f9b5a 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -187,19 +187,23 @@ static int git_fetch_config(const char *k, const char *v,\n \treturn git_default_config(k, v, ctx, cb);\n }\n \n-static enum follow_remote_head_settings get_follow_remote_head(const char *setting)\n+static enum follow_remote_head_settings get_follow_remote_head(const char *setting,\n+    const char **no_warn_branch)\n {\n+\t*no_warn_branch = NULL;\n \tif (!setting)\n-\t\tdie(_(\"missing value for 'fetch.followRemoteHEAD'\"));\n+\t\tdie(_(\"missing value for 'followRemoteHEAD'\"));\n \telse if (!strcmp(setting, \"never\"))\n \t\treturn FOLLOW_REMOTE_NEVER;\n \telse if (!strcmp(setting, \"create\"))\n \t\treturn FOLLOW_REMOTE_CREATE;\n \telse if (!strcmp(setting, \"warn\"))\n \t\treturn FOLLOW_REMOTE_WARN;\n+\telse if (skip_prefix(setting, \"warn-if-not-\", no_warn_branch))\n+\t\treturn FOLLOW_REMOTE_WARN;\n \telse if (!strcmp(setting, \"always\"))\n \t\treturn FOLLOW_REMOTE_ALWAYS;\n-\twarning(_(\"unrecognized fetch.followRemoteHEAD value '%s' ignored\"), setting);\n+\twarning(_(\"unrecognized followRemoteHEAD value '%s' ignored\"), setting);\n \treturn BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n }\n \n@@ -1760,12 +1764,11 @@ static void warn_set_head(const char *remote, const char *head_name,\n }\n \n static int set_head(const struct ref *remote_refs, struct remote *remote,\n-\t\t\tint follow_remote_head)\n+\t\t    int follow_remote_head, const char *no_warn_branch)\n {\n \tint result = 0, create_only, baremirror, was_detached;\n \tstruct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,\n \t\t      b_local_head = STRBUF_INIT;\n-\tconst char *no_warn_branch = remote->no_warn_branch;\n \tchar *head_name = NULL;\n \tstruct ref *ref, *matches;\n \tstruct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map;\n@@ -1955,6 +1958,7 @@ static int do_fetch(struct transport *transport,\n \tstruct strmap rejected_refs = STRMAP_INIT;\n \tint summary_width = 0;\n \tint follow_remote_head = FOLLOW_REMOTE_NEVER;\n+\tconst char *no_warn_branch = NULL;\n \n \tif (tags == TAGS_DEFAULT) {\n \t\tif (transport->remote->fetch_tags == 2)\n@@ -1978,14 +1982,10 @@ static int do_fetch(struct transport *transport,\n \t\tif (transport->remote->fetch.nr) {\n \t\t\trefspec_ref_prefixes(&transport->remote->fetch,\n \t\t\t\t\t     &transport_ls_refs_options.ref_prefixes);\n-\t\t\t/*\n-\t\t\t * See remote.c's handling of remote.<name>.followRemoteHEAD\n-\t\t\t * for the analogous, still-unresolved case.\n-\t\t\t */\n-\t\t\tif (transport->remote->follow_remote_head)\n-\t\t\t\tfollow_remote_head = transport->remote->follow_remote_head;\n+\t\t\tif (transport->remote->follow_remote_head_seen)\n+\t\t\t\tfollow_remote_head = get_follow_remote_head(transport->remote->follow_remote_head_raw, &no_warn_branch);\n \t\t\telse if (config->follow_remote_head_seen)\n-\t\t\t\tfollow_remote_head = get_follow_remote_head(config->follow_remote_head_raw);\n+\t\t\t\tfollow_remote_head = get_follow_remote_head(config->follow_remote_head_raw, &no_warn_branch);\n \t\t\telse\n \t\t\t\tfollow_remote_head = BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n \t\t}\n@@ -2195,7 +2195,7 @@ static int do_fetch(struct transport *transport,\n \t\t * Way too many cases where this can go wrong so let's just\n \t\t * ignore errors and fail silently for now.\n \t\t */\n-\t\tset_head(remote_refs, transport->remote, follow_remote_head);\n+\t\tset_head(remote_refs, transport->remote, follow_remote_head, no_warn_branch);\n \t}\n \n cleanup:\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex fb7e5b114f..92eaffb4a0 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -1606,7 +1606,7 @@ static int set_head(int argc, const char **argv, const char *prefix,\n \t}\n \tif (opt_a)\n \t\treport_set_head_auto(argv[0], head_name, &b_local_head, was_detached);\n-\tif (remote->follow_remote_head == FOLLOW_REMOTE_ALWAYS) {\n+\tif (remote->follow_remote_head_raw && !strcmp(remote->follow_remote_head_raw, \"always\")) {\n \t\tstruct strbuf config_name = STRBUF_INIT;\n \t\tstrbuf_addf(&config_name,\n \t\t\t\"remote.%s.followremotehead\", remote->name);\ndiff --git a/remote.c b/remote.c\nindex 49ee2ea318..fa230005ff 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -184,6 +184,7 @@ static void remote_clear(struct remote *remote)\n \tstring_list_clear(&remote->server_options, 0);\n \tstring_list_clear(&remote->negotiation_restrict, 0);\n \tstring_list_clear(&remote->negotiation_include, 0);\n+\tfree(remote->follow_remote_head_raw);\n }\n \n static void add_merge(struct branch *branch, const char *name)\n@@ -581,30 +582,9 @@ static int handle_config(const char *key, const char *value,\n \t\treturn parse_transport_option(key, value,\n \t\t\t\t\t      &remote->negotiation_include);\n \t} else if (!strcmp(subkey, \"followremotehead\")) {\n-\t\tconst char *no_warn_branch;\n-\t\t/*\n-\t\t * NEEDSWORK: this is validated/warned about here, during config\n-\t\t * parsing, regardless of whether the fetch that triggered this\n-\t\t * parse will ever consult it for this particular remote. See\n-\t\t * fetch.c's deferred handling of fetch.followRemoteHEAD for the\n-\t\t * pattern this should likely follow.\n-\t\t */\n-\t\tif (!strcmp(value, \"never\"))\n-\t\t\tremote->follow_remote_head = FOLLOW_REMOTE_NEVER;\n-\t\telse if (!strcmp(value, \"create\"))\n-\t\t\tremote->follow_remote_head = FOLLOW_REMOTE_CREATE;\n-\t\telse if (!strcmp(value, \"warn\")) {\n-\t\t\tremote->follow_remote_head = FOLLOW_REMOTE_WARN;\n-\t\t\tremote->no_warn_branch = NULL;\n-\t\t} else if (skip_prefix(value, \"warn-if-not-\", &no_warn_branch)) {\n-\t\t\tremote->follow_remote_head = FOLLOW_REMOTE_WARN;\n-\t\t\tremote->no_warn_branch = no_warn_branch;\n-\t\t} else if (!strcmp(value, \"always\")) {\n-\t\t\tremote->follow_remote_head = FOLLOW_REMOTE_ALWAYS;\n-\t\t} else {\n-\t\t\twarning(_(\"unrecognized followRemoteHEAD value '%s' ignored\"),\n-\t\t\t\tvalue);\n-\t\t}\n+\t\tfree(remote->follow_remote_head_raw);\n+\t\tremote->follow_remote_head_raw = xstrdup_or_null(value);\n+\t\tremote->follow_remote_head_seen = 1;\n \t}\n \treturn 0;\n }\ndiff --git a/remote.h b/remote.h\nindex cca02033b9..e80beee6bb 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -122,8 +122,8 @@ struct remote {\n \tstruct string_list negotiation_restrict;\n \tstruct string_list negotiation_include;\n \n-\tenum follow_remote_head_settings follow_remote_head;\n-\tconst char *no_warn_branch;\n+\tchar *follow_remote_head_raw;\n+\tint follow_remote_head_seen;\n };\n \n /**\ndiff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh\nindex 17c0be499c..1e5ad50912 100755\n--- a/t/t5510-fetch.sh\n+++ b/t/t5510-fetch.sh\n@@ -290,6 +290,34 @@ test_expect_success \"fetch test followRemoteHEAD warn-if-not-branch branch is di\n \ttest \"z$head\" = \"z$branch\"\n '\n \n+test_expect_success \"fetch test default followRemoteHEAD warn-if-not-branch branch is same\" '\n+\tgit -C two rev-parse --verify refs/remotes/origin/other &&\n+\tgit -C two remote set-head origin other &&\n+\tgit -C two rev-parse --verify refs/remotes/origin/HEAD &&\n+\tgit -C two rev-parse --verify refs/remotes/origin/main &&\n+\ttest_config -C two fetch.followRemoteHEAD \"warn-if-not-main\" &&\n+\tactual=$(git -C two fetch) &&\n+\ttest \"z\" = \"z$actual\" &&\n+\thead=$(git -C two rev-parse refs/remotes/origin/HEAD) &&\n+\tbranch=$(git -C two rev-parse refs/remotes/origin/other) &&\n+\ttest \"z$head\" = \"z$branch\"\n+'\n+\n+test_expect_success \"fetch test default followRemoteHEAD warn-if-not-branch branch is different\" '\n+\tgit -C two rev-parse --verify refs/remotes/origin/other &&\n+\tgit -C two remote set-head origin other &&\n+\tgit -C two rev-parse --verify refs/remotes/origin/HEAD &&\n+\tgit -C two rev-parse --verify refs/remotes/origin/main &&\n+\ttest_config -C two fetch.followRemoteHEAD \"warn-if-not-some/different-branch\" &&\n+\tgit -C two fetch >actual &&\n+\techo \"${SQ}HEAD${SQ} at ${SQ}origin${SQ} is ${SQ}main${SQ},\" \\\n+\t\t\"but we have ${SQ}other${SQ} locally.\" >expect &&\n+\ttest_cmp expect actual &&\n+\thead=$(git -C two rev-parse refs/remotes/origin/HEAD) &&\n+\tbranch=$(git -C two rev-parse refs/remotes/origin/other) &&\n+\ttest \"z$head\" = \"z$branch\"\n+'\n+\n test_expect_success \"fetch test default followRemoteHEAD always\" '\n \tgit -C two rev-parse --verify refs/remotes/origin/other &&\n \tgit -C two remote set-head origin other &&\n-- \n2.55.0.windows.3\n\n\n"},{"id":"555431","messageId":"xmqqbj8p66ra.fsf@gitster.g","threadId":"66581","inReplyTo":"20261018235508.848-1-colinlewishinton@gmail.com","subject":"Re: [PATCH v1] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-19T15:37:45Z","receivedAt":"2026-10-19T15:37:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Colin Hinton <colinlewishinton@gmail.com> writes:\n\n> Continuing from 86129fd (fetch.c: defer fetch.followRemoteHEAD\n> validation), apply the same treatment to\n> remote.<name>.followRemoteHEAD, which is still validated in\n> handle_config(). That emits a warning for any command that loads the\n> remote configuration, such as \"git push\" or \"git remote -v\", even\n> though only \"git fetch\" ever consults the value.\n\nYeah, I remember that topic.  Making these two sources of the\nsetting that controls the same behaviour consistent is a good thing\nto do.\n\n> Store the raw string in struct remote instead, and resolve it lazily\n> in do_fetch() through the get_follow_remote_head() helper introduced\n> by 86129fd. This replaces the parsed follow_remote_head and\n\nAnd the approach does sound familiar ;-).\n\n> no_warn_branch members, and the NEEDSWORK comment left behind by\n> 86129fd is removed. \"git remote set-head\" now compares against the\n> raw string to decide whether to rewrite \"always\" to \"warn\".\n\n> Because both settings now go through the same parser,\n> fetch.followRemoteHEAD accepts \"warn-if-not-<branch>\", which\n> previously was only recognized for remote.<name>.followRemoteHEAD.\n> Document it under fetch.followRemoteHEAD, drop the remote-specific\n> paragraph, and add tests for the new fetch-level form.\n>\n> Messages for an unrecognized or missing value no longer name the\n> fetch. prefix, as the helper now serves both the fetch-level and\n> the remote-level setting.\n\nObviously, when remote.origin.followRemoteHEAD has a bogus value, it\nis wrong to report that the user has fetch.followRemoteHEAD\nmisconfigured (and vice versa), so not hardcoding \"fetch.\" is of\ncourse the right thing to do.  As long as it is clear to the user\nwhat exact variable has problematic value that needs fixing, it is a\ngood change.  If not, the two calling sites should pass what prefix\nto use so that the user sees the variable name in full.\n\n> -static enum follow_remote_head_settings get_follow_remote_head(const char *setting)\n> +static enum follow_remote_head_settings get_follow_remote_head(const char *setting,\n> +    const char **no_warn_branch)\n>  {\n> +\t*no_warn_branch = NULL;\n>  \tif (!setting)\n> -\t\tdie(_(\"missing value for 'fetch.followRemoteHEAD'\"));\n> +\t\tdie(_(\"missing value for 'followRemoteHEAD'\"));\n\nThis needs to be corrected, if we are reusing the function to report\nfor both fetch.followRemoteHEAD and remote.origin.followRemoteHEAD,\nby having the caller pass what prefix to use, or what variable name\nto report.\n\n>  \telse if (!strcmp(setting, \"never\"))\n>  \t\treturn FOLLOW_REMOTE_NEVER;\n>  \telse if (!strcmp(setting, \"create\"))\n>  \t\treturn FOLLOW_REMOTE_CREATE;\n>  \telse if (!strcmp(setting, \"warn\"))\n>  \t\treturn FOLLOW_REMOTE_WARN;\n> +\telse if (skip_prefix(setting, \"warn-if-not-\", no_warn_branch))\n> +\t\treturn FOLLOW_REMOTE_WARN;\n>  \telse if (!strcmp(setting, \"always\"))\n>  \t\treturn FOLLOW_REMOTE_ALWAYS;\n> -\twarning(_(\"unrecognized fetch.followRemoteHEAD value '%s' ignored\"), setting);\n> +\twarning(_(\"unrecognized followRemoteHEAD value '%s' ignored\"), setting);\n\nSame here.\n\n>  \treturn BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n>  }\n>  \n> @@ -1760,12 +1764,11 @@ static void warn_set_head(const char *remote, const char *head_name,\n>  }\n>  \n>  static int set_head(const struct ref *remote_refs, struct remote *remote,\n> -\t\t\tint follow_remote_head)\n> +\t\t    int follow_remote_head, const char *no_warn_branch)\n>  {\n>  \tint result = 0, create_only, baremirror, was_detached;\n>  \tstruct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,\n>  \t\t      b_local_head = STRBUF_INIT;\n> -\tconst char *no_warn_branch = remote->no_warn_branch;\n>  \tchar *head_name = NULL;\n>  \tstruct ref *ref, *matches;\n>  \tstruct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map;\n> @@ -1955,6 +1958,7 @@ static int do_fetch(struct transport *transport,\n>  \tstruct strmap rejected_refs = STRMAP_INIT;\n>  \tint summary_width = 0;\n>  \tint follow_remote_head = FOLLOW_REMOTE_NEVER;\n> +\tconst char *no_warn_branch = NULL;\n>  \n>  \tif (tags == TAGS_DEFAULT) {\n>  \t\tif (transport->remote->fetch_tags == 2)\n> @@ -1978,14 +1982,10 @@ static int do_fetch(struct transport *transport,\n>  \t\tif (transport->remote->fetch.nr) {\n>  \t\t\trefspec_ref_prefixes(&transport->remote->fetch,\n>  \t\t\t\t\t     &transport_ls_refs_options.ref_prefixes);\n> -\t\t\t/*\n> -\t\t\t * See remote.c's handling of remote.<name>.followRemoteHEAD\n> -\t\t\t * for the analogous, still-unresolved case.\n> -\t\t\t */\n> -\t\t\tif (transport->remote->follow_remote_head)\n> -\t\t\t\tfollow_remote_head = transport->remote->follow_remote_head;\n> +\t\t\tif (transport->remote->follow_remote_head_seen)\n> +\t\t\t\tfollow_remote_head = get_follow_remote_head(transport->remote->follow_remote_head_raw, &no_warn_branch);\n>  \t\t\telse if (config->follow_remote_head_seen)\n> -\t\t\t\tfollow_remote_head = get_follow_remote_head(config->follow_remote_head_raw);\n> +\t\t\t\tfollow_remote_head = get_follow_remote_head(config->follow_remote_head_raw, &no_warn_branch);\n>  \t\t\telse\n>  \t\t\t\tfollow_remote_head = BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n>  \t\t}\n> @@ -2195,7 +2195,7 @@ static int do_fetch(struct transport *transport,\n>  \t\t * Way too many cases where this can go wrong so let's just\n>  \t\t * ignore errors and fail silently for now.\n>  \t\t */\n> -\t\tset_head(remote_refs, transport->remote, follow_remote_head);\n> +\t\tset_head(remote_refs, transport->remote, follow_remote_head, no_warn_branch);\n>  \t}\n>  \n>  cleanup:\n> diff --git a/builtin/remote.c b/builtin/remote.c\n> index fb7e5b114f..92eaffb4a0 100644\n> --- a/builtin/remote.c\n> +++ b/builtin/remote.c\n> @@ -1606,7 +1606,7 @@ static int set_head(int argc, const char **argv, const char *prefix,\n>  \t}\n>  \tif (opt_a)\n>  \t\treport_set_head_auto(argv[0], head_name, &b_local_head, was_detached);\n> -\tif (remote->follow_remote_head == FOLLOW_REMOTE_ALWAYS) {\n> +\tif (remote->follow_remote_head_raw && !strcmp(remote->follow_remote_head_raw, \"always\")) {\n\nOverly long line.\n\n>  \t\tstruct strbuf config_name = STRBUF_INIT;\n>  \t\tstrbuf_addf(&config_name,\n>  \t\t\t\"remote.%s.followremotehead\", remote->name);\n\nThanks.\n\n"},{"id":"555469","messageId":"DM94QXU2Y6J7.39IGDUTB5XN1L@lfurio.us","threadId":"66581","inReplyTo":"20261018235508.848-1-colinlewishinton@gmail.com","subject":"Re: [PATCH v1] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Matt Hunter","fromEmail":"m@lfurio.us","sentAt":"2026-10-19T21:24:30Z","receivedAt":"2026-10-19T21:24:30Z","isPatch":true,"sender":{"key":"m@lfurio.us","avatar":"https://avatars.githubusercontent.com/u/14925125?v=4"},"body":"On Sun Oct 18, 2026 at 7:55 PM EDT, Colin Hinton wrote:\n> Continuing from 86129fd (fetch.c: defer fetch.followRemoteHEAD\n> validation), apply the same treatment to\n> remote.<name>.followRemoteHEAD, which is still validated in\n> handle_config(). That emits a warning for any command that loads the\n> remote configuration, such as \"git push\" or \"git remote -v\", even\n> though only \"git fetch\" ever consults the value.\n>\n> Store the raw string in struct remote instead, and resolve it lazily\n> in do_fetch() through the get_follow_remote_head() helper introduced\n> by 86129fd. This replaces the parsed follow_remote_head and\n> no_warn_branch members, and the NEEDSWORK comment left behind by\n> 86129fd is removed. \"git remote set-head\" now compares against the\n> raw string to decide whether to rewrite \"always\" to \"warn\".\n>\n> Because both settings now go through the same parser,\n> fetch.followRemoteHEAD accepts \"warn-if-not-<branch>\", which\n> previously was only recognized for remote.<name>.followRemoteHEAD.\n> Document it under fetch.followRemoteHEAD, drop the remote-specific\n> paragraph, and add tests for the new fetch-level form.\n\nI think a better justification is needed for this.  The intent behind\n'warn-if-not-<branch>' makes much less sense in the context of the fetch\nvariable imo, and if it turns out to be problematic, reverting support\nlater will be tricky.\n\nSee previous discussion:\n<20260611060123.GA2187173@coredump.intra.peff.net>\n<DJ6IBPYNOTTY.3QKEZQ28P713V@ferdinandy.com>\n\n>\n> Messages for an unrecognized or missing value no longer name the\n> fetch. prefix, as the helper now serves both the fetch-level and\n> the remote-level setting.\n\nI agree with Junio that this should be addressed.\n\n>\n> @@ -139,6 +139,9 @@ remove the value for the `fetch.bundleCreationToken` value before fetching.\n>  `warn`;;\n>  \tDisplay a warning if the remote advertises a different `HEAD` than what is\n>  \tset locally.  Behaves like \"create\" if the local symbolic-ref doesn't exist.\n> +`warn-if-not-<branch>`;;\n> +\tLike \"warn\", but do not display the warning if the remote's `HEAD`\n> +\tis `remotes/<name>/<branch>`.\n>  `always`;;\n>  \tSilently update `remotes/<name>/HEAD` whenever the remote advertises a new\n>  \tvalue.\n\nI like the style change from $branch to <branch>\n\n> @@ -1978,14 +1982,10 @@ static int do_fetch(struct transport *transport,\n>  \t\tif (transport->remote->fetch.nr) {\n>  \t\t\trefspec_ref_prefixes(&transport->remote->fetch,\n>  \t\t\t\t\t     &transport_ls_refs_options.ref_prefixes);\n> -\t\t\t/*\n> -\t\t\t * See remote.c's handling of remote.<name>.followRemoteHEAD\n> -\t\t\t * for the analogous, still-unresolved case.\n> -\t\t\t */\n> -\t\t\tif (transport->remote->follow_remote_head)\n> -\t\t\t\tfollow_remote_head = transport->remote->follow_remote_head;\n> +\t\t\tif (transport->remote->follow_remote_head_seen)\n> +\t\t\t\tfollow_remote_head = get_follow_remote_head(transport->remote->follow_remote_head_raw, &no_warn_branch);\n>  \t\t\telse if (config->follow_remote_head_seen)\n> -\t\t\t\tfollow_remote_head = get_follow_remote_head(config->follow_remote_head_raw);\n> +\t\t\t\tfollow_remote_head = get_follow_remote_head(config->follow_remote_head_raw, &no_warn_branch);\n\nA couple more overly-long lines\n\n>  \t\t\telse\n>  \t\t\t\tfollow_remote_head = BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n>  \t\t}\n\nBy the way, I had previously made a comment about moving the definition\nof 'enum follow_remote_head_settings' over to the fetch file since that\nis now the only place it is relevant.  Do you think it's worth changing?\n\n"},{"id":"555753","messageId":"CAHeTm9N4s744v0bgJJSbPoc4=1omKrhAXNuoY4Wey7FZBw-48A@mail.gmail.com","threadId":"66581","inReplyTo":"DM94QXU2Y6J7.39IGDUTB5XN1L@lfurio.us","subject":"Re: [PATCH v1] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Colin Hinton","fromEmail":"colinlewishinton@gmail.com","sentAt":"2026-10-21T16:30:03Z","receivedAt":"2026-10-21T16:30:03Z","isPatch":true,"sender":{"key":"colinlewishinton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128193236?v=4"},"body":"Matt & Junio\n\n> I think a better justification is needed for this.  The intent behind\n> 'warn-if-not-<branch>' makes much less sense in the context of the fetch\n> variable imo, and if it turns out to be problematic, reverting support\n> later will be tricky.\n>\nI don't have a particularly strong justification for this,  and was\nalready on the fence about including this change or not.\nI likely will revert this addition for fetch, and make it so that this\nonly works for remote.\n\n> > Messages for an unrecognized or missing value no longer name the\n> > fetch. prefix, as the helper now serves both the fetch-level and\n> > the remote-level setting.\n>\n> I agree with Junio that this should be addressed.\n>\nI also went back and forth on how valuable this is, since if it's a\ntypo it should be clear which variable is incorrect.\nBut being detailed doesn't hurt, and in the event of an empty or \" \"\nmistake then it will be even easier to identify the configuration\nerror.\n> >\n> > @@ -139,6 +139,9 @@ remove the value for the `fetch.bundleCreationToken` value before fetching.\n> >  `warn`;;\n> >       Display a warning if the remote advertises a different `HEAD` than what is\n> >       set locally.  Behaves like \"create\" if the local symbolic-ref doesn't exist.\n> > +`warn-if-not-<branch>`;;\n> > +     Like \"warn\", but do not display the warning if the remote's `HEAD`\n> > +     is `remotes/<name>/<branch>`.\n> >  `always`;;\n> >       Silently update `remotes/<name>/HEAD` whenever the remote advertises a new\n> >       value.\n>\n> I like the style change from $branch to <branch>\n>\nIf I am reverting the change to fetch and warn-if-not, I will need to\nrevert the .adoc changes too, but I can make this change back in the\nremote.adoc if we believe this is an improvement.\n\n> > +                             follow_remote_head = get_follow_remote_head(transport->remote->follow_remote_head_raw, &no_warn_branch);\n> >                       else if (config->follow_remote_head_seen)\n> > -                             follow_remote_head = get_follow_remote_head(config->follow_remote_head_raw);\n> > +                             follow_remote_head = get_follow_remote_head(config->follow_remote_head_raw, &no_warn_branch);\n>\n> A couple more overly-long lines\n>\nI will clean these up, and the ones Junio mentioned, thanks for\npointing these out.\n> >                       else\n> >                               follow_remote_head = BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n> >               }\n>\n> By the way, I had previously made a comment about moving the definition\n> of 'enum follow_remote_head_settings' over to the fetch file since that\n> is now the only place it is relevant.  Do you think it's worth changing?\n\nGiven the change I am proposing in remote.c where the enum is no\nlonger used, I do see the value in changing the scope of the enum, I\nwill experiment with this and update this in v2.\n\n-Colin Hinton\n\n"},{"id":"555859","messageId":"DMBDGW6SDQSS.2QROT2GXP0R28@lfurio.us","threadId":"66581","inReplyTo":"CAHeTm9N4s744v0bgJJSbPoc4=1omKrhAXNuoY4Wey7FZBw-48A@mail.gmail.com","subject":"Re: [PATCH v1] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Matt Hunter","fromEmail":"m@lfurio.us","sentAt":"2026-10-22T12:39:53Z","receivedAt":"2026-10-22T12:39:53Z","isPatch":true,"sender":{"key":"m@lfurio.us","avatar":"https://avatars.githubusercontent.com/u/14925125?v=4"},"body":"On Wed Oct 21, 2026 at 12:30 PM EDT, Colin Hinton wrote:\n>> I like the style change from $branch to <branch>\n>>\n> If I am reverting the change to fetch and warn-if-not, I will need to\n> revert the .adoc changes too, but I can make this change back in the\n> remote.adoc if we believe this is an improvement.\n\nIt's more consistent, which is why I'd be in favor\n\nthanks\n\n"},{"id":"556100","messageId":"20261023185007.21642-1-colinlewishinton@gmail.com","threadId":"66581","inReplyTo":"20261018235508.848-1-colinlewishinton@gmail.com","subject":"[PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Colin Hinton","fromEmail":"colinlewishinton@gmail.com","sentAt":"2026-10-23T18:50:07Z","receivedAt":"2026-10-23T18:50:07Z","isPatch":true,"sender":{"key":"colinlewishinton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128193236?v=4"},"body":"Continuing from 86129fd (fetch.c: defer fetch.followRemoteHEAD\nvalidation), apply the same treatment to\nremote.<name>.followRemoteHEAD, which is still validated in\nhandle_config(). That emits a warning for any command that loads the\nremote configuration, such as \"git push\" or \"git remote -v\", even\nthough only \"git fetch\" ever consults the value.\n\nStore the raw string in struct remote instead, and resolve it lazily\nin do_fetch() through the get_follow_remote_head() helper introduced\nby 86129fd. This replaces the parsed follow_remote_head and\nno_warn_branch members, and the NEEDSWORK comment left behind by\n86129fd is removed. \"git remote set-head\" now compares against the\nraw string to decide whether to rewrite \"always\" to \"warn\".\n\nMoved enum follow_remote_head_settings to builtin/fetch.c as it is no\nlonger referenced in remote.\n\nMessages for an unrecognized or missing value name the full variable\nname prefix, as the helper now serves both the fetch-level and\nthe remote-level setting.\n\nSigned-off-by: Colin Hinton <colinlewishinton@gmail.com>\n---\n Documentation/config/remote.adoc |  4 +--\n builtin/fetch.c                  | 45 +++++++++++++++++++++-----------\n builtin/remote.c                 |  3 ++-\n remote.c                         | 28 +++-----------------\n remote.h                         | 13 ++-------\n t/t5510-fetch.sh                 | 18 +++++++++++++\n 6 files changed, 58 insertions(+), 53 deletions(-)\n\ndiff --git a/Documentation/config/remote.adoc b/Documentation/config/remote.adoc\nindex 3a20d0f752..d19fe88ef3 100644\n--- a/Documentation/config/remote.adoc\n+++ b/Documentation/config/remote.adoc\n@@ -173,5 +173,5 @@ remote.<name>.followRemoteHEAD::\n \taccepted values.\n +\n In addition to the values supported by `fetch.followRemoteHEAD`, this setting\n-may also take on the value \"warn-if-not-`$branch`\", which behaves like \"warn\",\n-but ignores the warning if the remote's `HEAD` is `remotes/<name>/$branch`.\n+may also take on the value \"warn-if-not-`<branch>`\", which behaves like \"warn\",\n+but ignores the warning if the remote's `HEAD` is `remotes/<name>/<branch>`.\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 1f76ae6242..bb59e70865 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -65,6 +65,15 @@ enum display_format {\n \tDISPLAY_FORMAT_PORCELAIN,\n };\n \n+#define BUILTIN_FOLLOW_REMOTE_HEAD_DFLT FOLLOW_REMOTE_CREATE\n+enum follow_remote_head_settings {\n+\tFOLLOW_REMOTE_UNCONFIGURED = 0,\n+\tFOLLOW_REMOTE_NEVER,\n+\tFOLLOW_REMOTE_CREATE,\n+\tFOLLOW_REMOTE_WARN,\n+\tFOLLOW_REMOTE_ALWAYS,\n+};\n+\n struct display_state {\n \tstruct strbuf buf;\n \n@@ -187,19 +196,22 @@ static int git_fetch_config(const char *k, const char *v,\n \treturn git_default_config(k, v, ctx, cb);\n }\n \n-static enum follow_remote_head_settings get_follow_remote_head(const char *setting)\n+static enum follow_remote_head_settings get_follow_remote_head(const char *setting,\n+    const char *key, const char **no_warn_branch)\n {\n \tif (!setting)\n-\t\tdie(_(\"missing value for 'fetch.followRemoteHEAD'\"));\n+\t\tdie(_(\"missing value for '%s'\"), key);\n \telse if (!strcmp(setting, \"never\"))\n \t\treturn FOLLOW_REMOTE_NEVER;\n \telse if (!strcmp(setting, \"create\"))\n \t\treturn FOLLOW_REMOTE_CREATE;\n \telse if (!strcmp(setting, \"warn\"))\n \t\treturn FOLLOW_REMOTE_WARN;\n+\telse if (no_warn_branch && skip_prefix(setting, \"warn-if-not-\", no_warn_branch))\n+\t\treturn FOLLOW_REMOTE_WARN;\n \telse if (!strcmp(setting, \"always\"))\n \t\treturn FOLLOW_REMOTE_ALWAYS;\n-\twarning(_(\"unrecognized fetch.followRemoteHEAD value '%s' ignored\"), setting);\n+\twarning(_(\"unrecognized %s value '%s' ignored\"), key, setting);\n \treturn BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n }\n \n@@ -1760,12 +1772,11 @@ static void warn_set_head(const char *remote, const char *head_name,\n }\n \n static int set_head(const struct ref *remote_refs, struct remote *remote,\n-\t\t\tint follow_remote_head)\n+\t\t    int follow_remote_head, const char *no_warn_branch)\n {\n \tint result = 0, create_only, baremirror, was_detached;\n \tstruct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,\n \t\t      b_local_head = STRBUF_INIT;\n-\tconst char *no_warn_branch = remote->no_warn_branch;\n \tchar *head_name = NULL;\n \tstruct ref *ref, *matches;\n \tstruct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map;\n@@ -1955,6 +1966,7 @@ static int do_fetch(struct transport *transport,\n \tstruct strmap rejected_refs = STRMAP_INIT;\n \tint summary_width = 0;\n \tint follow_remote_head = FOLLOW_REMOTE_NEVER;\n+\tconst char *no_warn_branch = NULL;\n \n \tif (tags == TAGS_DEFAULT) {\n \t\tif (transport->remote->fetch_tags == 2)\n@@ -1978,16 +1990,19 @@ static int do_fetch(struct transport *transport,\n \t\tif (transport->remote->fetch.nr) {\n \t\t\trefspec_ref_prefixes(&transport->remote->fetch,\n \t\t\t\t\t     &transport_ls_refs_options.ref_prefixes);\n-\t\t\t/*\n-\t\t\t * See remote.c's handling of remote.<name>.followRemoteHEAD\n-\t\t\t * for the analogous, still-unresolved case.\n-\t\t\t */\n-\t\t\tif (transport->remote->follow_remote_head)\n-\t\t\t\tfollow_remote_head = transport->remote->follow_remote_head;\n-\t\t\telse if (config->follow_remote_head_seen)\n-\t\t\t\tfollow_remote_head = get_follow_remote_head(config->follow_remote_head_raw);\n-\t\t\telse\n+\t\t\tif (transport->remote->follow_remote_head_seen) {\n+\t\t\t\tchar *key = xstrfmt(\"remote.%s.followRemoteHEAD\", transport->remote->name);\n+\t\t\t\tfollow_remote_head = get_follow_remote_head(\n+\t\t\t\t\ttransport->remote->follow_remote_head_raw,\n+\t\t\t\t\tkey, &no_warn_branch);\n+\t\t\t\tfree(key);\n+\t\t\t} else if (config->follow_remote_head_seen) {\n+\t\t\t\tfollow_remote_head = get_follow_remote_head(\n+\t\t\t\t\tconfig->follow_remote_head_raw,\n+\t\t\t\t\t\"fetch.followRemoteHEAD\", NULL);\n+\t\t\t} else {\n \t\t\t\tfollow_remote_head = BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n+\t\t\t}\n \t\t}\n \t\tif (branch && branch_has_merge_config(branch) &&\n \t\t    !strcmp(branch->remote_name, transport->remote->name)) {\n@@ -2195,7 +2210,7 @@ static int do_fetch(struct transport *transport,\n \t\t * Way too many cases where this can go wrong so let's just\n \t\t * ignore errors and fail silently for now.\n \t\t */\n-\t\tset_head(remote_refs, transport->remote, follow_remote_head);\n+\t\tset_head(remote_refs, transport->remote, follow_remote_head, no_warn_branch);\n \t}\n \n cleanup:\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex fb7e5b114f..aad92c7dcd 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -1606,7 +1606,8 @@ static int set_head(int argc, const char **argv, const char *prefix,\n \t}\n \tif (opt_a)\n \t\treport_set_head_auto(argv[0], head_name, &b_local_head, was_detached);\n-\tif (remote->follow_remote_head == FOLLOW_REMOTE_ALWAYS) {\n+\tif (remote->follow_remote_head_raw &&\n+\t    !strcmp(remote->follow_remote_head_raw, \"always\")) {\n \t\tstruct strbuf config_name = STRBUF_INIT;\n \t\tstrbuf_addf(&config_name,\n \t\t\t\"remote.%s.followremotehead\", remote->name);\ndiff --git a/remote.c b/remote.c\nindex 49ee2ea318..fa230005ff 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -184,6 +184,7 @@ static void remote_clear(struct remote *remote)\n \tstring_list_clear(&remote->server_options, 0);\n \tstring_list_clear(&remote->negotiation_restrict, 0);\n \tstring_list_clear(&remote->negotiation_include, 0);\n+\tfree(remote->follow_remote_head_raw);\n }\n \n static void add_merge(struct branch *branch, const char *name)\n@@ -581,30 +582,9 @@ static int handle_config(const char *key, const char *value,\n \t\treturn parse_transport_option(key, value,\n \t\t\t\t\t      &remote->negotiation_include);\n \t} else if (!strcmp(subkey, \"followremotehead\")) {\n-\t\tconst char *no_warn_branch;\n-\t\t/*\n-\t\t * NEEDSWORK: this is validated/warned about here, during config\n-\t\t * parsing, regardless of whether the fetch that triggered this\n-\t\t * parse will ever consult it for this particular remote. See\n-\t\t * fetch.c's deferred handling of fetch.followRemoteHEAD for the\n-\t\t * pattern this should likely follow.\n-\t\t */\n-\t\tif (!strcmp(value, \"never\"))\n-\t\t\tremote->follow_remote_head = FOLLOW_REMOTE_NEVER;\n-\t\telse if (!strcmp(value, \"create\"))\n-\t\t\tremote->follow_remote_head = FOLLOW_REMOTE_CREATE;\n-\t\telse if (!strcmp(value, \"warn\")) {\n-\t\t\tremote->follow_remote_head = FOLLOW_REMOTE_WARN;\n-\t\t\tremote->no_warn_branch = NULL;\n-\t\t} else if (skip_prefix(value, \"warn-if-not-\", &no_warn_branch)) {\n-\t\t\tremote->follow_remote_head = FOLLOW_REMOTE_WARN;\n-\t\t\tremote->no_warn_branch = no_warn_branch;\n-\t\t} else if (!strcmp(value, \"always\")) {\n-\t\t\tremote->follow_remote_head = FOLLOW_REMOTE_ALWAYS;\n-\t\t} else {\n-\t\t\twarning(_(\"unrecognized followRemoteHEAD value '%s' ignored\"),\n-\t\t\t\tvalue);\n-\t\t}\n+\t\tfree(remote->follow_remote_head_raw);\n+\t\tremote->follow_remote_head_raw = xstrdup_or_null(value);\n+\t\tremote->follow_remote_head_seen = 1;\n \t}\n \treturn 0;\n }\ndiff --git a/remote.h b/remote.h\nindex cca02033b9..b95f00df2d 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -62,15 +62,6 @@ struct remote_state {\n void remote_state_clear(struct remote_state *remote_state);\n struct remote_state *remote_state_new(void);\n \n-#define BUILTIN_FOLLOW_REMOTE_HEAD_DFLT FOLLOW_REMOTE_CREATE\n-enum follow_remote_head_settings {\n-\tFOLLOW_REMOTE_UNCONFIGURED = 0,\n-\tFOLLOW_REMOTE_NEVER,\n-\tFOLLOW_REMOTE_CREATE,\n-\tFOLLOW_REMOTE_WARN,\n-\tFOLLOW_REMOTE_ALWAYS,\n-};\n-\n struct remote {\n \tstruct hashmap_entry ent;\n \n@@ -122,8 +113,8 @@ struct remote {\n \tstruct string_list negotiation_restrict;\n \tstruct string_list negotiation_include;\n \n-\tenum follow_remote_head_settings follow_remote_head;\n-\tconst char *no_warn_branch;\n+\tchar *follow_remote_head_raw;\n+\tint follow_remote_head_seen;\n };\n \n /**\ndiff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh\nindex 17c0be499c..5b97dced12 100755\n--- a/t/t5510-fetch.sh\n+++ b/t/t5510-fetch.sh\n@@ -290,6 +290,24 @@ test_expect_success \"fetch test followRemoteHEAD warn-if-not-branch branch is di\n \ttest \"z$head\" = \"z$branch\"\n '\n \n+test_expect_success \"fetch test default followRemoteHEAD warn-if-not-branch is not supported\" '\n+\tgit -C two rev-parse --verify refs/remotes/origin/other &&\n+\tgit -C two remote set-head origin other &&\n+\ttest_config -C two fetch.followRemoteHEAD \"warn-if-not-main\" &&\n+\tgit -C two fetch >out 2>err &&\n+\ttest_must_be_empty out &&\n+\ttest_grep \"unrecognized fetch.followRemoteHEAD value ${SQ}warn-if-not-main${SQ} ignored\" err &&\n+\techo refs/remotes/origin/other >expect &&\n+\tgit -C two symbolic-ref refs/remotes/origin/HEAD >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success \"fetch test followRemoteHEAD unrecognized value names the remote\" '\n+   \ttest_config -C two remote.origin.followRemoteHEAD bogus &&\n+   \tgit -C two fetch 2>err &&\n+   \ttest_grep \"unrecognized remote.origin.followRemoteHEAD value ${SQ}bogus${SQ} ignored\" err\n+'\n+\n test_expect_success \"fetch test default followRemoteHEAD always\" '\n \tgit -C two rev-parse --verify refs/remotes/origin/other &&\n \tgit -C two remote set-head origin other &&\n-- \n2.55.0.windows.3\n\n\n"},{"id":"556117","messageId":"xmqq33tw3wol.fsf@gitster.g","threadId":"66581","inReplyTo":"20261023185007.21642-1-colinlewishinton@gmail.com","subject":"Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-23T21:59:38Z","receivedAt":"2026-10-23T21:59:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Colin Hinton <colinlewishinton@gmail.com> writes:\n\n> Continuing from 86129fd (fetch.c: defer fetch.followRemoteHEAD\n> validation), apply the same treatment to\n> remote.<name>.followRemoteHEAD, which is still validated in\n> handle_config(). That emits a warning for any command that loads the\n> remote configuration, such as \"git push\" or \"git remote -v\", even\n> though only \"git fetch\" ever consults the value.\n>\n> Store the raw string in struct remote instead, and resolve it lazily\n> in do_fetch() through the get_follow_remote_head() helper introduced\n> by 86129fd. This replaces the parsed follow_remote_head and\n> no_warn_branch members, and the NEEDSWORK comment left behind by\n> 86129fd is removed. \"git remote set-head\" now compares against the\n> raw string to decide whether to rewrite \"always\" to \"warn\".\n>\n> Moved enum follow_remote_head_settings to builtin/fetch.c as it is no\n> longer referenced in remote.\n>\n> Messages for an unrecognized or missing value name the full variable\n> name prefix, as the helper now serves both the fetch-level and\n> the remote-level setting.\n>\n> Signed-off-by: Colin Hinton <colinlewishinton@gmail.com>\n> ---\n>  Documentation/config/remote.adoc |  4 +--\n>  builtin/fetch.c                  | 45 +++++++++++++++++++++-----------\n>  builtin/remote.c                 |  3 ++-\n>  remote.c                         | 28 +++-----------------\n>  remote.h                         | 13 ++-------\n>  t/t5510-fetch.sh                 | 18 +++++++++++++\n>  6 files changed, 58 insertions(+), 53 deletions(-)\n\nThis looks mostly good, except that I see a few places where the\nindentation is a bit off.\n\n> -static enum follow_remote_head_settings get_follow_remote_head(const char *setting)\n> +static enum follow_remote_head_settings get_follow_remote_head(const char *setting,\n> +    const char *key, const char **no_warn_branch)\n\nPerhaps indent with a tab (instead of four spaces).\n\n>  {\n>  \tif (!setting)\n> -\t\tdie(_(\"missing value for 'fetch.followRemoteHEAD'\"));\n> +\t\tdie(_(\"missing value for '%s'\"), key);\n>  \telse if (!strcmp(setting, \"never\"))\n>  \t\treturn FOLLOW_REMOTE_NEVER;\n>  \telse if (!strcmp(setting, \"create\"))\n>  \t\treturn FOLLOW_REMOTE_CREATE;\n>  \telse if (!strcmp(setting, \"warn\"))\n>  \t\treturn FOLLOW_REMOTE_WARN;\n> +\telse if (no_warn_branch && skip_prefix(setting, \"warn-if-not-\", no_warn_branch))\n> +\t\treturn FOLLOW_REMOTE_WARN;\n>  \telse if (!strcmp(setting, \"always\"))\n>  \t\treturn FOLLOW_REMOTE_ALWAYS;\n> -\twarning(_(\"unrecognized fetch.followRemoteHEAD value '%s' ignored\"), setting);\n> +\twarning(_(\"unrecognized %s value '%s' ignored\"), key, setting);\n>  \treturn BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n>  }\n>  \n> @@ -1760,12 +1772,11 @@ static void warn_set_head(const char *remote, const char *head_name,\n>  }\n>  \n>  static int set_head(const struct ref *remote_refs, struct remote *remote,\n> -\t\t\tint follow_remote_head)\n> +\t\t    int follow_remote_head, const char *no_warn_branch)\n>  {\n>  \tint result = 0, create_only, baremirror, was_detached;\n>  \tstruct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,\n>  \t\t      b_local_head = STRBUF_INIT;\n> -\tconst char *no_warn_branch = remote->no_warn_branch;\n>  \tchar *head_name = NULL;\n>  \tstruct ref *ref, *matches;\n>  \tstruct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map;\n> @@ -1955,6 +1966,7 @@ static int do_fetch(struct transport *transport,\n>  \tstruct strmap rejected_refs = STRMAP_INIT;\n>  \tint summary_width = 0;\n>  \tint follow_remote_head = FOLLOW_REMOTE_NEVER;\n> +\tconst char *no_warn_branch = NULL;\n>  \n>  \tif (tags == TAGS_DEFAULT) {\n>  \t\tif (transport->remote->fetch_tags == 2)\n> @@ -1978,16 +1990,19 @@ static int do_fetch(struct transport *transport,\n>  \t\tif (transport->remote->fetch.nr) {\n>  \t\t\trefspec_ref_prefixes(&transport->remote->fetch,\n>  \t\t\t\t\t     &transport_ls_refs_options.ref_prefixes);\n> -\t\t\t/*\n> -\t\t\t * See remote.c's handling of remote.<name>.followRemoteHEAD\n> -\t\t\t * for the analogous, still-unresolved case.\n> -\t\t\t */\n> -\t\t\tif (transport->remote->follow_remote_head)\n> -\t\t\t\tfollow_remote_head = transport->remote->follow_remote_head;\n> -\t\t\telse if (config->follow_remote_head_seen)\n> -\t\t\t\tfollow_remote_head = get_follow_remote_head(config->follow_remote_head_raw);\n> -\t\t\telse\n> +\t\t\tif (transport->remote->follow_remote_head_seen) {\n> +\t\t\t\tchar *key = xstrfmt(\"remote.%s.followRemoteHEAD\", transport->remote->name);\n\nThis line is +l00 columns of long.  Line wrap?\n\n> +test_expect_success \"fetch test followRemoteHEAD unrecognized value names the remote\" '\n> +   \ttest_config -C two remote.origin.followRemoteHEAD bogus &&\n> +   \tgit -C two fetch 2>err &&\n> +   \ttest_grep \"unrecognized remote.origin.followRemoteHEAD value ${SQ}bogus${SQ} ignored\" err\n> +'\n\nThese lines have space-before-tab whitespace errors.\n\n>  test_expect_success \"fetch test default followRemoteHEAD always\" '\n>  \tgit -C two rev-parse --verify refs/remotes/origin/other &&\n>  \tgit -C two remote set-head origin other &&\n\n"},{"id":"556145","messageId":"DMCYNNPMFVMA.S74D9Y3OQ9QE@lfurio.us","threadId":"66581","inReplyTo":"20261023185007.21642-1-colinlewishinton@gmail.com","subject":"Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Matt Hunter","fromEmail":"m@lfurio.us","sentAt":"2026-10-24T09:28:46Z","receivedAt":"2026-10-24T09:28:46Z","isPatch":true,"sender":{"key":"m@lfurio.us","avatar":"https://avatars.githubusercontent.com/u/14925125?v=4"},"body":"On Fri Oct 23, 2026 at 2:50 PM EDT, Colin Hinton wrote:\n> Continuing from 86129fd (fetch.c: defer fetch.followRemoteHEAD\n> validation), apply the same treatment to\n> remote.<name>.followRemoteHEAD, which is still validated in\n> handle_config(). That emits a warning for any command that loads the\n> remote configuration, such as \"git push\" or \"git remote -v\", even\n> though only \"git fetch\" ever consults the value.\n>\n> Store the raw string in struct remote instead, and resolve it lazily\n> in do_fetch() through the get_follow_remote_head() helper introduced\n> by 86129fd. This replaces the parsed follow_remote_head and\n> no_warn_branch members, and the NEEDSWORK comment left behind by\n> 86129fd is removed. \"git remote set-head\" now compares against the\n> raw string to decide whether to rewrite \"always\" to \"warn\".\n>\n> Moved enum follow_remote_head_settings to builtin/fetch.c as it is no\n> longer referenced in remote.\n>\n> Messages for an unrecognized or missing value name the full variable\n> name prefix, as the helper now serves both the fetch-level and\n> the remote-level setting.\n>\n> Signed-off-by: Colin Hinton <colinlewishinton@gmail.com>\n> ---\n>  Documentation/config/remote.adoc |  4 +--\n>  builtin/fetch.c                  | 45 +++++++++++++++++++++-----------\n>  builtin/remote.c                 |  3 ++-\n>  remote.c                         | 28 +++-----------------\n>  remote.h                         | 13 ++-------\n>  t/t5510-fetch.sh                 | 18 +++++++++++++\n>  6 files changed, 58 insertions(+), 53 deletions(-)\n\nBesides Junio's whitespace notes, I have no additional comments.  Looks\ngood.\n\nThanks\n\n"},{"id":"556175","messageId":"xmqqwlr7yrj5.fsf@gitster.g","threadId":"66581","inReplyTo":"DMCYNNPMFVMA.S74D9Y3OQ9QE@lfurio.us","subject":"Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-24T16:47:26Z","receivedAt":"2026-10-24T16:47:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Matt Hunter\" <m@lfurio.us> writes:\n\n> Besides Junio's whitespace notes, I have no additional comments.  Looks\n> good.\n\nThanks, Matt, for an extra set of eyes.\n\nThis however has some textual conflict with Harald's work to limit\nthe set of branches to fetch with refmap which keeps this topic out\nof 'seen'.  If the hn/fetch-refmap topic is solid enough, it might\nmake sense to wait for it to hit 'next', and then rebase this patch\non top of the result of merging the hn/fetch-refmap topic into\n'master', to avoid mismerges.\n\n\n\n"},{"id":"556196","messageId":"xmqqecdezfr1.fsf@gitster.g","threadId":"66581","inReplyTo":"20261023185007.21642-1-colinlewishinton@gmail.com","subject":"Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-25T02:16:34Z","receivedAt":"2026-10-25T02:16:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Colin Hinton <colinlewishinton@gmail.com> writes:\n\nOne more thing.\n\n> @@ -1978,16 +1990,19 @@ static int do_fetch(struct transport *transport,\n>  \t\tif (transport->remote->fetch.nr) {\n>  \t\t\trefspec_ref_prefixes(&transport->remote->fetch,\n>  \t\t\t\t\t     &transport_ls_refs_options.ref_prefixes);\n> -\t\t\t/*\n> -\t\t\t * See remote.c's handling of remote.<name>.followRemoteHEAD\n> -\t\t\t * for the analogous, still-unresolved case.\n> -\t\t\t */\n> -\t\t\tif (transport->remote->follow_remote_head)\n> -\t\t\t\tfollow_remote_head = transport->remote->follow_remote_head;\n> -\t\t\telse if (config->follow_remote_head_seen)\n> -\t\t\t\tfollow_remote_head = get_follow_remote_head(config->follow_remote_head_raw);\n> -\t\t\telse\n> +\t\t\tif (transport->remote->follow_remote_head_seen) {\n> +\t\t\t\tchar *key = xstrfmt(\"remote.%s.followRemoteHEAD\", transport->remote->name);\n> +\t\t\t\tfollow_remote_head = get_follow_remote_head(\n> +\t\t\t\t\ttransport->remote->follow_remote_head_raw,\n> +\t\t\t\t\tkey, &no_warn_branch);\n> +\t\t\t\tfree(key);\n> +\t\t\t} else if (config->follow_remote_head_seen) {\n> +\t\t\t\tfollow_remote_head = get_follow_remote_head(\n> +\t\t\t\t\tconfig->follow_remote_head_raw,\n> +\t\t\t\t\t\"fetch.followRemoteHEAD\", NULL);\n> +\t\t\t} else {\n>  \t\t\t\tfollow_remote_head = BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n> +\t\t\t}\n>  \t\t}\n\nThis part of the code becomes overly deeply indented, and more\nimportantly, the outer conditional around here has been reworked by\nanother topic and the code that learns follow_remote_head will have\nto be reused elsewhere, which would lead to a nasty merge conflict.\n\nI'd like to see this part refactored into a separate helper\nfunction, by squashing something like this on top of this patch.\n\nThanks.\n\n builtin/fetch.c | 38 +++++++++++++++++++++++++-------------\n 1 file changed, 25 insertions(+), 13 deletions(-)\n\ndiff --git c/builtin/fetch.c w/builtin/fetch.c\nindex bb59e70865..77e3276cc4 100644\n--- c/builtin/fetch.c\n+++ w/builtin/fetch.c\n@@ -1946,6 +1946,28 @@ static void collect_updated_tips(struct oidset *tips, struct ref *ref_map)\n \t}\n }\n \n+static int lazy_follow_remote_head(const struct transport *transport,\n+\t\t\t\t   const struct fetch_config *config,\n+\t\t\t\t   const char **no_warn_branch)\n+{\n+\tint ret = BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n+\n+\tif (transport->remote->follow_remote_head_seen) {\n+\t\tchar *key = xstrfmt(\"remote.%s.followRemoteHEAD\",\n+\t\t\t\t    transport->remote->name);\n+\t\tret = get_follow_remote_head(\n+\t\t\ttransport->remote->follow_remote_head_raw,\n+\t\t\tkey, no_warn_branch);\n+\t\tfree(key);\n+\t} else if (config->follow_remote_head_seen) {\n+\t\tret = get_follow_remote_head(\n+\t\t\tconfig->follow_remote_head_raw,\n+\t\t\t\"fetch.followRemoteHEAD\", NULL);\n+\t}\n+\n+\treturn ret;\n+}\n+\n static int do_fetch(struct transport *transport,\n \t\t    struct refspec *rs,\n \t\t    const struct fetch_config *config,\n@@ -1990,19 +2012,9 @@ static int do_fetch(struct transport *transport,\n \t\tif (transport->remote->fetch.nr) {\n \t\t\trefspec_ref_prefixes(&transport->remote->fetch,\n \t\t\t\t\t     &transport_ls_refs_options.ref_prefixes);\n-\t\t\tif (transport->remote->follow_remote_head_seen) {\n-\t\t\t\tchar *key = xstrfmt(\"remote.%s.followRemoteHEAD\", transport->remote->name);\n-\t\t\t\tfollow_remote_head = get_follow_remote_head(\n-\t\t\t\t\ttransport->remote->follow_remote_head_raw,\n-\t\t\t\t\tkey, &no_warn_branch);\n-\t\t\t\tfree(key);\n-\t\t\t} else if (config->follow_remote_head_seen) {\n-\t\t\t\tfollow_remote_head = get_follow_remote_head(\n-\t\t\t\t\tconfig->follow_remote_head_raw,\n-\t\t\t\t\t\"fetch.followRemoteHEAD\", NULL);\n-\t\t\t} else {\n-\t\t\t\tfollow_remote_head = BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n-\t\t\t}\n+\t\t\tfollow_remote_head =\n+\t\t\t\tlazy_follow_remote_head(transport, config,\n+\t\t\t\t\t\t\t&no_warn_branch);\n \t\t}\n \t\tif (branch && branch_has_merge_config(branch) &&\n \t\t    !strcmp(branch->remote_name, transport->remote->name)) {\n\n\n\n\n\n"},{"id":"556598","messageId":"CAHeTm9NOqLA=BfTU9ABDFt8+jOzaRDPRrMNP8thzAQN2NVZAew@mail.gmail.com","threadId":"66581","inReplyTo":"xmqqecdezfr1.fsf@gitster.g","subject":"Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Colin Hinton","fromEmail":"colinlewishinton@gmail.com","sentAt":"2026-10-28T02:56:33Z","receivedAt":"2026-10-28T02:56:33Z","isPatch":true,"sender":{"key":"colinlewishinton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128193236?v=4"},"body":"> This part of the code becomes overly deeply indented, and more\n> importantly, the outer conditional around here has been reworked by\n> another topic and the code that learns follow_remote_head will have\n> to be reused elsewhere, which would lead to a nasty merge conflict.\n>\n> I'd like to see this part refactored into a separate helper\n> function, by squashing something like this on top of this patch.\n>\n> Thanks.\n\nOkay, I will refactor this into a helper method since yes the\nintending is becoming too much, I will also keep my eye on the patch\nyou previously mentioned, and post a new version once Next has been\nupdated from Harald's work so I can rebase with their fixes. Thanks\nfor the feedback.\n\n-Colin Hinton\n\n"},{"id":"556666","messageId":"xmqqmrrxdhox.fsf@gitster.g","threadId":"66581","inReplyTo":"CAHeTm9NOqLA=BfTU9ABDFt8+jOzaRDPRrMNP8thzAQN2NVZAew@mail.gmail.com","subject":"Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-28T14:26:54Z","receivedAt":"2026-10-28T14:26:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Colin Hinton <colinlewishinton@gmail.com> writes:\n\n>> This part of the code becomes overly deeply indented, and more\n>> importantly, the outer conditional around here has been reworked by\n>> another topic and the code that learns follow_remote_head will have\n>> to be reused elsewhere, which would lead to a nasty merge conflict.\n>>\n>> I'd like to see this part refactored into a separate helper\n>> function, by squashing something like this on top of this patch.\n>>\n>> Thanks.\n>\n> Okay, I will refactor this into a helper method since yes the\n> intending is becoming too much, I will also keep my eye on the patch\n> you previously mentioned, and post a new version once Next has been\n> updated from Harald's work so I can rebase with their fixes. Thanks\n> for the feedback.\n>\n> -Colin Hinton\n\nThe 'ch/remote-defer-follow-remote-head-validation' branch at\nhttps://github.com/gitster/git/ has a change on top that you can use\nas a reference.  If you are going to make this a two-patch series, it\nmay make sense to first extract the code commented with \"See\nremote.c's handling of ...\" into a helper function, and then extend\nit to cover the lazy behavior in the second patch.  When viewed\nthat way, the helper function should not be named with a 'lazy_'\nprefix as I mistakenly did.  Being lazy is not its purpose.  Its\npoint is to determine which setting of followRemoteHEAD is to be\nused, and the helper function should be named after that concept.\n\nThanks.\n\n"},{"id":"556856","messageId":"DMHZCS9LOW3N.ZJ3947HUCXZ8@lfurio.us","threadId":"66581","inReplyTo":"xmqqmrrxdhox.fsf@gitster.g","subject":"Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Matt Hunter","fromEmail":"m@lfurio.us","sentAt":"2026-10-30T07:04:55Z","receivedAt":"2026-10-30T07:04:55Z","isPatch":true,"sender":{"key":"m@lfurio.us","avatar":"https://avatars.githubusercontent.com/u/14925125?v=4"},"body":"On Wed Oct 28, 2026 at 10:26 AM EDT, Junio C Hamano wrote:\n>\n>>> This part of the code becomes overly deeply indented, and more\n>>> importantly, the outer conditional around here has been reworked by\n>>> another topic and the code that learns follow_remote_head will have\n>>> to be reused elsewhere, which would lead to a nasty merge conflict.\n>>>\n>>> I'd like to see this part refactored into a separate helper\n>>> function, by squashing something like this on top of this patch.\n>>>\n> [...]\n>\n> The 'ch/remote-defer-follow-remote-head-validation' branch at\n> https://github.com/gitster/git/ has a change on top that you can use\n> as a reference.  If you are going to make this a two-patch series, it\n> may make sense to first extract the code commented with \"See\n> remote.c's handling of ...\" into a helper function, and then extend\n> it to cover the lazy behavior in the second patch.  When viewed\n> that way, the helper function should not be named with a 'lazy_'\n> prefix as I mistakenly did.  Being lazy is not its purpose.  Its\n> point is to determine which setting of followRemoteHEAD is to be\n> used, and the helper function should be named after that concept.\n\nI wonder if it makes sense to incorporate such a new helper function\ninto the existing 'get_follow_remote_head()', since it would be the only\nplace using it.\n\n"},{"id":"556923","messageId":"xmqq33tnz0hb.fsf@gitster.g","threadId":"66581","inReplyTo":"DMHZCS9LOW3N.ZJ3947HUCXZ8@lfurio.us","subject":"Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-30T15:12:16Z","receivedAt":"2026-10-30T15:12:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Matt Hunter\" <m@lfurio.us> writes:\n\n> On Wed Oct 28, 2026 at 10:26 AM EDT, Junio C Hamano wrote:\n>>\n>>>> This part of the code becomes overly deeply indented, and more\n>>>> importantly, the outer conditional around here has been reworked by\n>>>> another topic and the code that learns follow_remote_head will have\n>>>> to be reused elsewhere, which would lead to a nasty merge conflict.\n> ...\n> I wonder if it makes sense to incorporate such a new helper function\n> into the existing 'get_follow_remote_head()', since it would be the only\n> place using it.\n\nI am not sure what being the only place has to do with avoiding to\nsplit a helper function out to clarify the main logic flow, though.\nAnd simultaneously, another topic wants to have this piece of logic\ntwice.\n\n\n"},{"id":"557049","messageId":"DMJFKJCI5DLL.12R7AMFO4DK2Y@lfurio.us","threadId":"66581","inReplyTo":"xmqq33tnz0hb.fsf@gitster.g","subject":"Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Matt Hunter","fromEmail":"m@lfurio.us","sentAt":"2026-11-01T00:00:00Z","receivedAt":"2026-11-01T00:00:00Z","isPatch":true,"sender":{"key":"m@lfurio.us","avatar":"https://avatars.githubusercontent.com/u/14925125?v=4"},"body":"On Fri Oct 30, 2026 at 11:12 AM EDT, Junio C Hamano wrote:\n> \"Matt Hunter\" <m@lfurio.us> writes:\n>> ...\n>> I wonder if it makes sense to incorporate such a new helper function\n>> into the existing 'get_follow_remote_head()', since it would be the only\n>> place using it.\n>\n> I am not sure what being the only place has to do with avoiding to\n> split a helper function out to clarify the main logic flow, though.\n> And simultaneously, another topic wants to have this piece of logic\n> twice.\n\nI should explain myself better.  I don't mean Colin should avoid\nsplitting out logic from the main flow in do_fetch.  But the end result\ncan be reached without introducing a new function.  I find needing to\nhold fewer functions in my head makes the code easier to reason about,\nthough that is a subjective point.\n\nThe idea in my head is below and is\nSigned-off-by: Matt Hunter <m@lfurio.us>\nFeel free to run with this or not.\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex bb59e70865ff..844ff5105f91 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -196,23 +196,44 @@ static int git_fetch_config(const char *k, const char *v,\n \treturn git_default_config(k, v, ctx, cb);\n }\n \n-static enum follow_remote_head_settings get_follow_remote_head(const char *setting,\n-    const char *key, const char **no_warn_branch)\n+static enum follow_remote_head_settings get_follow_remote_head(\n+\t\tconst struct transport *transport, const struct fetch_config *config,\n+\t\tconst char **no_warn_branch)\n {\n-\tif (!setting)\n-\t\tdie(_(\"missing value for '%s'\"), key);\n-\telse if (!strcmp(setting, \"never\"))\n-\t\treturn FOLLOW_REMOTE_NEVER;\n-\telse if (!strcmp(setting, \"create\"))\n-\t\treturn FOLLOW_REMOTE_CREATE;\n-\telse if (!strcmp(setting, \"warn\"))\n-\t\treturn FOLLOW_REMOTE_WARN;\n-\telse if (no_warn_branch && skip_prefix(setting, \"warn-if-not-\", no_warn_branch))\n-\t\treturn FOLLOW_REMOTE_WARN;\n-\telse if (!strcmp(setting, \"always\"))\n-\t\treturn FOLLOW_REMOTE_ALWAYS;\n-\twarning(_(\"unrecognized %s value '%s' ignored\"), key, setting);\n-\treturn BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n+\tint ret = BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n+\tchar *key = NULL;\n+\tconst char *setting = NULL;\n+\n+\tif (transport->remote->follow_remote_head_seen) {\n+\t\tkey = xstrfmt(\"remote.%s.followRemoteHEAD\", transport->remote->name);\n+\t\tsetting = transport->remote->follow_remote_head_raw;\n+\t} else if (config->follow_remote_head_seen) {\n+\t\tkey = xstrdup(\"fetch.followRemoteHEAD\");\n+\t\tsetting = config->follow_remote_head_raw;\n+\t\tno_warn_branch = NULL;\n+\t}\n+\n+\tif (key) {\n+\t\tif (!setting)\n+\t\t\tdie(_(\"missing value for '%s'\"), key);\n+\t\telse if (!strcmp(setting, \"never\"))\n+\t\t\tret = FOLLOW_REMOTE_NEVER;\n+\t\telse if (!strcmp(setting, \"create\"))\n+\t\t\tret = FOLLOW_REMOTE_CREATE;\n+\t\telse if (!strcmp(setting, \"warn\"))\n+\t\t\tret = FOLLOW_REMOTE_WARN;\n+\t\telse if (no_warn_branch &&\n+\t\t\t\tskip_prefix(setting, \"warn-if-not-\", no_warn_branch))\n+\t\t\tret = FOLLOW_REMOTE_WARN;\n+\t\telse if (!strcmp(setting, \"always\"))\n+\t\t\tret = FOLLOW_REMOTE_ALWAYS;\n+\t\telse\n+\t\t\twarning(_(\"unrecognized %s value '%s' ignored\"), key, setting);\n+\n+\t\tfree(key);\n+\t}\n+\n+\treturn ret;\n }\n \n static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)\n@@ -1990,19 +2011,9 @@ static int do_fetch(struct transport *transport,\n \t\tif (transport->remote->fetch.nr) {\n \t\t\trefspec_ref_prefixes(&transport->remote->fetch,\n \t\t\t\t\t     &transport_ls_refs_options.ref_prefixes);\n-\t\t\tif (transport->remote->follow_remote_head_seen) {\n-\t\t\t\tchar *key = xstrfmt(\"remote.%s.followRemoteHEAD\", transport->remote->name);\n-\t\t\t\tfollow_remote_head = get_follow_remote_head(\n-\t\t\t\t\ttransport->remote->follow_remote_head_raw,\n-\t\t\t\t\tkey, &no_warn_branch);\n-\t\t\t\tfree(key);\n-\t\t\t} else if (config->follow_remote_head_seen) {\n-\t\t\t\tfollow_remote_head = get_follow_remote_head(\n-\t\t\t\t\tconfig->follow_remote_head_raw,\n-\t\t\t\t\t\"fetch.followRemoteHEAD\", NULL);\n-\t\t\t} else {\n-\t\t\t\tfollow_remote_head = BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;\n-\t\t\t}\n+\t\t\tfollow_remote_head =\n+\t\t\t\tget_follow_remote_head(transport, config,\n+\t\t\t\t\t\t&no_warn_branch);\n \t\t}\n \t\tif (branch && branch_has_merge_config(branch) &&\n \t\t    !strcmp(branch->remote_name, transport->remote->name)) {\n\n\nAdmittedly, I haven't been following Harald's hn/fetch-refmap topic\nclosely, but am more familiar with the affected areas now.\n\n"},{"id":"557643","messageId":"xmqqjymqobc3.fsf@gitster.g","threadId":"66581","inReplyTo":"DMJFKJCI5DLL.12R7AMFO4DK2Y@lfurio.us","subject":"Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-06T04:03:40Z","receivedAt":"2026-11-06T04:03:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Matt Hunter\" <m@lfurio.us> writes:\n\n> I should explain myself better.  I don't mean Colin should avoid\n> splitting out logic from the main flow in do_fetch.  But the end result\n> can be reached without introducing a new function.  I find needing to\n> hold fewer functions in my head makes the code easier to reason about,\n> though that is a subjective point.\n>\n> The idea in my head is below and is\n> Signed-off-by: Matt Hunter <m@lfurio.us>\n> Feel free to run with this or not.\n\nHmph, interesting.  Can you rewrite Colin's patch using this, and\nthen merge the result into 'seen' (after reverting Colin's topic\nch/remote-defer-follow-remote-head-validation from 'seen' first) to\nsee how badly it crashes with other topics in flight?\n\nThanks.\n\n\n\n\n"},{"id":"557647","messageId":"DMO0XC1PL4MP.1J5830XZ4GCS5@lfurio.us","threadId":"66581","inReplyTo":"xmqqjymqobc3.fsf@gitster.g","subject":"Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Matt Hunter","fromEmail":"m@lfurio.us","sentAt":"2026-11-06T09:34:46Z","receivedAt":"2026-11-06T09:34:46Z","isPatch":true,"sender":{"key":"m@lfurio.us","avatar":"https://avatars.githubusercontent.com/u/14925125?v=4"},"body":"On Thu Nov 5, 2026 at 11:03 PM EST, Junio C Hamano wrote:\n>\n> Hmph, interesting.  Can you rewrite Colin's patch using this, and\n> then merge the result into 'seen' (after reverting Colin's topic\n> ch/remote-defer-follow-remote-head-validation from 'seen' first) to\n> see how badly it crashes with other topics in flight?\n\nI still have the commit sitting around.  I tried this and a replay of\nthe current topic to compare -- the conflict is the same in both\ncases.  eg: Nothing else in flight is touching the\nget_follow_remote_head() function.\n\n\nstatic int do_fetch(struct transport *transport,\n\t\t    struct refspec *rs,\n\t\t    const struct fetch_config *config,\n\t\t    struct list_objects_filter_options *filter_options,\n\t\t    struct oidset *updated_tips)\n{\n\tstruct ref_transaction *transaction = NULL;\n\tstruct ref *ref_map = NULL;\n\tstruct display_state display_state = { 0 };\n\tint autotags = (transport->remote->fetch_tags == 1);\n\tint retcode = 0;\n\tconst struct ref *remote_refs;\n\tstruct transport_ls_refs_options transport_ls_refs_options =\n\t\tTRANSPORT_LS_REFS_OPTIONS_INIT;\n\tstruct fetch_head fetch_head = { 0 };\n\tstruct strbuf err = STRBUF_INIT;\n\tstruct ref_update_display_info_array display_array = { 0 };\n\tstruct strmap rejected_refs = STRMAP_INIT;\n\tint summary_width = 0;\n\tint follow_remote_head = FOLLOW_REMOTE_NEVER;\n<<<<<<< HEAD\n\tbool apply_follow_remote_head_config = false;\n=======\n\tconst char *no_warn_branch = NULL;\n>>>>>>> try-merge\n\n\tif (tags == TAGS_DEFAULT) {\n\t\tif (transport->remote->fetch_tags == 2)\n\t\t\ttags = TAGS_SET;\n\t\tif (transport->remote->fetch_tags == -1)\n\t\t\ttags = TAGS_UNSET;\n\t}\n\n\t/* if not appending, truncate FETCH_HEAD */\n\tif (!append && write_fetch_head) {\n\t\tretcode = truncate_fetch_head();\n\t\tif (retcode)\n\t\t\tgoto cleanup;\n\t}\n\n\tif (rs->nr) {\n\t\trefspec_ref_prefixes(rs, &transport_ls_refs_options.ref_prefixes);\n\t} else if (transport->remote->fetch.nr) {\n\t\trefspec_ref_prefixes(&transport->remote->fetch,\n\t\t\t\t     &transport_ls_refs_options.ref_prefixes);\n\t\tapply_follow_remote_head_config = true;\n\n<<<<<<< HEAD\n\t\t/*\n\t\t * The configured refspec may not cover the current\n\t\t * branch's upstream (e.g. a narrowed -t refspec), so\n\t\t * make sure we can still fetch it regardless.\n\t\t */\n\t\tcollect_upstream_from_remote(the_repository, transport->remote,\n\t\t\t\t\t      NULL, &transport_ls_refs_options.ref_prefixes);\n\t} else {\n\t\t/*\n\t\t * The --refmap command line option, if given, takes\n\t\t * precedence over remote.<name>.fetchRefmap.\n\t\t */\n\t\tstruct refspec *effective_refmap = refmap.nr ? &refmap :\n\t\t\t&transport->remote->refmap;\n\n\t\tif (effective_refmap->nr) {\n\t\t\tbranches_tracking_remote(the_repository, transport->remote,\n\t\t\t\t\t\t  &transport_ls_refs_options.ref_prefixes);\n\t\t\tapply_follow_remote_head_config = true;\n\t\t} else {\n\t\t\tcollect_upstream_from_remote(the_repository, transport->remote,\n\t\t\t\t\t\t      NULL, &transport_ls_refs_options.ref_prefixes);\n=======\n\t\tif (transport->remote->fetch.nr) {\n\t\t\trefspec_ref_prefixes(&transport->remote->fetch,\n\t\t\t\t\t     &transport_ls_refs_options.ref_prefixes);\n\t\t\tfollow_remote_head =\n\t\t\t\tget_follow_remote_head(transport, config,\n\t\t\t\t\t\t&no_warn_branch);\n\t\t}\n\t\tif (branch && branch_has_merge_config(branch) &&\n\t\t    !strcmp(branch->remote_name, transport->remote->name)) {\n\t\t\tint i;\n\t\t\tfor (i = 0; i < branch->merge_nr; i++) {\n\t\t\t\tstrvec_push(&transport_ls_refs_options.ref_prefixes,\n\t\t\t\t\t    branch->merge[i]->src);\n\t\t\t}\n>>>>>>> try-merge\n\t\t}\n\n\t\t/*\n\t\t * If there are no refs specified to fetch, then we just\n\t\t * fetch HEAD; mention that to narrow the advertisement.\n\t\t */\n\t\tif (!transport_ls_refs_options.ref_prefixes.nr)\n\t\t\tstrvec_push(&transport_ls_refs_options.ref_prefixes,\n\t\t\t\t    \"HEAD\");\n\t}\n\n"},{"id":"557708","messageId":"xmqq1p8ylywh.fsf@gitster.g","threadId":"66581","inReplyTo":"DMO0XC1PL4MP.1J5830XZ4GCS5@lfurio.us","subject":"Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-06T16:15:10Z","receivedAt":"2026-11-06T16:15:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Matt Hunter\" <m@lfurio.us> writes:\n\n> On Thu Nov 5, 2026 at 11:03 PM EST, Junio C Hamano wrote:\n>>\n>> Hmph, interesting.  Can you rewrite Colin's patch using this, and\n>> then merge the result into 'seen' (after reverting Colin's topic\n>> ch/remote-defer-follow-remote-head-validation from 'seen' first) to\n>> see how badly it crashes with other topics in flight?\n>\n> I still have the commit sitting around.  I tried this and a replay of\n> the current topic to compare -- the conflict is the same in both\n> cases.  eg: Nothing else in flight is touching the\n> get_follow_remote_head() function.\n\nThanks for investigating.  \n\nYour approach of passing more context into get_follow_remote_head()\nand have _it_ do the (lazy) conversion from string to value makes it\nmuch easier for callers to make calls from multiple branches to the\nfunction, because the need to \"set-up\" to make the call disappears.\n\nVery cleanly done.\n\nColin, what's your preference?  Can we move this topic past the\nfinish line?\n\nThanks.\n\n"},{"id":"557862","messageId":"CAHeTm9M5maWM=yrJPNzCibv_rewH3-yBK8J5-MDyDvPzfihe4A@mail.gmail.com","threadId":"66581","inReplyTo":"xmqq1p8ylywh.fsf@gitster.g","subject":"Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation","fromName":"Colin Hinton","fromEmail":"colinlewishinton@gmail.com","sentAt":"2026-11-08T21:45:16Z","receivedAt":"2026-11-08T21:45:16Z","isPatch":true,"sender":{"key":"colinlewishinton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128193236?v=4"},"body":"I prefer Matt's approach as I agree it's cleaner and simpler by\nremoving the setup at the call site. I'll adopt it into my next\nversion and will give credit to Matt for his contribution.\n\nI am still holding on to the re-roll until hn/fetch-refmap is accepted\ninto 'next', so that I can rebase and resolve any conflicts myself.\nJunio, if you think there is a better branch for me to base this off\nof so that I can begin the conflict resolution now please let me know.\n\n-Colin Hinton\n\nOn Fri, Nov 6, 2026 at 8:15 AM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> \"Matt Hunter\" <m@lfurio.us> writes:\n>\n> > On Thu Nov 5, 2026 at 11:03 PM EST, Junio C Hamano wrote:\n> >>\n> >> Hmph, interesting.  Can you rewrite Colin's patch using this, and\n> >> then merge the result into 'seen' (after reverting Colin's topic\n> >> ch/remote-defer-follow-remote-head-validation from 'seen' first) to\n> >> see how badly it crashes with other topics in flight?\n> >\n> > I still have the commit sitting around.  I tried this and a replay of\n> > the current topic to compare -- the conflict is the same in both\n> > cases.  eg: Nothing else in flight is touching the\n> > get_follow_remote_head() function.\n>\n> Thanks for investigating.\n>\n> Your approach of passing more context into get_follow_remote_head()\n> and have _it_ do the (lazy) conversion from string to value makes it\n> much easier for callers to make calls from multiple branches to the\n> function, because the need to \"set-up\" to make the call disappears.\n>\n> Very cleanly done.\n>\n> Colin, what's your preference?  Can we move this topic past the\n> finish line?\n>\n> Thanks.\n\n"}]}