From 3621202548e26725885f0ed28ac1c425cf927099 Mon Sep 17 00:00:00 2001 From: Saravana Dhandapani Date: Wed, 25 Jun 2025 11:27:59 -0700 Subject: [PATCH] feat: recursively scan for unpushed changes git_repos_status.sh --- git_repos_status.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 git_repos_status.sh diff --git a/git_repos_status.sh b/git_repos_status.sh new file mode 100755 index 0000000..15d801c --- /dev/null +++ b/git_repos_status.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +CYAN='\033[0;36m' +NC='\033[0m' # No Color + +# Find all git repos +find . -type d -name ".git" | while read gitdir; do + repo=$(dirname "$gitdir") + cd "$repo" || continue + + echo -e "${CYAN}Repository: $repo${NC}" + + # Latest 2 commits + echo -e " ${YELLOW}Latest 2 commits:${NC}" + git log --oneline -2 --decorate + + # Uncommitted file count + uncommitted=$(git status --porcelain | wc -l | tr -d ' ') + if [ "$uncommitted" -eq 0 ]; then + echo -e " ${GREEN}Uncommitted files: $uncommitted${NC}" + else + echo -e " ${RED}Uncommitted files: $uncommitted${NC}" + fi + + # Check for unpushed commits + git remote update > /dev/null 2>&1 + ahead=$(git rev-list --count @{u}..HEAD 2>/dev/null) + behind=$(git rev-list --count HEAD..@{u} 2>/dev/null) + if [ "$ahead" -gt 0 ]; then + echo -e " ${YELLOW}Locally committed (not pushed): $ahead commit(s)${NC}" + else + echo -e " ${GREEN}All local commits are pushed${NC}" + fi + if [ "$behind" -gt 0 ]; then + echo -e " ${RED}Behind remote by $behind commit(s)${NC}" + fi + + echo -e "${CYAN}----------------------------------------${NC}" + cd - > /dev/null || exit +done \ No newline at end of file