branch_name=$1
# See if it already exists
-git rev-parse $branch_name >/dev/null
+git rev-parse --verify --quiet $branch_name >/dev/null
if [[ $? -eq 0 ]] ; then
# Just checkout what they asked
git checkout "$branch_name"
else
# Make sure we have the latest origin/$branch_name to branch
git fetch
- exists_remote=$(git branch | grep -x " origin/$branch_name" | wc -l)
+ exists_remote=$(git branch -r | grep -x " origin/$branch_name" | wc -l)
if [[ $exists_remote -eq 0 ]] ; then
# Specifying stable to get the last released code
git checkout -b "$branch_name" origin/stable
test_expect_success 'checkout an existing remote branch' '
cd server &&
git checkout -b topic2 stable &&
- echo "$test_name" >a &&
+ echo "$test_name on server" >a &&
git commit -a -m "Made topic2 on server" &&
cd .. &&
- gc-checkout topic2
- git branch | grep topic2
- git branch -r | grep origin/topic2
- git config --list | grep "branch.topic2.merge=refs/heads/topic2"
+ ! git branch | grep topic2 &&
+ gc-checkout topic2 &&
+ git branch | grep topic2 &&
+ git branch -r | grep origin/topic2 &&
+ git config --list | grep "branch.topic2.merge=refs/heads/topic2" &&
+
+ echo "$test_name on client" >a &&
+ git commit -a -m "Move topic2 on client" &&
+ git push origin topic2
'
test_expect_success 'checkout an existing local branch' '