vcs_git() { local rev='master' local setver=true local OPTIND=1 local opt while getopts 'r:V' opt; do case "$opt" in r) local rev="$OPTARG" ;; V) local setver=false ;; esac; done shift $((OPTIND-1)) [ "$1" = '--' ] && shift local reponame="$(basename "$1")" local dir="$dir_source/$name/$reponame" mkdir -p "$dir" cd "$dir" if [ ! -f HEAD ]; then # Create new repo git init --bare git remote add --mirror=fetch origin "$1" elif [ "$1" != "$(git config --get remote.origin.url)" ]; then # Update the URL git remote remove origin git remote add --mirror=fetch origin "$1" fi # Make sure we have the latest of whatever revision we want git fetch --prune --depth=1 --recurse-submodules origin "$rev" || true # Check if it's actually been updated local rev="$(git rev-parse "$rev")" if [ "$rev" != "$(cat "${dir}_rev_$_satname" 2> /dev/null || true)" ]; then echo "$rev" > "${dir}_rev_$_satname" vcs_compile=true fi cd "$OLDPWD" # Clone the repository if [ "$download_only" = false ]; then git clone "$dir" "$reponame" 2> /dev/null cd "$reponame" git checkout "$rev" 2> /dev/null # Update the $version variable accordingly [ "$setver" = true ] && version="$(git rev-list HEAD --count)_$(git rev-parse --short HEAD)" || true cd "$OLDPWD" fi }