Skip to content

Instantly share code, notes, and snippets.

@krohne
Last active January 18, 2019 15:37
Show Gist options
  • Save krohne/77f2d6bd916b7d667d896620728f1548 to your computer and use it in GitHub Desktop.
Save krohne/77f2d6bd916b7d667d896620728f1548 to your computer and use it in GitHub Desktop.
Update local Git repositories in parallel, 1 thread per core
#!/bin/bash
export GIT_ROOT=/Volumes/Routematch/Git
doit() {
cd $GIT_ROOT/$1
# What branch is this repo on?
# If master branch, checkout package.json and pull latest updates
# If .nvmrc exists, use specified version, else use node version 4
# Update dependencies
# --no-save prevents npm from adding that pesky extra line break at end of package.json
bash --login -c 'BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$BRANCH" == "master" ]]
then
[ -f package.json ] && git checkout package.json
git pull
fi
if [ -f .nvmrc ]
then
nvm use
else
nvm use 4
fi
if [ -f package.json ]
then
npm install --no-save
fi'
}
export -f doit
# Pull the latest scripts
cd $GIT_ROOT/com-utils-vagrant
git pull
cd $GIT_ROOT
# Add any missing development repos
com-utils-vagrant/gitutilities/createDeveloperGitClones.sh
# Update all the repos in parallel
if [[ $(command -v parallel) ]] ; then
# use gnu parallel, if installed. Parallel defaults to 1 per core.
ls -d1 */ | cut -d '/' -f1 | parallel -q --bar doit
else
# Use core count
CORES=$( sysctl -n hw.ncpu )
ls -d1 */ | xargs -I % -n 1 -P $CORES doit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment