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

Re: [PATCH v4 2/2] remote: find tracking branches for URL push destinations

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 22, 2026, 19:03 UTC
Message-ID
<xmqqpl0eoniz.fsf@gitster.g>
In-Reply-To
<08c432a2d4f52c202a2bebaa72330a17e94aedd1.1784743738.git.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 10 quoted lines
> +static bool remote_has_push_url(struct remote *remote, const char *url)
> +{
> +	const struct strvec *push_urls = push_url_of_remote(remote);
> +
> +	for (size_t i = 0; i < push_urls->nr; i++) {
> +		if (!strcmp(push_urls->v[i], url))
> +			return true;
> +	}
> +	return false;
> +}
A new helper is very much welcome.
Show 30 quoted lines
>  void ref_push_report_free(struct ref_push_report *report)
>  {
>  	while (report) {
> @@ -1887,13 +1898,45 @@ const char *branch_get_upstream(struct branch *branch, struct strbuf *err)
>  	return branch->merge[0]->dst;
>  }
>  
> -static char *tracking_for_push_dest(struct repository *repo UNUSED,
> +struct remote *repo_remote_for_push_tracking(struct repository *repo,
> +					     struct remote *remote)
> +{
> +	const struct strvec *push_urls;
> +	struct remote *first_match = NULL;
> +	struct remote_state *remote_state = repo->remote_state;
> +	const char *check_url;
> +
> +	if (remote->origin != REMOTE_UNCONFIGURED)
> +		return remote;
> +
> +	push_urls = push_url_of_remote(remote);
> +	if (push_urls->nr != 1)
> +		return remote;
> +	check_url = push_urls->v[0];
> +
> +	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_push_url(candidate, check_url))

This part used to use remote_has_url(candidate, remote->url.v[0]), which only looked at the .url and ignored .pushurl. Now it uses remote_has_push_url() so we grab the effective push URL for the remote we are dealing with and match it against the effective push URL of the candidates. Looks correct.

Show 10 quoted lines
> diff --git a/transport.c b/transport.c
> index fc144f0aed..30a4ab2cd5 100644
> --- a/transport.c
> +++ b/transport.c
> @@ -1553,8 +1553,11 @@ int transport_push(struct repository *r,
>  	if (!(flags & (TRANSPORT_PUSH_DRY_RUN |
>  		       TRANSPORT_RECURSE_SUBMODULES_ONLY))) {
>  		struct ref *ref;
> +		struct remote *tracking_remote = repo_remote_for_push_tracking(
> +			r, transport->remote);
Personally, I would have line-wrapped the above more like this:
		struct remote *tracking_remote =
			repo_remote_for_push_tracking(r, transport->remote);

This is just for a future reference; it is certainly not critical enough to warrant a new iteration just for this.

Thanks.
Previous: Harald Nordgren via GitGitGadgetNext: Junio C Hamano
Message 22 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.