summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 23fcdc7)
raw | patch | inline | side by side (parent: 23fcdc7)
author | Junio C Hamano <gitster@pobox.com> | |
Fri, 8 Jun 2007 08:19:13 +0000 (01:19 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 8 Jun 2007 08:19:13 +0000 (01:19 -0700) |
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 <gitster@pobox.com>
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 <gitster@pobox.com>
git-checkout.sh | patch | blob | history | |
t/t7201-co.sh | patch | blob | history |
diff --git a/git-checkout.sh b/git-checkout.sh
index ed7c2c5f6aab338c844329e3ae3d9c7ce003680f..7c5ca3d62f85b78ec82f02c2045435d889c32cdd 100755 (executable)
--- a/git-checkout.sh
+++ b/git-checkout.sh
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.
diff --git a/t/t7201-co.sh b/t/t7201-co.sh
index 5fa6a45577894e05446351fc5076a27accb1fa9f..ed2e9ee3c6fea4767f0aa288dca02825569abedf 100755 (executable)
--- a/t/t7201-co.sh
+++ b/t/t7201-co.sh
fi
'
+test_expect_success 'checkout with ambiguous tag/branch names' '
+
+ git tag both side &&
+ git branch both master &&
+ git reset --hard &&
+ git checkout master &&
+
+ git checkout both &&
+ H=$(git rev-parse --verify HEAD) &&
+ M=$(git show-ref -s --verify refs/heads/master) &&
+ test "z$H" = "z$M" &&
+ name=$(git symbolic-ref HEAD 2>/dev/null) &&
+ test "z$name" = zrefs/heads/both
+
+'
+
+test_expect_success 'checkout with ambiguous tag/branch names' '
+
+ git reset --hard &&
+ git checkout master &&
+
+ git tag frotz side &&
+ git branch frotz master &&
+ git reset --hard &&
+ git checkout master &&
+
+ git checkout tags/frotz &&
+ H=$(git rev-parse --verify HEAD) &&
+ S=$(git show-ref -s --verify refs/heads/side) &&
+ test "z$H" = "z$S" &&
+ if name=$(git symbolic-ref HEAD 2>/dev/null)
+ then
+ echo "Bad -- should have detached"
+ false
+ else
+ : happy
+ fi
+
+'
+
test_done