Subject: Re: Re* [PATCH] Fix `git fetch --tags` in repo with no configured remote

From: Junio C Hamano <[email-masked]>
Date: Fri, 06 Dec 2024 20:30:39 +0900

Junio C Hamano <[email-masked]> writes:

> +static int uses_remote_tracking(struct transport *transport, struct refspec *rs)
> +{
> +	if (!remote_is_configured(transport->remote, 0))
> +		return 0;
> +
> +	if (!rs->nr)
> +		rs = &transport->remote->fetch;
> +
> +	for (int i = 0; i < rs->nr; i++)
> +		if (rs->items[i].dst)
> +			return 1;
> +
> +	return 0;
> +}

For the purpose of adjusting refs/remotes/<name>/HEAD, which is
expected to point at something that we copy from their refs/heads/,
it may be tempting to tighten the above logic to say, instead of "we
have a refspec item that stores to somewhere", do something like

	for (int i = 0; i < rs->nr; i++) {
		struct refspec_item *item = &rs->items[i];

		if (item->dst &&
		    item->src && starts_with(item->src, "refs/heads/"))
			return 1;
	}

to make sure that we are tracking their branch refs, not some random
hierarchy for which refs/remotes/<name>/HEAD does not matter.

I will leave the simplest "just check we have .dst" version (in
other words, without any additional check on the .src side) in my
tree, but if anybody wants to pursue "let's make sure that .src
copies from somewhere in refs/heads/", please make sure that you
consider "--mirror", where an equivalent of "refs/*:refs/*" is used
as the refspec, i.e. there is a case where .src does not begin with
"refs/heads/" but does cover the hierarchy and wants to learn about
"HEAD".

Thanks.