feat: add git-status-check.sh scan script
Scans all git repos in a directory for uncommitted changes and unpushed commits. Outputs structured TAB-separated results. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
28
git-status-check.sh
Normal file
28
git-status-check.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user