1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/tool/git-refresh

37 lines
664 B
Text
Raw Normal View History

#!/bin/sh
set -e
quiet=
branch=
until [ $# = 0 ]; do
case "$1" in
--) shift; break;;
-C|--directory) shift; cd "$1";;
-C*) cd "${1#-C}";;
--directory=*) cd "${1#*=}";;
-q) quiet=1;;
-b|--branch) shift; branch="$1";;
-b*) branch="${1#-b}";;
--branch=*) branch="${1#*=}";;
-*) echo "unknown option: $1" 1>&2; exit 1;;
*) break;;
esac
shift
done
url="$1"
dir="$2"
shift 2
if [ -d "$dir" ]; then
echo updating "${dir#*/}" ...
[ $quiet ] || set -x
cd "$dir"
git fetch "$@"
exec git checkout ${branch:+"$branch"} "$@"
else
echo retrieving "${dir#*/}" ...
[ $quiet ] || set -x
exec git clone "$url" "$dir" "$@"
fi