Subject: Re: [PATCH 2/2] config: fix evaluating "onbranch" with nonexistent git dir

From: Junio C Hamano <[email-masked]>
Date: Tue, 24 Sep 2024 09:17:45 -0700

Patrick Steinhardt <[email-masked]> writes:

> As the quoted comment mentions, we'd ideally refactor the code to not
> set up `gitdir` with an invalid value in the first place, but that may
> be a bigger undertaking. Instead, refactor the code to use the ref
> storage format as an indicator of whether or not the ref store has been
> set up to fix the bug.
>
> Reported-by: Ronan Pigott <[email-masked]>
> Signed-off-by: Patrick Steinhardt <[email-masked]>
> ---
> ...
> -	const char *refname = (!data->repo || !data->repo->gitdir) ?
> -		NULL : refs_resolve_ref_unsafe(get_main_ref_store(data->repo),
> -					       "HEAD", 0, NULL, &flags);
> -	const char *shortname;
> +	const char *refname, *shortname;
>  
> -	if (!refname || !(flags & REF_ISSYMREF)	||
> -			!skip_prefix(refname, "refs/heads/", &shortname))
> +	if (!data->repo || data->repo->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
> +		return 0;

OK.  A very direct check to see what we really care about.