Skip to content

Instantly share code, notes, and snippets.

@subfuzion
Last active August 29, 2015 14:10
Show Gist options
  • Save subfuzion/b313c826e452a1bdcee8 to your computer and use it in GitHub Desktop.
Save subfuzion/b313c826e452a1bdcee8 to your computer and use it in GitHub Desktop.
Update Repos Script
#!/usr/bin/env bash
# tony@subfuzion.com
# WARNING! This script assumes you never work in the master branch,
# so it doesn't check to see if there are any uncommitted changes
# or untracked files. If the branch is master, this script will
# attempt a git pull; otherwise, it will perform a git fetch.
# directories to include (use valid glob patterns, default is all)
declare -a whitelist=( */ )
# directories to ignore
declare -a blacklist=( scratch/ tmp/ )
function check_blacklist {
for name in ${blacklist[@]}; do
[[ $name = $1 ]] && return 0
done
return 1
}
for dir in ${whitelist[@]}; do
check_blacklist $dir
# ensure is a directory, contains .git directory, and is not in blacklist
[[ $? -ne 0 && -d "${dir}" && -e "${dir}/.git" ]] || continue
cd ${dir}
if git symbolic-ref --short HEAD | grep -Fxq "master"; then
# if on branch master, use git pull
git pull origin master
else
# otherwise, git fetch (will need to manually git merge)
echo "[ ${dir} ] FETCHING master, CURRENT BRANCH: $(git symbolic-ref --short HEAD)"
git fetch origin master
fi
[[ $? -ne 0 ]] && echo "*** Error accessing repo: ${dir} ***"
cd ..
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment