]> git.droids-corp.org - git-central.git/commitdiff
Use rev-parse so gc-checkout recognizes more than just branch names.
authorStephen Haberman <stephen@exigencecorp.com>
Sun, 24 Aug 2008 03:43:46 +0000 (22:43 -0500)
committerStephen Haberman <stephen@exigencecorp.com>
Sun, 24 Aug 2008 03:43:46 +0000 (22:43 -0500)
scripts/gc-checkout
tests/t5000-script-checkout.sh

index b8c5ee9b2884e05988ea27e2e75ce2ae1e323315..3a112c598da257dbd71a4ca12269f911e4c438ef 100644 (file)
@@ -1,27 +1,28 @@
 #!/bin/sh
 
 branch_name=$1
-exists_local=$(git branch | grep -x "  $branch_name" | wc -l)
-exists_remote=$(git branch | grep -x "  origin/$branch_name" | wc -l)
 
-if [[ $exists_remote -eq 0 ]] ; then
-       # Make sure we have the latest origin/stable to branch
-       git fetch
-       # Specifying stable to get the last released code
-       git checkout -b "$branch_name" origin/stable
-       # Go ahead and put the branch out on the server
-       git push origin "$branch_name"
-       # Setup the merge property so that pulls come from the right place (instead of stable)
-       git config --replace-all "branch.$branch_name.merge" "refs/heads/$branch_name"
+# See if it already exists
+git rev-parse $branch_name >/dev/null
+if [[ $? -eq 0 ]] ; then
+       # Just checkout what they asked
+       git checkout "$branch_name"
 else
-       if [[ $exists_local -eq 0 ]] ; then
+       exists_remote=$(git branch | grep -x "  origin/$branch_name" | wc -l)
+       if [[ $exists_remote -eq 0 ]] ; then
+               # Make sure we have the latest origin/stable to branch
+               git fetch
+               # Specifying stable to get the last released code
+               git checkout -b "$branch_name" origin/stable
+               # Go ahead and put the branch out on the server
+               git push origin "$branch_name"
+               # Setup the merge property so that pulls come from the right place (instead of stable)
+               git config --replace-all "branch.$branch_name.merge" "refs/heads/$branch_name"
+       else
                # Make sure we have the latest origin/$branch_name to branch
                git fetch
                # Do the checkout
                git checkout -b "$branch_name" "origin/$branch_name"
-       else
-               # Just checkout
-               git checkout "$branch_name"
        fi
 fi
 
index 56fb794f55f751d99574211abbc110ff77c6ced3..f162189b9585dd93d8f33344381ac92eed2a16ff 100644 (file)
@@ -41,5 +41,14 @@ test_expect_success 'checkout an existing local branch' '
        gc-checkout topic1
 '
 
+test_expect_success 'checkout a revision does not create a new branch' '
+       echo "$test_name" >a &&
+       git commit -a -m "$test_name" &&
+
+       prior=$(git rev-parse HEAD^) &&
+       gc-checkout $prior &&
+       git branch | grep "no branch"
+'
+
 test_done