]> git.droids-corp.org - git-central.git/commitdiff
Refactor create-branch into checkout which does more.
authorStephen Haberman <stephen@exigencecorp.com>
Tue, 19 Aug 2008 20:34:43 +0000 (15:34 -0500)
committerStephen Haberman <stephen@exigencecorp.com>
Tue, 19 Aug 2008 20:34:43 +0000 (15:34 -0500)
scripts/checkout [new file with mode: 0644]
scripts/create-branch [deleted file]
tests/t5000-script-checkout.sh [new file with mode: 0644]
tests/t5000-script-create-branch.sh [deleted file]

diff --git a/scripts/checkout b/scripts/checkout
new file mode 100644 (file)
index 0000000..5914676
--- /dev/null
@@ -0,0 +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"
+else
+       if [[ $exists_local -eq 0 ]] ; then
+               # 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
+
diff --git a/scripts/create-branch b/scripts/create-branch
deleted file mode 100644 (file)
index a3743d2..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-
-new_branch_name=$1
-
-# Make sure we have the latest origin/stable to branch
-git fetch
-
-# Specifying stable to get the last released code
-git checkout -b $new_branch_name origin/stable
-
-# Go ahead and put the branch out on the server
-git push origin $new_branch_name
-
-# Setup the merge property so that pulls come from the right place (instead of stable)
-git config --replace-all "branch.$new_branch_name.merge" "refs/heads/$new_branch_name"
-
diff --git a/tests/t5000-script-checkout.sh b/tests/t5000-script-checkout.sh
new file mode 100644 (file)
index 0000000..937143d
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+test_description='script checkout'
+
+. ./test-lib.sh
+
+export PATH=$PATH:../../scripts
+
+test_expect_success 'setup' '
+       echo "setup" >a &&
+       git add a &&
+       git commit -m "setup" &&
+       git clone ./. server &&
+       rm -fr server/.git/hooks &&
+       git remote add origin ./server
+       git checkout -b stable &&
+       git push origin stable
+'
+
+test_expect_success 'checkout a new branch clones stable' '
+       checkout topic1 &&
+       git branch | grep topic1 &&
+       git branch -r | grep origin/topic1 &&
+       git config --list | grep "branch.topic1.merge=refs/heads/topic1"
+'
+
+test_expect_success 'checkout an existing remote branch' '
+       cd server &&
+       git checkout -b topic2 stable &&
+       echo "$test_name" >a &&
+       git commit -a -m "Made topic2 on server" &&
+       cd .. &&
+
+       checkout topic2
+       git branch | grep topic2
+       git branch -r | grep origin/topic2
+       git config --list | grep "branch.topic2.merge=refs/heads/topic2"
+'
+
+test_expect_success 'checkout an existing local branch' '
+       checkout topic1
+'
+
+test_done
+
diff --git a/tests/t5000-script-create-branch.sh b/tests/t5000-script-create-branch.sh
deleted file mode 100644 (file)
index a5985d6..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-
-test_description='script create branch'
-
-. ./test-lib.sh
-
-export PATH=$PATH:../../scripts
-
-test_expect_success 'setup' '
-       echo "setup" >a &&
-       git add a &&
-       git commit -m "setup" &&
-       git clone ./. server &&
-       rm -fr server/.git/hooks &&
-       git remote add origin ./server &&
-       git config --add branch.master.remote origin &&
-       git config --add branch.master.merge refs/heads/master &&
-       git fetch
-
-       git checkout -b stable
-       git push origin stable
-'
-
-test_expect_success 'create branch clones stable' '
-       create-branch topic1
-       git branch | grep topic1
-       git branch -r | grep origin/topic1
-       git config --list | grep "branch.topic1.merge=refs/heads/topic1"
-'
-
-test_done
-