#!/bin/bash
g() { git "$@"; }
+
cmd=$1
shift
-acmd=$(git config --get "alias.${cmd}")
+[[ -n ${cmd} ]] && acmd=$(git config --get "alias.${cmd}")
-case ${acmd} in
+case ${acmd:-${cmd}} in
rebase)
if [[ $1 == "all" ]] ; then
shift
exit 0
fi
;;
+sb-push)
+ sync_branch="v"
+
+ root=${PWD}
+ while [[ ! -d ${root}/.repo && ${root} != "/" ]] ; do
+ root=${root%/*}
+ done
+ cd "${root}" || exit 1
+
+ if [[ ! -e .repo/sandbox-url ]] ; then
+ echo "Please configure remote url base in ${root}/.repo/sandbox-url"
+ exit 1
+ fi
+ remote=$(<.repo/sandbox-url) || exit 1
+
+ echo "pushing projects from ${root}"
+
+ pids=()
+ rlist=$(r list)
+ tcnt=$(echo "${rlist}" | wc -l)
+ cnt=1
+ while read line ; do
+ line=( ${line} )
+ path=${line[0]}
+ export GIT_DIR=${path}/.git
+ proj=${line[2]}
+ printf '### (%*i/%i %3i%%) %s\n' \
+ ${#tcnt} $((cnt++)) ${tcnt} $(( cnt * 100 / tcnt )) ${proj}
+ src="${sync_branch}"
+ g l -1 ${src} >& /dev/null || src=
+ ( g push --force ${remote}/${proj} ${src}:refs/sandbox/${USER}/${sync_branch} >/dev/null ) &
+
+ # ssh servers do not like it when you hammer them :)
+ # Received disconnect from 74.125.248.80: 7: Too many concurrent connections
+ # fatal: The remote end hung up unexpectedly
+ pids+=( $! )
+ if [[ ${#pids[@]} -eq 20 ]] ; then
+ wait ${pids[@]:0:3}
+ pids=( ${pids[@]:3} )
+ fi
+ done <<<"$(r list)"
+ wait
+
+ exit 0
+ ;;
esac
exec repo ${acmd:-${cmd}} "$@"