Last active
August 16, 2016 12:42
-
-
Save rpunt/d1121258be406bac7599ca96c56ee0c1 to your computer and use it in GitHub Desktop.
Parallel git pulls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
superpull() { | |
dir=$1 | |
error_repos=$2 | |
cd $dir | |
STATUS=`mktemp` | |
echo -e "\n************************************\n* Pulling $dir\n************************************" >$STATUS | |
git checkout master 1>>$STATUS 2>&1 | |
if [[ $? != 0 ]]; then | |
# we probably have uncommitted changes | |
set -x | |
echo -e "\t$(tput setaf 1)${dir}$(tput sgr0)" >>"$error_repos" 2>&1 | |
echo -e "$(tput setaf 1)$(cat $STATUS)$(tput sgr0)" | |
set +x | |
else | |
git pull 1>>$STATUS 2>&1 | |
if [[ $? != 0 ]]; then | |
# pull failure; most likely because origin has been deleted | |
echo -e "\t$(tput setaf 1)${dir}$(tput sgr0)" >>"$error_repos" 2>&1 | |
echo -e "$(tput setaf 1)$(cat $STATUS)$(tput sgr0)" | |
else | |
# re-colorize pull output | |
# match repeating '+' or '-' at EOL, and the dash in '(-)' | |
sed -i '' "s/[+]/$(tput setaf 2)&$(tput sgr0)/g" $STATUS | |
sed -i '' "s/-*$/$(tput setaf 1)&$(tput sgr0)/g" $STATUS | |
sed -i '' "s/(-)/\($(tput setaf 1)-$(tput sgr0)\)/g" $STATUS | |
cat "$STATUS" | |
git fetch -p | |
fi | |
fi | |
rm -f $STATUS | |
} | |
export -f superpull | |
error_repos=`mktemp` | |
pushd ~/git/basedir 1>/dev/null 2>&1 | |
find -L $base -type d -depth 1 | xargs -P20 -I{} bash -c "superpull {} $error_repos" | |
test -s "$error_repos" && echo -e "\n$(tput setaf 1)*** Repos with errors: ***$(tput sgr0)" && cat $error_repos | |
rm -f $error_repos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment