#!/bin/bash
# performs svn update in this command's directory
-DIRNAME=$(dirname $0)
-DIRNAME=$(cd $DIRNAME; pwd -P)
+function _svn_or_git () {
+ where="$1"; [ -z "$where" ] && where="."
+ pushd $where >& /dev/null
+ cd $(pwd -P)
+ while true; do
+ [ -d .svn ] && { popd >& /dev/null; echo svn ; return ; }
+ [ -d .git ] && { popd >& /dev/null; echo git ; return ; }
+ [ "$(pwd -P)" == "/" ] && { popd >& /dev/null; echo none ; return ; }
+ cd ..
+ done
+}
-cd $DIRNAME
-(date ; svn update ) &> .auto-update.log
+# idem but runs in a subshell to protect cwd
+function svn_or_git () { ( _svn_or_git "$@" ; ) }
+
+####################
+# without an argument, use the place where the command is stored
+if [[ -z "$@" ]] ; then
+ DIRNAME=$(dirname $0)
+ DIRNAME=$(cd $DIRNAME; pwd -P)
+else
+ DIRNAME="$1" ; shift
+fi
+##########
+cd $DIRNAME
+case $(_svn_or_git) in
+ svn) (date ; svn update ) >& .auto-update.log ;;
+ git) (date ; git pull ) >& .auto-update.log ;;
+ *) echo 'only svn and git are supported' >& .auto-update.log ;;
+esac