Thread (6 messages) flat view 6 messages, 2 authors, 2016-06-15

Re: git does the wrong thing with ambiguous names

From: Alex Riesen <hidden>
Date: 2016-06-15 22:43:14
Subsystem: the rest · Maintainer: Linus Torvalds

Alex Riesen, Thu, Jun 07, 2007 01:33:27 +0200:
Alex Riesen, Thu, Jun 07, 2007 00:58:26 +0200:
quoted
Brandon Casey, Thu, Jun 07, 2007 00:13:48 +0200:
quoted
When a branch and tag have the same name, a git-checkout using that name 
succeeds (exits zero without complaining), switches to the _branch_, but 
updates the working directory contents to that specified by the _tag_. 
git-status show modified files.
Bad. To reproduce:

mkdir a && cd a && git init && :> a && git add . && git commit -m1 &&
:>b && git add . && git commit -m2 && git tag master HEAD^ &&
find .git/refs/ && gco -b new && gco master && git status
git-rev-parse actually warns about ambguities:

    $ git-rev-parse --verify master
    warning: refname 'master' is ambiguous.
    dd5cdc387f2160bf04d02ac08dfdaf952f769357

It's just that the warning is thrown away in git-checkout.sh

A quick and _very_ messy fix could like like that:
This one is much shorter and less friendly. Suggested by Junio on irc.
It makes checkout always prefer a branch.
diff --git a/git-checkout.sh b/git-checkout.sh
index 6b6facf..282c84f 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -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" 2>/dev/null)
+				new="$rev"
 				branch="$arg"
 			fi
 		elif rev=$(git-rev-parse --verify "$arg^{tree}" 2>/dev/null)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help