mirror of
https://github.com/tj/git-extras.git
synced 2026-09-13 00:46:26 -04:00
Allow -r parameter to be in any order in command line
This commit is contained in:
parent
61b2a2c703
commit
93150aa411
|
|
@ -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 $?
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue