| 1 |
#!/bin/sh |
| 2 |
set -e |
| 3 |
|
| 4 |
if (cd -P .) 2>/dev/null; then |
| 5 |
CHDIR='cd -P' |
| 6 |
else |
| 7 |
CHDIR='cd' |
| 8 |
fi |
| 9 |
|
| 10 |
quiet= |
| 11 |
branch= |
| 12 |
|
| 13 |
until [ $# = 0 ]; do |
| 14 |
case "$1" in |
| 15 |
--) shift; break;; |
| 16 |
-C|--directory) shift; $CHDIR "$1";; |
| 17 |
-C*) $CHDIR `expr "$1" : '-C\(.*\)'`;; |
| 18 |
--directory=*) $CHDIR `expr "$1" : '[^=]*=\(.*\)'`;; |
| 19 |
-q) quiet=1;; |
| 20 |
-b|--branch) shift; branch="$1";; |
| 21 |
-b*) branch=`expr "$1" : '-b\(.*\)'`;; |
| 22 |
--branch=*) branch=`expr "$1" : '[^=]*=\(.*\)'`;; |
| 23 |
-*) echo "unknown option: $1" 1>&2; exit 1;; |
| 24 |
*) break;; |
| 25 |
esac |
| 26 |
shift |
| 27 |
done |
| 28 |
|
| 29 |
url="$1" |
| 30 |
dir="$2" |
| 31 |
shift 2 |
| 32 |
[ x"$branch" = x ] && unset branch || : |
| 33 |
if [ -d "$dir" ]; then |
| 34 |
if [ x"$(git -C "$dir" describe --tags)" = x"$branch" ]; then |
| 35 |
exit 0 # already up-to-date |
| 36 |
fi |
| 37 |
echo updating `expr "/$dir/" : '.*/\([^/][^/]*\)/'` ... |
| 38 |
[ $quiet ] || set -x |
| 39 |
$CHDIR "$dir" |
| 40 |
${branch+git} ${branch+fetch} ${branch+"$@"} |
| 41 |
exec git ${branch+checkout} "${branch-pull}" "$@" |
| 42 |
else |
| 43 |
echo retrieving `expr "/$dir/" : '.*/\([^/][^/]*\)/'` ... |
| 44 |
[ $quiet ] || set -x |
| 45 |
exec git clone ${branch+--branch} ${branch+"$branch"} "$url" "$dir" "$@" |
| 46 |
fi |