Last active
January 3, 2018 15:33
-
-
Save birgitta410/8d643d2a70fdeecf5fb41aca70633be3 to your computer and use it in GitHub Desktop.
Script to update multiple git repos in a folder
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
#!/bin/bash | |
set -e | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
BLUE='\033[1;34m' | |
YELLOW='\033[1;33m' | |
NC='\033[0m' # No Color | |
BRANCH_AHEAD_PATTERN="^.*ahead.*$" | |
NOT_STAGED_PATTERN="^.*not staged.*$" | |
rootDir=$(pwd) | |
printf "${YELLOW}You want to 'pull --rebase' all projects${NC}\n" | |
projects=('repo-dir-1' 'repo-dir-2' 'repo-dir-3') | |
printf "${YELLOW}Let's look at their status first${NC}\n" | |
for project in ${projects[@]} | |
do | |
printf "\n== ${BLUE}git status${NC} for ${BLUE}${project}${NC}\n" | |
cd $rootDir/$project | |
status=$(git status) | |
result_string="${status/Your branch is ahead/${YELLOW}Your branch is ahead${NC}}" | |
if [[ "${status}" =~ ${NOT_STAGED_PATTERN} ]]; then | |
git status # with shell syntax highlighting, red will show unstaged changes | |
elif [[ "${status}" =~ ${BRANCH_AHEAD_PATTERN} ]]; then | |
printf "${result_string}\n" # with custom coloring of "you are ahead" | |
else | |
git status # with shell syntax highlighting | |
fi | |
done | |
printf "${YELLOW}All clean? Do you want to continue with the pulls?${NC}\n" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) break;; | |
No ) exit;; | |
esac | |
done | |
for project in ${projects[@]} | |
do | |
printf "\n== Pulling ${BLUE}${project}${NC}\n" | |
cd $rootDir/$project | |
git pull --rebase | |
done | |
printf "\n${YELLOW}Done pulling, listing local commits FYI${NC}\n" | |
found_local_commits=0 | |
for project in ${projects[@]} | |
do | |
cd $rootDir/$project | |
status=$(git status) | |
result_string="${status/Your branch is ahead/${YELLOW}Your branch is ahead${NC}}" | |
if [[ "${status}" =~ ${BRANCH_AHEAD_PATTERN} ]]; then | |
printf "\n== ${BLUE}git status${NC} for ${BLUE}${project}${NC}\n" | |
printf "${result_string}\n" | |
found_local_commits=1 | |
fi | |
done | |
if [ ${found_local_commits} -eq 0 ]; then | |
echo "☯ No local commits found, everything's in sync ☯" | |
fi | |
printf "\n${YELLOW}========= ALL DONE ===========${NC}\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment