From: Junio C Hamano <gitster@pobox.com>
To: Johan Herland <johan@herland.net>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] branch/checkout --track: Ensure that upstream branch is indeed a branch
Date: Wed, 16 Feb 2011 14:00:02 -0800 [thread overview]
Message-ID: <7vwrkzhc7x.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <201102161146.23749.johan@herland.net> (Johan Herland's message of "Wed\, 16 Feb 2011 11\:46\:23 +0100")
Johan Herland <johan@herland.net> writes:
> 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?
next prev parent reply other threads:[~2011-02-16 22:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-15 17:52 checkout/branch needs some extra safety around the --track option Johan Herland
2011-02-15 20:04 ` Junio C Hamano
2011-02-16 10:46 ` [PATCH] branch/checkout --track: Ensure that upstream branch is indeed a branch Johan Herland
2011-02-16 22:00 ` Junio C Hamano [this message]
2011-02-16 23:12 ` [PATCH v2] " Johan Herland
2011-02-18 0:45 ` Martin von Zweigbergk
2011-02-18 4:32 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vwrkzhc7x.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=johan@herland.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).