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

Re: [PATCH 2/3] branch: suggest how to undo a --set-upstream when given one branch

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jul 10, 2012, 19:24 UTC
Message-ID
<20120710192408.GF8439@burratino>
In-Reply-To
<1341939181-8962-3-git-send-email-cmn@elego.de>
Hi,
Quick nitpicks.
Carlos Martín Nieto wrote:
Show 17 quoted lines
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -864,10 +864,32 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
>  		   info and making sure new_upstream is correct */
>  		create_branch(head, branch->name, new_upstream, 0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
>  	} else if (argc > 0 && argc <= 2) {
> +		struct branch *branch = branch_get(argv[0]);
> +		const char *old_upstream = NULL;
> +		int branch_existed = 0;
> +
>  		if (kinds != REF_LOCAL_BRANCH)
>  			die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
> +
> +		/* Save what argv[0] was pointing to so we can give
> +		   the --set-upstream-to hint */
> +		if (branch_has_merge_config(branch))
> +		  old_upstream = shorten_unambiguous_ref(branch->merge[0]->dst, 0);

Whitespace is odd here. Maybe this case could be factored out as a new function to make room on the right margin and make cmd_branch() easier to read straight through.

Show 13 quoted lines
> +
> +		branch_existed = ref_exists(branch->refname);
>  		create_branch(head, argv[0], (argc == 2) ? argv[1] : head,
>  			      force_create, reflog, 0, quiet, track);
> +
> +		if (argc == 1) {
> +			printf("If you wanted to make '%s' track '%s', do this:\n", head, argv[0]);
> +			if (branch_existed)
> +				printf(" $ git branch --set-upstream '%s' '%s'\n", argv[0], old_upstream);
> +			else
> +				printf(" $ git branch -d '%s'\n", argv[0]);
> +
> +			printf(" $ git branch --set-upstream-to '%s'\n", argv[0]);

Message should go on stderr and be guarded with an advice option (see advice.c).

Like this:
	const char *arg;
	...
	if (argc != 1 || !advice_old_fashioned_set_upstream)
		return 0; /* ok. */
	arg = argv[0];
	advise("If you wanted to make '%s' track '%s', do this:",
							head, arg);
	if (branch_existed)
		advise(" $ git branch --set-upstream-to='%s' '%s'",
			old_upstream, arg);
	else
		advise(" $ git branch -d '%s'", arg);
	advise(" $ git branch --set-upstream-to='%s'", arg);

If an argument contains single-quotes, the quoting will be wrong, but that's probably not worth worrying about.

Hope that helps, Jonathan

Previous: Carlos Martín NietoNext: Junio C Hamano
Message 21 of 29 in “A better way of handling upstream information in git-branch”
  1. 0/3 A better way of handling upstream information in git-branchCarlos Martín Nieto, Jul 10, 2012
  2. 1/3 branch: introduce --set-upstream-toCarlos Martín Nieto, Jul 10, 2012
  3. Matthieu MoyJul 10, 2012
  4. Junio C HamanoJul 10, 2012
  5. Jonathan NiederJul 10, 2012
  6. Junio C HamanoJul 10, 2012
  7. Jonathan NiederJul 10, 2012
  8. Junio C HamanoJul 10, 2012
  9. Jonathan NiederJul 10, 2012
  10. Junio C HamanoJul 10, 2012
  11. Jonathan NiederJul 10, 2012
  12. Junio C HamanoJul 11, 2012
  13. Jonathan NiederJul 11, 2012
  14. Miles BaderJul 12, 2012
  15. Junio C HamanoJul 12, 2012
  16. 2/3 branch: suggest how to undo a --set-upstream when given one branchCarlos Martín Nieto, Jul 10, 2012
  17. Matthieu MoyJul 10, 2012
  18. Carlos Martín NietoJul 11, 2012
  19. Junio C HamanoJul 10, 2012
  20. Carlos Martín NietoJul 11, 2012
  21. Jonathan NiederJul 10, 2012
  22. Junio C HamanoJul 10, 2012
  23. Jonathan NiederJul 10, 2012
  24. Carlos Martín NietoJul 11, 2012
  25. 3/3 branch: add --unset-upstream optionCarlos Martín Nieto, Jul 10, 2012
  26. Junio C HamanoJul 10, 2012
  27. Carlos Martín NietoJul 11, 2012
  28. Junio C HamanoJul 11, 2012
  29. Carlos Martín NietoJul 12, 2012

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.