Thread (8 messages) flat view 8 messages, 3 authors, 2016-06-15

Re: [PATCH] checkout: allow full refnames for local branches

From: Lars Hjemli <hidden>
Date: 2016-06-15 22:43:09

On 5/9/07, Junio C Hamano [off-list ref] wrote:
"Lars Hjemli" [off-list ref] writes:
quoted
On 5/9/07, Junio C Hamano [off-list ref] wrote:
quoted
Lars Hjemli [off-list ref] writes:
quoted
This teaches git-checkout to strip the prefix 'refs/heads/' from the
supplied <branch> argument
Why is this necessary, may I ask?
I'm playing around with a gui frontend, and there I use
git-for-each-ref to obtain possible arguments for git-checkout. That's
how I discovered the 'problem', and solved it by stripping
'refs/heads/' in my frontend.
Pathspec-less variant of "git checkout" takes two kinds of
parameters and has two flavours in its behaviour:

 (1) an exact branch name, in which case it switches to the
     branch; otherwise

 (2) any arbitrary commit object name, in whch case it checks
     out and detaches HEAD.

A tricky part is that an exact branch name is often a perfectly
valid commit object name, so rule (1) trumps the rule (2).  You
just discovered a way to have a detached HEAD at a commit that
happens to be at an existing branch -- by naming that commit
without using its exact branch name.
Ok. But if this is intended behaviour, maybe we would want do change
the detach-message in this case:

[~/src/git] next$ git checkout refs/heads/master
Note: moving to "refs/heads/master" which isn't a local branch

(sorry for stealing your time with this unimportant stuff, it just
surprised me that refs/heads/$branch wasn't treated as a local branch
name)

-- 
larsh
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help