summaryrefslogtreecommitdiff
path: root/tool/git-refresh
diff options
context:
space:
mode:
Diffstat (limited to 'tool/git-refresh')
-rwxr-xr-xtool/git-refresh32
1 files changed, 21 insertions, 11 deletions
diff --git a/tool/git-refresh b/tool/git-refresh
index e3aa1b0970..9ed7d7c76e 100755
--- a/tool/git-refresh
+++ b/tool/git-refresh
@@ -1,19 +1,25 @@
#!/bin/sh
set -e
+if (cd -P .) 2>/dev/null; then
+ CHDIR='cd -P'
+else
+ CHDIR='cd'
+fi
+
quiet=
branch=
until [ $# = 0 ]; do
case "$1" in
--) shift; break;;
- -C|--directory) shift; cd "$1";;
- -C*) cd "${1#-C}";;
- --directory=*) cd "${1#*=}";;
+ -C|--directory) shift; $CHDIR "$1";;
+ -C*) $CHDIR `expr "$1" : '-C\(.*\)'`;;
+ --directory=*) $CHDIR `expr "$1" : '[^=]*=\(.*\)'`;;
-q) quiet=1;;
-b|--branch) shift; branch="$1";;
- -b*) branch="${1#-b}";;
- --branch=*) branch="${1#*=}";;
+ -b*) branch=`expr "$1" : '-b\(.*\)'`;;
+ --branch=*) branch=`expr "$1" : '[^=]*=\(.*\)'`;;
-*) echo "unknown option: $1" 1>&2; exit 1;;
*) break;;
esac
@@ -23,14 +29,18 @@ done
url="$1"
dir="$2"
shift 2
+[ x"$branch" = x ] && unset branch || :
if [ -d "$dir" ]; then
- echo updating "${dir#*/}" ...
+ if [ x"$(git -C "$dir" describe --tags)" = x"$branch" ]; then
+ exit 0 # already up-to-date
+ fi
+ echo updating `expr "/$dir/" : '.*/\([^/][^/]*\)/'` ...
[ $quiet ] || set -x
- cd "$dir"
- git fetch "$@"
- exec git checkout ${branch:+"$branch"} "$@"
+ $CHDIR "$dir"
+ ${branch+git} ${branch+fetch} ${branch+"$@"}
+ exec git ${branch+checkout} "${branch-pull}" "$@"
else
- echo retrieving "${dir#*/}" ...
+ echo retrieving `expr "/$dir/" : '.*/\([^/][^/]*\)/'` ...
[ $quiet ] || set -x
- exec git clone "$url" "$dir" "$@"
+ exec git clone ${branch+--branch} ${branch+"$branch"} "$url" "$dir" "$@"
fi