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

Re: [PATCH] branch/checkout --track: Ensure that upstream branch is indeed a branch

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 16, 2011, 22:00 UTC
Message-ID
<7vwrkzhc7x.fsf@alter.siamese.dyndns.org>
In-Reply-To
<201102161146.23749.johan@herland.net>
Johan Herland <johan@herland.net> writes:
Show 30 quoted lines
> When creating a new branch using the --track option, we must make sure that
> we don't try to set an upstream that does not make sense to follow (using
> 'git pull') or update (using 'git push'). The current code checks against
> using HEAD as upstream (since tracking a symref doesn't make sense). However,
> tracking a tag doesn't make sense either. Indeed, tracking _any_ ref that is
> not a (local or remote) branch doesn't make sense, and should be disallowed.
>
> This patch achieves this by checking that the ref we're trying to --track
> resides within refs/heads/* or refs/remotes/*. This new check replaces the
> previous check against HEAD.
> ...
> Make it so.
>
> diff --git a/branch.c b/branch.c
> index 93dc866..f46a43a 100644
> --- a/branch.c
> +++ b/branch.c
> @@ -175,8 +175,10 @@ void create_branch(const char *head,
>  			die("Cannot setup tracking information; starting point is not a branch.");
>  		break;
>  	case 1:
> -		/* Unique completion -- good, only if it is a real ref */
> -		if (explicit_tracking && !strcmp(real_ref, "HEAD"))
> +		/* Unique completion -- good, only if it is a real branch */
> +		if (explicit_tracking &&
> +		    prefixcmp(real_ref, "refs/heads/") &&
> +		    prefixcmp(real_ref, "refs/remotes/"))
>  			die("Cannot setup tracking information; starting point is not a branch.");
>  		break;
>  	default:

Thomas's "HEAD" patch 84c1a89 (branch: do not attempt to track HEAD implicitly, 2010-12-14) has an extra action to reset real_ref to NULL when not asking for "explicit_tracking" in the same codepath.

<<<<<<< HEAD
		/* Unique completion -- good, only if it is a real ref */
		if (!strcmp(real_ref, "HEAD")) {
			if (explicit_tracking)
				die("Cannot setup tracking information; starting point is not a branch.");
			else
				real_ref = NULL;
		}
=======
		/* Unique completion -- good, only if it is a real branch */
		if (explicit_tracking &&
		    prefixcmp(real_ref, "refs/heads/") &&
		    prefixcmp(real_ref, "refs/remotes/"))
			die("Cannot setup tracking information; starting point is not a branch.");
>>>>>>> @{-1}
Don't we need something similar here?
Previous: Johan HerlandNext: Johan Herland
Message 4 of 7 in “checkout/branch needs some extra safety around the --track option”
  1. Johan HerlandFeb 15, 2011
  2. Junio C HamanoFeb 15, 2011
  3. branch/checkout --track: Ensure that upstream branch is indeed a branchJohan Herland, Feb 16, 2011
  4. Junio C HamanoFeb 16, 2011
  5. branch/checkout --track: Ensure that upstream branch is indeed a branchJohan Herland, Feb 16, 2011
  6. Martin von ZweigbergkFeb 18, 2011
  7. Junio C HamanoFeb 18, 2011

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.