From: Jonathan Nieder <jrnieder@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Dun Peal <dunpealer@gmail.com>, git@vger.kernel.org
Subject: Re: Inconsistent behavior of the path disambiguator
Date: Fri, 29 Oct 2010 14:46:39 -0500 [thread overview]
Message-ID: <20101029194639.GA1738@burratino> (raw)
In-Reply-To: <7vbp6c7ski.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
> I can see why this is confusing, though.
>
> Dun Peal <dunpealer@gmail.com> writes:
>> $ git checkout foo --
>> fatal: invalid reference: foo
>
> Immediately after a clone you would have
>
> refs/heads/master
> refs/HEAD -> refs/heads/master
> refs/remotes/origin/foo
> refs/remotes/origin/whatever-else-you-have
> ...
>
> and there is no commit that you can name with "foo" when asking git to
> check out some paths out of, nor there is no branch that you can name with
> "foo" when asking git to check out to work on it.
How about something like this?
-- 8< --
Subject: checkout: apply Dscho's dwim even with "--" present
git reset and similar commands use -- to disambiguate between
revisions and paths on the command line. The same syntax is not
necessary to specify a revision to git checkout (for convenience
and historical reasons, revisions are preferred over paths), but
for consistency it is accepted:
git checkout master --; # check out master branch, not "master" file.
The autovivification of branches introduced by 70c9ac2f1 (DWIM "git
checkout frotz" to "git checkout -b frotz origin/frotz", 2009-10-18)
is currently disabled by that syntax, for no good reason. Paranoid
scripts can still use
git checkout --no-guess master
or even better,
old=$(git rev-parse --verify HEAD)
new=$(git rev-parse --verify refs/heads/master^0)
git read-tree -m -u --exclude-standard $old $new
git symbolic-ref -m "$me: switching branches" HEAD refs/heads/master
Requested-by: Dun Peal <dunpealer@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 9240faf..1dc3640 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -771,6 +771,12 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
* <ref> must be a valid tree, everything after the '--' must be
* a path.
*
+ * Except: with no paths, if <something> does not resolve as
+ * an object, no -t nor -b was given, and there is a tracking
+ * branch whose name is <something> in one and only one remote,
+ * then this is a short-hand to fork local <something> from
+ * that remote-tracking branch.
+ *
* case 2: git checkout -- [<paths>]
*
* everything after the '--' must be paths.
@@ -808,13 +814,11 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
arg = "@{-1}";
if (get_sha1_mb(arg, rev)) {
- if (has_dash_dash) /* case (1) */
- die("invalid reference: %s", arg);
if (!patch_mode &&
dwim_new_local_branch &&
opts.track == BRANCH_TRACK_UNSPECIFIED &&
!opts.new_branch &&
- !check_filename(NULL, arg) &&
+ (has_dash_dash || !check_filename(NULL, arg)) &&
argc == 1) {
const char *remote = unique_tracking_name(arg);
if (!remote || get_sha1(remote, rev))
@@ -822,9 +826,11 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
opts.new_branch = arg;
arg = remote;
/* DWIMmed to create local branch */
- }
- else
+ } else if (has_dash_dash) { /* case (1) */
+ die("invalid reference: %s", arg);
+ } else {
goto no_reference;
+ }
}
/* we can't end up being in (2) anymore, eat the argument */
next prev parent reply other threads:[~2010-10-29 19:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-29 18:11 Inconsistent behavior of the path disambiguator Dun Peal
2010-10-29 18:38 ` Junio C Hamano
2010-10-29 18:54 ` Dun Peal
2010-10-29 20:19 ` Re* " Junio C Hamano
2010-10-29 19:46 ` Jonathan Nieder [this message]
2010-10-29 20:25 ` Junio C Hamano
2010-10-29 23:53 ` [PATCH v2] checkout: apply Dscho's dwim even with "--" present Jonathan Nieder
2010-10-29 23:59 ` Jonathan Nieder
2010-10-30 0:41 ` Jonathan Nieder
2010-10-31 3:57 ` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101029194639.GA1738@burratino \
--to=jrnieder@gmail.com \
--cc=dunpealer@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.