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

Re: [PATCH v7] tracking branches: add advice to ambiguous refspec error

From
Glen Choo <chooglen@google.com>
Date
Apr 1, 2022, 16:53 UTC
Message-ID
<kl6lmth4sq1m.fsf@chooglen-macbookpro.roam.corp.google.com>
In-Reply-To
<pull.1183.v7.git.1648793113943.gitgitgadget@gmail.com>
"Tao Klerks via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 39 quoted lines
> diff --git a/branch.c b/branch.c
> index 6b31df539a5..182f1c5a556 100644
> --- a/branch.c
> +++ b/branch.c
> @@ -18,17 +18,31 @@ struct tracking {
>  	int matches;
>  };
>  
> +struct find_tracked_branch_cb {
> +	struct tracking *tracking;
> +	struct string_list ambiguous_remotes;
> +};
> +
>  static int find_tracked_branch(struct remote *remote, void *priv)
>  {
> -	struct tracking *tracking = priv;
> +	struct find_tracked_branch_cb *ftb = priv;
> +	struct tracking *tracking = ftb->tracking;
>  
>  	if (!remote_find_tracking(remote, &tracking->spec)) {
> -		if (++tracking->matches == 1) {
> +		switch (++tracking->matches) {
> +		case 1:
>  			string_list_append(tracking->srcs, tracking->spec.src);
>  			tracking->remote = remote->name;
> -		} else {
> +			break;
> +		case 2:
> +			/* there are at least two remotes; backfill the first one */
> +			string_list_append(&ftb->ambiguous_remotes, tracking->remote);
> +			/* fall through */
> +		default:
> +			string_list_append(&ftb->ambiguous_remotes, remote->name);
>  			free(tracking->spec.src);
>  			string_list_clear(tracking->srcs, 0);
> +		break;
>  		}
>  		tracking->spec.src = NULL;
>  	}

Ah I see, on the first iteration, we set the first remote's name to tracking->remote, and on the second iteration, we copy that value to the list before copying the _current_ remote's name to the list.

Show 25 quoted lines
> -test_expect_success 'avoid ambiguous track' '
> +test_expect_success 'avoid ambiguous track and advise' '
>  	git config branch.autosetupmerge true &&
>  	git config remote.ambi1.url lalala &&
>  	git config remote.ambi1.fetch refs/heads/lalala:refs/heads/main &&
>  	git config remote.ambi2.url lilili &&
>  	git config remote.ambi2.fetch refs/heads/lilili:refs/heads/main &&
> -	test_must_fail git branch all1 main &&
> +	cat <<-EOF >expected &&
> +	fatal: not tracking: ambiguous information for ref '\''refs/heads/main'\''
> +	hint: There are multiple remotes whose fetch refspecs map to the remote
> +	hint: tracking ref '\''refs/heads/main'\'':
> +	hint:   ambi1
> +	hint:   ambi2
> +	hint: ''
> +	hint: This is typically a configuration error.
> +	hint: ''
> +	hint: To support setting up tracking branches, ensure that
> +	hint: different remotes'\'' fetch refspecs map into different
> +	hint: tracking namespaces.
> +	EOF
> +	test_must_fail git branch all1 main 2>actual &&
> +	test_cmp expected actual &&
>  	test -z "$(git config branch.all1.merge)"
>  '

And this test shows that this indeed does what we think it does. Nicely done.

I notice that we there is an instance of test -z "$(some git command)", which IIRC is discouraged because it would mask a failure in the git command, but that's not new and I don't think it needs to be fixed in this series anyway.

Reviewed-by: Glen Choo <chooglen@google.com>
Previous: Tao Klerks via GitGitGadgetNext: Junio C Hamano
Message 35 of 36 in “tracking branches: add advice to ambiguous refspec error”
  1. tracking branches: add advice to ambiguous refspec errorTao Klerks via GitGitGadget, Mar 21, 2022
  2. Ævar Arnfjörð BjarmasonMar 21, 2022
  3. Tao KlerksMar 22, 2022
  4. RFC: tracking branches: add advice to ambiguous refspec errorTao Klerks via GitGitGadget, Mar 22, 2022
  5. Ævar Arnfjörð BjarmasonMar 22, 2022
  6. tracking branches: add advice to ambiguous refspec errorTao Klerks via GitGitGadget, Mar 28, 2022
  7. Junio C HamanoMar 28, 2022
  8. Glen ChooMar 28, 2022
  9. Junio C HamanoMar 28, 2022
  10. Tao KlerksMar 28, 2022
  11. Ævar Arnfjörð BjarmasonMar 28, 2022
  12. Junio C HamanoMar 28, 2022
  13. Junio C HamanoMar 28, 2022
  14. Tao KlerksMar 29, 2022
  15. tracking branches: add advice to ambiguous refspec errorTao Klerks via GitGitGadget, Mar 29, 2022
  16. Tao KlerksMar 29, 2022
  17. Junio C HamanoMar 29, 2022
  18. Tao KlerksMar 30, 2022
  19. tracking branches: add advice to ambiguous refspec errorTao Klerks via GitGitGadget, Mar 30, 2022
  20. Ævar Arnfjörð BjarmasonMar 30, 2022
  21. Tao KlerksMar 30, 2022
  22. Tao KlerksMar 30, 2022
  23. Ævar Arnfjörð BjarmasonMar 30, 2022
  24. Junio C HamanoMar 30, 2022
  25. Ævar Arnfjörð BjarmasonMar 30, 2022
  26. Junio C HamanoMar 30, 2022
  27. Ævar Arnfjörð BjarmasonMar 30, 2022
  28. tracking branches: add advice to ambiguous refspec errorTao Klerks via GitGitGadget, Mar 31, 2022
  29. Junio C HamanoMar 31, 2022
  30. Glen ChooMar 31, 2022
  31. Tao KlerksApr 1, 2022
  32. Glen ChooApr 1, 2022
  33. Junio C HamanoMar 31, 2022
  34. tracking branches: add advice to ambiguous refspec errorTao Klerks via GitGitGadget, Apr 1, 2022
  35. Glen ChooApr 1, 2022
  36. Junio C HamanoApr 1, 2022

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.