2017-03-30 09:44:27 +03:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
2017-04-14 03:45:48 +03:00
|
|
|
if (cd -P .) 2>/dev/null; then
|
2017-04-13 11:08:04 +03:00
|
|
|
CHDIR='cd -P'
|
|
|
|
else
|
|
|
|
CHDIR='cd'
|
|
|
|
fi
|
|
|
|
|
2017-03-30 09:44:27 +03:00
|
|
|
quiet=
|
|
|
|
branch=
|
|
|
|
|
|
|
|
until [ $# = 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
--) shift; break;;
|
2017-04-13 11:08:04 +03:00
|
|
|
-C|--directory) shift; $CHDIR "$1";;
|
|
|
|
-C*) $CHDIR `expr "$1" : '-C\(.*\)'`;;
|
|
|
|
--directory=*) $CHDIR `expr "$1" : '[^=]*=\(.*\)'`;;
|
2017-03-30 09:44:27 +03:00
|
|
|
-q) quiet=1;;
|
2017-03-30 10:04:14 +03:00
|
|
|
-b|--branch) shift; branch="$1";;
|
2017-04-12 08:22:36 +03:00
|
|
|
-b*) branch=`expr "$1" : '-b\(.*\)'`;;
|
|
|
|
--branch=*) branch=`expr "$1" : '[^=]*=\(.*\)'`;;
|
2017-03-30 09:44:27 +03:00
|
|
|
-*) echo "unknown option: $1" 1>&2; exit 1;;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
url="$1"
|
|
|
|
dir="$2"
|
|
|
|
shift 2
|
2017-04-30 06:52:06 +03:00
|
|
|
[ x"$branch" = x ] && unset branch || :
|
2017-03-30 09:44:27 +03:00
|
|
|
if [ -d "$dir" ]; then
|
2017-04-13 10:52:05 +03:00
|
|
|
echo updating `expr "/$dir/" : '.*/\([^/][^/]*\)/'` ...
|
2017-03-30 09:44:27 +03:00
|
|
|
[ $quiet ] || set -x
|
2017-04-13 11:08:04 +03:00
|
|
|
$CHDIR "$dir"
|
2017-04-30 13:53:42 +03:00
|
|
|
${branch+git} ${branch+fetch} ${branch+"$@"}
|
2017-04-30 06:52:06 +03:00
|
|
|
exec git ${branch+checkout} "${branch-pull}" "$@"
|
2017-03-30 09:44:27 +03:00
|
|
|
else
|
2017-04-13 10:52:05 +03:00
|
|
|
echo retrieving `expr "/$dir/" : '.*/\([^/][^/]*\)/'` ...
|
2017-03-30 09:44:27 +03:00
|
|
|
[ $quiet ] || set -x
|
2017-04-30 13:53:42 +03:00
|
|
|
exec git clone ${branch+--branch} ${branch+"$branch"} "$url" "$dir" "$@"
|
2017-03-30 09:44:27 +03:00
|
|
|
fi
|