Last active
July 30, 2020 09:18
-
-
Save gokhansolak/6c386636cc0b72daac558b290fc7aeba to your computer and use it in GitHub Desktop.
Updates all repos in a folder. The user is prompted to choose the repos.
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 | |
# This script updates all git repos in the folder | |
# it resides. It does fetch, pull and push to the | |
# current branch of a repo. It shows the diff and | |
# asks user to commit if there are changes in the | |
# working copy. Put it in your workspace and run | |
# it using terminal, from any path. Press 'q' to | |
# skip long diff. | |
# It requires an execution permission (chmod +x) | |
# -- Gokhan Solak | |
update_repo() { | |
git fetch | |
git diff | |
if [[ $(git diff) ]]; then | |
while true; do | |
read -p "Commit all? (y/n)" yn | |
case $yn in | |
[Yy]* ) | |
# commit all, user will enter the message | |
git commit -a | |
break;; | |
[Nn]* ) | |
echo "Ignoring changes." | |
break;; | |
* ) | |
echo "Please answer y or n.";; | |
esac | |
done | |
else | |
echo "No changes." | |
fi | |
# assigns the current branch into cb | |
cb=`git branch | grep \* | cut -d ' ' -f2` | |
echo "** Pulling" | |
git pull origin $cb | |
echo "** Pushing" | |
git push origin $cb | |
} | |
### main program begins here ### | |
echo "== Update Repos ==" | |
echo -e "All git repos under \e[32m$PWD/$(dirname "$0")\e[0m will be updated." | |
for d in $PWD/$(dirname "$0")/*/ | |
do | |
# Characters like \e[31m indicate color | |
echo -e "\n\n*** Entering \e[32m${d}\e[0m." | |
while true; do | |
echo -e "Update repo? (\e[31my\e[0m/\e[31mn\e[0m/\e[31mc\e[0m)" | |
read -p "" yn | |
case $yn in | |
[Yy]* ) | |
cd $d; update_repo; cd ..; break;; | |
[Nn]* ) | |
echo "Skipping $d"; break;; | |
[Cc]* ) | |
exit;; | |
* ) echo -e "Please answer \e[31my\e[0mes, \e[31mn\e[0mo or \e[31mc\e[0mancel.";; | |
esac | |
done | |
done | |
echo -e "\e[32mAll done.\e[0m" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment