-
-
Save soutar/ff701834d0ce6194f677 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
stash_name="wip" | |
echo "> Updating master on all git repositories in the current directory" | |
for dir in */ | |
do | |
if [ -d ${dir}/.git ]; then | |
cd ${dir} | |
stashed=false | |
echo "----------------------------------------------------" | |
echo "- Processing ${dir}" | |
echo "----------------------------------------------------" | |
current_branch=$(git symbolic-ref --short HEAD) | |
# If git status has any output then we need to stash our changes | |
# so we can restore them after | |
if [[ -n $(git status -s) ]]; then | |
echo "> Saving WIP changes" | |
git stash save ${stash_name} | |
stashed=true | |
fi | |
# If we're not on master, checkout master | |
if [[ ${current_branch} -ne "master" ]]; then | |
echo "> Checking out master" | |
git checkout master | |
fi | |
echo "> Pulling master" | |
git pull origin master | |
# If we've moved branch, checkout the branch we started on | |
if [[ $(git symbolic-ref --short HEAD) -ne ${current_branch} ]]; then | |
git checkout ${current_branch} | |
fi | |
# If we stashed changes previously, restore them | |
if [[ ${stashed} = true ]]; then | |
echo "> Restoring WIP changes" | |
git stash pop stash^{/${stash_name}} | |
fi | |
cd - > /dev/null # Leave the repo | |
fi | |
done |
Good idea. I'll see what I can hack together
Also, maybe some command line flags to update all, api, cms, core etc.
array=( $@ )
len=${#array[@]}
if [[
then
echo "INFO: updating ALL sites.
else
echo "INFO: updating the given list [$@]"
cd ~/Sites
for site in $@ ; do
If the index is dirty, you can always stash non-committed changes before pulling and pop them back once it's done
There's another issue I tried to cater for with a script, which I unfortunately haven't had much time to look into. If you're switching between projects, your repos may be on different branches, e.g., master, feature1, and feature2, and it's easy to forget. That's where Brendan's flags could come in handy, but you still need to remember what branch each of your repos is on.
I'm ok with stashing if it's automatically put back on, but still wary here. The other thing is as mentioned all the various combos of, is the index dirty, is the repo on master (obviously it shouldnt really be dirty on master, but we all do that sometimes by mistake and then create a branch later). If its on another branch should it update that branch or should it update master? (this could be a parameter to pass ๐ ). These aren't problems or anything preventing from working, just things to take into account and features to add i guess ๐
Only risk i see with this is if one of your repos isnt on master / there are changes to files. Maybe add checking for that?