Re: [PATCH 1/2] sha1_name.c: signal if @{-N} was a true branch nameor a detached head
- From
Jeff King <peff@peff.net>
- Date
- May 9, 2013, 06:46 UTC
- Message-ID
- <20130509064607.GA11985@sigill.intra.peff.net>
- In-Reply-To
- <7vk3n9dvlu.fsf@alter.siamese.dyndns.org>
On Wed, May 08, 2013 at 02:12:29PM -0700, Junio C Hamano wrote:
Show 14 quoted lines
> The original API read "checkout: moving from (.*) to ..." from the > reflog of the HEAD, and returned the substring between "from" and > "to", but there was no way, if the substring was a 40-hex string, to > tell if we were on a detached HEAD at that commit object, or on a > branch whose name happened to be the 40-hex string. > > At this point, we cannot afford to change the format recorded in the > reflog, so introduce a heuristics to see if the 40-hex matches the > object name of the commit we are switching out of. This will > unfortunately mishandle this case: > > HEX=$(git rev-parse master) > git checkout -b $HEX master > git checkout master
I do not think I've ever seen a 40-hex branch name in practice, but I would think a branch named after the commit tip would be a reasonably common reason to have one, and would trigger this case.
Since the point of marking the detached HEAD is to turn off things like "@{-1}@{u}", we would want to be generous and err on the side of assuming it is a branch if it _might_ be one. IOW, shouldn't we treat the above sequence as a branch, and therefore mishandle:
git checkout $HEX^0 master git checkout master
by erroneously assuming that we moved to the branch $HEX?
-Peff