Last active
August 29, 2015 14:10
-
-
Save subfuzion/b313c826e452a1bdcee8 to your computer and use it in GitHub Desktop.
Update Repos Script
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 | |
# [email protected] | |
# 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