Bail better when changebranch fails due to something like trumping a file.
[socialgit.git] / bin / changebranch
blob8b061a914c07619d23b37177679233beb589c70d
1 #!/bin/sh
2 # changebranch
4 CURBRANCH=`currentbranchname`
5 if [ "$CURBRANCH" = "$1" ]; then
6 exit
7 fi
9 if (( $(git diff HEAD | wc -l) > 0 )); then
10 git branch $CURBRANCH.dirty
11 git checkout $CURBRANCH.dirty
12 echo "stashing dirty working copy" | git commit -a -F -
15 git fetch
16 git checkout -b $1 origin/$1
17 git checkout $1
19 if [ "$?" = "0" ]; then
21 if [ "$(git branch | grep $1.dirty)" != "" ]; then
22 git merge $1.dirty
23 git branch -D $1.dirty
24 git reset HEAD^
27 # HOOK
28 HOOK_POST_CHANGE_BRANCH=./`git rev-parse --show-cdup`.socialgit/hooks/post-change-branch
29 ls $HOOK_POST_CHANGE_BRANCH 2>/dev/null && $HOOK_POST_CHANGE_BRANCH
31 else
32 exit 1