Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save martinandersen3d/21c438e2f1249c4bca834c3478e1c2b3 to your computer and use it in GitHub Desktop.
Save martinandersen3d/21c438e2f1249c4bca834c3478e1c2b3 to your computer and use it in GitHub Desktop.
recursive find folders with uncommitet files in git folders
#!/bin/bash
LANG=en_US.UTF-8
dir="/media/myuser/gitrepos"
cd "$dir"
# -------------------------------------------
console_log () {
COLOR='\033[1;33m'
NC='\033[0m' # No Color
echo ""
printf "${COLOR}-------------------------------------------${NC}\n"
printf "${COLOR}$1 ${NC}\n"
printf "${COLOR}-------------------------------------------${NC}\n"
echo ""
}
# -------------------------------------------
console_color () {
COLOR='\033[1;33m'
NC='\033[0m' # No Color
printf "${COLOR}$1 ${NC}\n"
}
# -------------------------------------------
console_green () {
COLOR='\033[1;32m'
NC='\033[0m' # No Color
printf "${COLOR}$1 ${NC}\n"
}
# -------------------------------------------
console_red () {
COLOR='\033[1;31m'
NC='\033[0m' # No Color
printf "${COLOR}$1 ${NC}\n"
}
# -------------------------------------------
console_log "ALL GIT DIRECTORYS IN THIS FOLDER: "
# -------------------------------------------
find "$(pwd -P)" -type d -name '.git' -exec dirname {} \; 2>/dev/null | sort
# -------------------------------------------
console_log "ALL GIT DIRECTORYS WITH MISSING COMMITS: "
# -------------------------------------------
IFS=$'\n'
dirs=`find "$(pwd -P)" -type d -name '.git' -exec dirname {} \; 2>/dev/null | sort`
count=0
for item in $dirs
do
count=$((count+1))
cd "$item"
echo "$item"
echo ""
branch=`git branch --show-current`
echo "Branch: $branch"
last_commit_date=`git log -1 --format="%at" | xargs -I{} date -d @{} +%Y/%m/%d_%H:%M:%S`
echo "Last Commit Date: $last_commit_date"
changed_files_count=`git status --porcelain | wc -l`
if [ "$changed_files_count" == "0" ]; then
console_green "Changed Files Count: $changed_files_count"
else
console_red "Changed Files Count: $changed_files_count"
echo ""
git status --porcelain | head -n 5
echo "..and maybe more files"
fi
echo ""
echo "Remote repositorys:"
remotes=`git remote -v`
remotes_count=`git remote -v | wc -l`
git remote -v
if [ "$remotes_count" == "0" ]; then
console_red "REMOTE REPOSITORY IS MISSING"
fi
echo "-------------------------------------------------------------------------------------------"
cd "$item"
done
# SCRIPT EXAMPLE Output:
# -------------------------------------------------------------------------------------------
# /path/to/folder/with/git/files
# Branch: master
# Last Commit Date: 2020/04/16_18:19:09
# Changed Files Count: 7
# D .DS_Store
# M .gitattributes
# M file1
# M file2
# M file2
# ..and maybe more files
# Remote repositorys:
# origin ssh://[email protected]/gitusername/reponame.git (fetch)
# origin ssh://[email protected]/gitusername/reponame.git (push)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment