Nicolas Pitre [off-list ref] writes:
What purpose does this "feature" serve? Making sure people remain
stupid and get even more confused when the special dwimery doesn't work
because they don't know the difference between a local branch and a
remote tracking branch?
And now people will be left wondering why after a fetch they don't get
the latest stuff when they do "git checkout topic" again. Is this any
better?
Sverre's explanation does not match reality.
We used to just say "topic is not a rev nor path" and failed when the user
said "git checkout topic". And the magic kicks in when there is only one
"remotes/*/topic".
Because this cannot be any request other than to check out a local branch
"topic", and because there is no place more sensible than the "topic"
taken from the "origin" (as that is the sole place that has "topic"), it
dwims as a shorthand for "checkout -b topic origin/topic" and tells you
that it did so.
So people _has_ to still know that local branches are the only thing they
can check out (iow, "checkout topic" is not a request to check out a
remote tracking branch).
Heya,
On Fri, Jan 29, 2010 at 22:58, Junio C Hamano [off-list ref] wrote:
Sverre's explanation does not match reality.
Heh, that's the second time I messed up explaining this new feature,
maybe I should stop doing that... eh... my bad.
--
Cheers,
Sverre Rabbelier
On Fri, 29 Jan 2010, Junio C Hamano wrote:
We used to just say "topic is not a rev nor path" and failed when the user
said "git checkout topic". And the magic kicks in when there is only one
"remotes/*/topic".
Because this cannot be any request other than to check out a local branch
"topic", and because there is no place more sensible than the "topic"
taken from the "origin" (as that is the sole place that has "topic"), it
dwims as a shorthand for "checkout -b topic origin/topic" and tells you
that it did so.
OK. That is probably sensible.
I don't think any improvement on the detached head message should
presume on this though.
And it might be a good idea to say explicitly that what happened is the
creation of a detached HEAD, like in:
diff --git a/builtin-checkout.c b/builtin-checkout.c
index 5277817..c0a44d7 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -523,7 +523,10 @@ static void update_refs_for_switch(struct checkout_opts *opts,
REF_NODEREF, DIE_ON_ERR);
if (!opts->quiet) {
if (old->path)
- fprintf(stderr, "Note: moving to '%s' which isn't a local branch\nIf you want to create a new branch from this checkout, you may do so\n(now or later) by using -b with the checkout command again. Example:\n git checkout -b <new_branch_name>\n", new->name);
+ fprintf(stderr, "Note: '%s' isn't a local branch head: creating a detached HEAD\n"
+ "If you want to create a new branch from this checkout, you may do so\n"
+ "(now or later) by using -b with the checkout command again. Example:\n"
+ " git checkout -b <new_branch_name>\n", new->name);
describe_detached_head("HEAD is now at", new->commit);
}
}
(string split onto multiple lines for easier source reading)
I think this is important to 1) mention the notion of a branch _head_,
and 2) mention "detached HEAD" explicitly for people to be directed to
appropriate documentation. So with this change you know exactly what
happened and why.
Nicolas