# vim: ft=sh [ -n "$LAMINAR_COMMON" ] # variables definition guard V="${V:-0}" if [ "$V" -ge 3 ]; then set -x fi ## Simple echo wrappers ######################################################### echo_stage() { echo -e "\033[1;34m========== " "$@" " ==========\033[0m ($(date))" >&2 } echo_info() { echo -e "\033[1;32m---------- " "$@" " ----------\033[0m" >&2 } echo_error() { echo -e "\033[1;31m---------- " "$@" " ----------\033[0m" >&2 } echo_debug() { echo -e "\033[1;30m--- " "$@" " ---\033[0m" >&2 } echo_fail() { echo -e "\033[1;31m---------- " "$@" " ----------\033[0m" >&2 return 1 } ## GIT ########################################################################## # Locked git lgit() { local gitdir="$1" shift flock --exclusive "$gitdir" git --git-dir="$gitdir" "$@" } # Fetch bare git repository # First argument has to be a source URL # Second argument is path to directory to which will be repository cloned to. git_fetch_bare() { if [ -d "$2" ]; then lgit "$2" --bare remote update --prune else git clone --mirror "$1" "$2" fi } # Common function for git_fetch_{w,g} # Additional fourth argument should be base path to git mirror _git_fetch() { local branch="$3" [ -n "$branch" ] || branch=master git_fetch_bare "$1" "$4/$2" lgit "$4/$2" --bare worktree prune # remove old work trees lgit "$4/$2" --bare worktree add --force --detach "$2" "$branch" } # Fetch git repository with mirror # _w: mirror is in WORKSPACE # _t: mirror is in TWORKSPACE # _g: mirror is in global workspace # First agument has to be a source URL # Second argument is name of directory to which will be directory cloned in. # Third argument is optional and should be branch name (master is used if not # provided). git_fetch_w() { _git_fetch "$1" "$2" "$3" "$WORKSPACE/git-mirror" } git_fetch_t() { _git_fetch "$1" "$2" "$3" "$TWORKSPACE/git-mirror" } git_fetch_g() { _git_fetch "$1" "$2" "$3" "$HOME/workspace/git-mirror" } # Clones one depth given repository with given branch/tag/hash # First agument has to be a source URL # Second argument is name of directory to which will be directory cloned in. # Third argument is optional and should be branch name (master is used if not # provided). git_clone() { local src="$1" local dir="$2" local branch="${3:-master}" git clone --depth 1 --branch "$branch" --recurse-submodules "$src" "$dir" }