#!/usr/bin/env bash # git-status-check.sh - Scan git repos for uncommitted changes and unpushed commits # Usage: git-status-check.sh [directory] # directory: path to scan (default: parent of script directory) # Output: TAB-separated lines: project_name \t uncommitted_count \t unpushed_count \t branch set -euo pipefail SCAN_DIR="${1:-$(dirname "$(dirname "$(readlink -f "$0")")")}" for dir in "$SCAN_DIR"/*/; do [ -d "$dir/.git" ] || continue name=$(basename "$dir") branch=$(git -C "$dir" rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown") # Count uncommitted changes uncommitted=$(git -C "$dir" status --porcelain 2>/dev/null | wc -l | tr -d ' ') # Count unpushed commits (0 if no upstream) if git -C "$dir" rev-parse --verify '@{u}' &>/dev/null; then unpushed=$(git -C "$dir" log '@{u}..HEAD' --oneline 2>/dev/null | wc -l | tr -d ' ') else unpushed=0 fi printf '%s\t%s\t%s\t%s\n' "$name" "$uncommitted" "$unpushed" "$branch" done