git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] remote: resolve URL-valued push tracking remotes

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 21, 2026, 16:11 UTC
Message-ID
<xmqqecgw726b.fsf@gitster.g>
In-Reply-To
<ff645b21591a4b365b30acaf67a295510889141c.1784538618.git.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 29 quoted lines
> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> A branch may name its push destination with a URL instead of a
> configured remote. This is useful in fork workflows, where the original
> remote is renamed to "upstream", the fork is added as "origin", and an
> existing branch.<name>.pushRemote continues to contain the fork URL.
>
> Git can still push through the anonymous remote created for that URL.
> However, the anonymous remote has no fetch refspec. Git therefore cannot
> resolve @{push} to origin/<branch> or update that remote-tracking branch
> after a push. The push can succeed, or report that everything is up to
> date, while status continues to compare against a stale tracking ref or
> cannot show the push branch at all.
>
> A uniquely matching configured remote already provides the missing
> mapping. Use its fetch refspec when resolving the push tracking branch
> and when updating tracking refs after a push. This changes neither the
> push destination nor configuration. Keep the existing behavior when no
> remote matches or multiple remotes share the URL, since either case is
> ambiguous.
> ...
> +struct remote *repo_remote_for_push_tracking(struct repository *repo,
> +					     struct remote *remote)
> +{
> +	struct remote *first_match = NULL;
> +	struct remote_state *remote_state = repo->remote_state;
> +
> +	if (remote->origin != REMOTE_UNCONFIGURED || remote->url.nr != 1)
> +		return remote;

I briefly wondered what should happen when a caller passes NULL as the remote parameter to this function, but it turns out that no caller passes NULL. One caller is tracking_for_push_dest(), which is called from branch_get_push_1(). The latter refuses to proceed when !remote is true and does not call tracking_for_push_dest(), meaning it cannot pass NULL to this function. The other caller is transport_push(), which passes transport->remote. This value comes from transport_get(), which ensures transport->remote is not NULL before returning, so it cannot pass NULL to this function either.

Therefore, it is OK to assume remote is not NULL, and let the program crash loudly if that assumption is violated. Adding an explicit BUG() check would be overkill here:

    if (!repo || !remote)
            BUG("...");
Show 7 quoted lines
> +	for (int i = 0; i < remote_state->remotes_nr; i++) {
> +		struct remote *candidate = remote_state->remotes[i];
> +
> +		if (!candidate || candidate == remote ||
> +		    !remote_is_configured(candidate, 0) ||
> +		    !remote_has_url(candidate, remote->url.v[0]))
> +			continue;

This check, as well as the safety uniqueness check at the beginning of the function, only pays attention to the url member. However, it should also consider the pushurl member and, when it exists, ignore the url member. The upfront check would then look something like this (please sanity check the details):

	const char *check_url = NULL;
	if (remote->origin != REMOTE_UNCONFIGURED)
		return remote;
	if (remote->pushurl.nr) {
		if (remote->pushurl.nr != 1)
			return remote;
		check_url = remote->pushurl.v[0];
	} else if (remote->url.nr != 1) {
		return remote;
	} else {
		check_url = remote->url.v[0];
	}
The test inside the loop would then use check_url:
		!remote_has_url(candidate, check_url)
instead of testing remote->url.v[0] directly.
Thanks.
Previous: Junio C HamanoNext: Harald Nordgren via GitGitGadget
Message 8 of 23 in “remote: resolve url push tracking”
  1. 0/2 remote: resolve url push trackingHarald Nordgren via GitGitGadget, Jul 20, 2026
  2. 1/2 remote: pass repository to push tracking helperHarald Nordgren via GitGitGadget, Jul 20, 2026
  3. Junio C HamanoJul 20, 2026
  4. 2/2 remote: resolve URL-valued push tracking remotesHarald Nordgren via GitGitGadget, Jul 20, 2026
  5. Junio C HamanoJul 20, 2026
  6. Harald NordgrenJul 20, 2026
  7. Junio C HamanoJul 20, 2026
  8. Junio C HamanoJul 21, 2026
  9. 0/2 remote: renamed remote push trackingHarald Nordgren via GitGitGadget, Jul 21, 2026
  10. 1/2 remote: pass repository to push tracking helperHarald Nordgren via GitGitGadget, Jul 21, 2026
  11. 2/2 remote: find tracking branches for URL push destinationsHarald Nordgren via GitGitGadget, Jul 21, 2026
  12. D. Ben KnobleJul 21, 2026
  13. Harald NordgrenJul 21, 2026
  14. 0/2 remote: url-based pushRemote with renamed remotesHarald Nordgren via GitGitGadget, Jul 21, 2026
  15. 1/2 remote: pass repository to push tracking helperHarald Nordgren via GitGitGadget, Jul 21, 2026
  16. 2/2 remote: find tracking branches for URL push destinationsHarald Nordgren via GitGitGadget, Jul 21, 2026
  17. Junio C HamanoJul 21, 2026
  18. Ben KnobleJul 22, 2026
  19. 0/2 remote: url-based pushRemote with renamed remotesHarald Nordgren via GitGitGadget, Jul 22, 2026
  20. 1/2 remote: pass repository to push tracking helperHarald Nordgren via GitGitGadget, Jul 22, 2026
  21. 2/2 remote: find tracking branches for URL push destinationsHarald Nordgren via GitGitGadget, Jul 22, 2026
  22. Junio C HamanoJul 22, 2026
  23. Junio C HamanoJul 23, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.