From 5035242c4785bd23c53827a1656b5f97394f724e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 8 Jun 2007 01:19:13 -0700 Subject: checkout: do not get confused with ambiguous tag/branch names Although it is not advisable, we have always allowed a branch and a tag to have the same basename (i.e. it is not illegal to have refs/heads/frotz and refs/tags/frotz at the same time). When talking about a specific commit, the interpretation of 'frotz' has always been "use tag and then check branch", although we warn when ambiguities exist. However "git checkout $name" is defined to (1) first see if it matches the branch name, and if so switch to that branch; (2) otherwise it is an instruction to detach HEAD to point at the commit named by $name. We did not follow this definition when $name appeared under both refs/heads/ and refs/tags/ -- we switched to the branch but read the tree from the tagged commit, which was utterly bogus. Signed-off-by: Junio C Hamano --- git-checkout.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git-checkout.sh') diff --git a/git-checkout.sh b/git-checkout.sh index ed7c2c5f6a..7c5ca3d62f 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -63,12 +63,13 @@ while [ "$#" != "0" ]; do echo "unknown flag $arg" exit 1 fi - new="$rev" new_name="$arg" if git-show-ref --verify --quiet -- "refs/heads/$arg" then + rev=$(git-rev-parse --verify "refs/heads/$arg^0") branch="$arg" fi + new="$rev" elif rev=$(git-rev-parse --verify "$arg^{tree}" 2>/dev/null) then # checking out selected paths from a tree-ish. -- cgit v1.2.3