Created
February 5, 2020 15:21
-
-
Save Noxilex/5952da628a73f2647bf40231430090eb to your computer and use it in GitHub Desktop.
git fetch all
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 | |
# Checks if all subdirectories are up-to-date with their current git branch | |
REPOSITORIES=`pwd` | |
SUCCESS='✔️ ' | |
PROBLEM='✖️ ' | |
WARNING='⚠️ ' | |
BOLD='\033[1m' | |
RED='\033[0;31m' | |
YELLOW='\033[0;33m' | |
GREEN='\033[32m' | |
MAGENTA='\033[95m' | |
NC='\033[0m' # No Color | |
IFS=$'\n' | |
PULL="1" | |
#Handles arguments | |
while [[ $# -gt 0 ]] | |
do | |
key="$1" | |
case $key in | |
-p|--pull) | |
#Forces pull & doesn't prompt the user | |
PULL="0" | |
shift # past argument | |
;; | |
esac | |
done | |
for REPO in `ls "$REPOSITORIES/"` | |
do | |
if [ -d "$REPOSITORIES/$REPO" ] | |
then | |
if [ -d "$REPOSITORIES/$REPO/.git" ]; then | |
cd "$REPOSITORIES/$REPO" | |
BRANCH=$(git branch | grep '*' | cut -d ' ' -f2) | |
echo -e "${BOLD}# Fetching ${YELLOW} $REPO ${NC}${MAGENTA}($BRANCH)${NC}" | |
git fetch | |
GIT_STATUS=$(git status) | |
UP_TO_DATE=$(echo $GIT_STATUS | grep 'Your branch is up to date') | |
IS_BEHIND=$(echo $GIT_STATUS | grep 'Your branch is behind') | |
UNCOMMITED_CHANGES=$(echo $GIT_STATUS | grep 'Changes not staged for commit') | |
UNPUSHED_CHANGES=$(echo $GIT_STATUS | grep 'Your branch is ahead') | |
#==== UP TO DATE with remote ============= | |
if [[ -n $UP_TO_DATE ]];then | |
echo -e "${GREEN}${SUCCESS} Branch is up to date ${NC}" | |
elif [[ -n $UNPUSHED_CHANGES ]]; then | |
echo -e "${YELLOW}${WARNING} This repository has unpushed commits${NC}" | |
elif [[ -n $IS_BEHIND ]]; then | |
echo -e "${RED}${PROBLEM} Branch is out of date ${NC}" | |
if [[ $PULL != "0" ]];then | |
read -p "Pull from remote ? (y/n) : " pullValidation | |
case $pullValidation in | |
y) | |
git pull | |
;; | |
esac | |
else | |
git pull | |
fi | |
fi | |
#==== Uncommited Changes ====== | |
if [[ -n $UNCOMMITED_CHANGES ]]; then | |
echo -e "${YELLOW}${WARNING} This repository has uncommited changes${NC}" | |
else | |
echo -e "${GREEN}${SUCCESS} No changes left to commit${NC}" | |
fi | |
else | |
echo -e "${BOLD}# Fetching ${YELLOW} $REPO${NC}" | |
echo -e "${YELLOW}${WARNING} Directory doesn't contain .git folder.${NC}" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment