#!/bin/bash g() { git "$@"; } case $1 in ""|-*) ;; *) cmd=$1 shift acmd=$(git config --get "alias.${cmd}") ;; esac case ${acmd:-${cmd}} in rebase) if [[ $1 == "all" ]] ; then shift if [[ $# -eq 0 ]] ; then exec r forall -c 'r rb all .' fi branches=$(g b | awk ' { if ($0 ~ "^[*] *[(]no branch[)]") { next } else if ($1 == "*") { b = $NF } else { list = list $NF " " } } END { print list b }') [[ -z ${branches} ]] && exit 0 eval $(bash-colors --env) echo "${GOOD}### ${PWD}${NORMAL}" for b in ${branches} ; do echo " ${HILITE}### $b${NORMAL}" g co $b || exit 1 if ! r rb "$@" ; then g rb-a fi done 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}} "$@"