From 93150aa4114c51f9426b95101a5b84fbdc628ddf Mon Sep 17 00:00:00 2001 From: Mark Pitman Date: Sun, 9 Jul 2017 12:10:19 -0700 Subject: [PATCH] Allow -r parameter to be in any order in command line --- bin/git-create-branch | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/bin/git-create-branch b/bin/git-create-branch index 8e335b7..6035840 100755 --- a/bin/git-create-branch +++ b/bin/git-create-branch @@ -1,22 +1,30 @@ #!/usr/bin/env bash -for param in $* +while test $# != 0 do - case $param in + case $1 in -r|--remote) - if [ $# -eq 2 ] + if [[ -n $2 ]] then - BRANCH=$2 - else REMOTE=$2 - BRANCH=$3 + shift + else + REMOTE=origin + shift fi ;; *) - BRANCH=$param + BRANCH=$1 esac + shift done +if [[ -z $BRANCH ]] && [[ -n $REMOTE ]] +then + BRANCH=$REMOTE + REMOTE=origin +fi + test -z $BRANCH && echo "branch required." 1>&2 && exit 1 if [[ -n $REMOTE ]] then @@ -26,10 +34,10 @@ then git push $REMOTE HEAD:refs/heads/$BRANCH git fetch $REMOTE git checkout --track -b $BRANCH $REMOTE/$BRANCH - else - git checkout -b $BRANCH + exit $? fi -else - git checkout -b $BRANCH fi +git checkout -b $BRANCH +exit $? +