summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2007-06-08 09:55:19 (GMT)
committerJunio C Hamano <gitster@pobox.com>2007-06-08 09:55:19 (GMT)
commitabc403f58452da667b261274a1091af61dfec35c (patch)
tree93e073859ddce0d1f2ce9067cb1adf93d73c9b7f
parent16befb8b7fbfcc9b2d38931f4081669558300adf (diff)
parent5035242c4785bd23c53827a1656b5f97394f724e (diff)
downloadgit-abc403f58452da667b261274a1091af61dfec35c.zip
git-abc403f58452da667b261274a1091af61dfec35c.tar.gz
git-abc403f58452da667b261274a1091af61dfec35c.tar.bz2
Merge branch 'maint'
* maint: checkout: do not get confused with ambiguous tag/branch names
-rwxr-xr-xgit-checkout.sh3
-rwxr-xr-xt/t7201-co.sh40
2 files changed, 42 insertions, 1 deletions
diff --git a/git-checkout.sh b/git-checkout.sh
index d561c88..33f1e87 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.
diff --git a/t/t7201-co.sh b/t/t7201-co.sh
index 5fa6a45..ed2e9ee 100755
--- a/t/t7201-co.sh
+++ b/t/t7201-co.sh
@@ -190,4 +190,44 @@ test_expect_success 'checkout to detach HEAD with HEAD^0' '
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