Skip to contentSkip to conversation

git does the wrong thing with ambiguous names

DISCUSSION Brandon Casey 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Didn't hit reply-all...

Quoted 17 lines · Brandon Casey
Quoted 3 lines · Alex Riesen

Alex Riesen, Thu, Jun 07, 2007 01:33:27 +0200:

Quoted 2 lines

Alex Riesen, Thu, Jun 07, 2007 00:58:26 +0200:

Quoted 1 line

Brandon Casey, Thu, Jun 07, 2007 00:13:48 +0200:

[snip]

Quoted 12 lines

This one is much shorter and less friendly. Suggested by Junio on irc. It makes checkout always prefer a branch.

git-checkout.sh +1 -0
index 6b6facf..282c84f 100755
@@ -67,6 +67,8 @@ while [ "$#" != "0" ]; do
             new_name="$arg"
             if git-show-ref --verify --quiet -- "refs/heads/$arg"
             then
+                rev=$(git-rev-parse --verify "refs/heads/$arg^0" 
Quoted 8 lines
Quoted 6 lines
git-checkout.sh +1 -0
 2>/dev/null)
+                new="$rev"
                 branch="$arg"
             fi
         elif rev=$(git-rev-parse --verify "$arg^{tree}" 2>/dev/null)

This doesn't work.

sorry, scratch that. It does work.

Thunderbird turned $arg _hat_ 0 into $arg _superscript_ 0, which became $arg0 when I copy/pasted. And I didn't catch it. Again, apologies.

I think this is the intuitive behavior, prefer branch over tag. though I think a warning or refusal to switch would be better (but more complicated, and I don't know how to do it).

A quick run through of some other porcelain commands shows they prefer tag:
git log
git show
git diff

-brandon