Re: [PATCH v2] fetch.c: defer fetch.followRemoteHEAD validation
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 25, 2026, 19:40 UTC
- Message-ID
- <xmqqo6dlt906.fsf@gitster.g>
- In-Reply-To
- <20260925192658.1166-1-colinlewishinton@gmail.com>
Colin Hinton <colinlewishinton@gmail.com> writes:
Show 25 quoted lines
> struct fetch_config {
> enum display_format display_format;
> - enum follow_remote_head_settings follow_remote_head;
> + char *follow_remote_head_raw;
> int all;
> int prune;
> int prune_tags;
> @@ -176,24 +176,31 @@ static int git_fetch_config(const char *k, const char *v,
> }
>
> if (!strcmp(k, "fetch.followremotehead")) {
> - if (!v)
> - return config_error_nonbool(k);
> - else if (!strcmp(v, "never"))
> - fetch_config->follow_remote_head = FOLLOW_REMOTE_NEVER;
> - else if (!strcmp(v, "create"))
> - fetch_config->follow_remote_head = FOLLOW_REMOTE_CREATE;
> - else if (!strcmp(v, "warn"))
> - fetch_config->follow_remote_head = FOLLOW_REMOTE_WARN;
> - else if (!strcmp(v, "always"))
> - fetch_config->follow_remote_head = FOLLOW_REMOTE_ALWAYS;
> - else
> - warning(_("unrecognized fetch.followRemoteHEAD value '%s' ignored"), v);
> + free(fetch_config->follow_remote_head_raw);
> + fetch_config->follow_remote_head_raw = xstrdup(v);This will segfault when !v, so
fetch_config->follow_remote_head_raw = xstrdup_or_null(v);
With that change,
Show 15 quoted lines
> +static enum follow_remote_head_settings get_follow_remote_head(const char *setting)
> +{
> + if (!setting)
> + die(_("missing value for 'fetch.followRemoteHEAD'"));
> + else if (!strcmp(setting, "never"))
> + return FOLLOW_REMOTE_NEVER;
> + else if (!strcmp(setting, "create"))
> + return FOLLOW_REMOTE_CREATE;
> + else if (!strcmp(setting, "warn"))
> + return FOLLOW_REMOTE_WARN;
> + else if (!strcmp(setting, "always"))
> + return FOLLOW_REMOTE_ALWAYS;
> + warning(_("unrecognized fetch.followRemoteHEAD value '%s' ignored"), setting);
> + return FOLLOW_REMOTE_UNCONFIGURED;
> +}This would do a reasonable job.
We should do something similar to what remote.c parses for consistency, but other than that, it seems this topic is moving in the right direction.
Thanks.