packages-scripts/git/commit-all-dirty.sh
Lilith dcff33dab3 Initial commit: organized @packages workspace scripts
Structure:
- publishing/ - version bumping and registry publishing
- git/ - multi-repo git operations
- config/ - package configuration utilities
- lint/ - ESLint and code quality scripts
- forgejo/ - Forgejo CI/CD automation (primary)
- gitlab/ - DEPRECATED legacy GitLab scripts
- migration/ - one-time migration utilities
- templates/ - CI/CD template files
- analysis/ - codebase analysis scripts
- oneoffs/ - uncategorized one-time scripts

Note: commits CLI will be merged into @ml/auto-commit-service

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 19:34:13 -08:00

96 lines
2.4 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# commit-all-dirty.sh - Commit all dirty repos with simple messages
#
# Usage:
# commit-all-dirty.sh # defaults to current directory
# commit-all-dirty.sh ~/Code/@packages # search specific path
#
# This is a simple bulk commit tool that doesn't require LLM service.
# Use 'commits once' for AI-generated commit messages.
#
set -euo pipefail
ROOT_PATH="${1:-.}"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Find all git repos
repos=$(find "$ROOT_PATH" -name ".git" -type d 2>/dev/null | while read gitdir; do
dirname "$gitdir"
done | sort)
if [ -z "$repos" ]; then
echo "No git repositories found in $ROOT_PATH"
exit 0
fi
committed=0
skipped=0
failed=0
echo -e "${BLUE}=== Committing all dirty repos ===${NC}"
echo ""
echo "$repos" | while read repo; do
# Get change count
changes=$(git -C "$repo" status --porcelain 2>/dev/null | wc -l)
if [ "$changes" -eq 0 ]; then
((skipped++)) || true
continue
fi
# Get package name for better commit message
pkg_name="unknown"
if [ -f "$repo/package.json" ]; then
pkg_name=$(python3 -c "import json; print(json.load(open('$repo/package.json')).get('name', 'unknown'))" 2>/dev/null || echo "unknown")
fi
rel_path="${repo#$ROOT_PATH/}"
[ "$rel_path" = "$repo" ] && rel_path="$repo"
echo -e "${YELLOW}Processing:${NC} $rel_path ($pkg_name) - $changes changes"
# Stage all changes
if ! git -C "$repo" add -A 2>/dev/null; then
echo -e "${RED} ✗ Failed to stage changes${NC}"
((failed++)) || true
continue
fi
# Get a summary of changes for commit message
file_count=$(git -C "$repo" status --porcelain | wc -l)
summary=$(git -C "$repo" status --short | head -5 | awk '{print $2}' | tr '\n' ', ' | sed 's/,$//')
if [ ${#summary} -gt 80 ]; then
summary="${file_count} files changed"
fi
# Create commit message
commit_msg="chore: update ${pkg_name} - ${summary}"
# Commit
if git -C "$repo" commit -m "$commit_msg" 2>/dev/null; then
echo -e "${GREEN} ✓ Committed: $commit_msg${NC}"
((committed++)) || true
else
echo -e "${RED} ✗ Commit failed${NC}"
((failed++)) || true
fi
echo ""
done
# Summary
echo ""
echo -e "${BLUE}=== Summary ===${NC}"
echo -e "Committed: ${GREEN}$committed${NC}"
echo -e "Skipped (clean): ${YELLOW}$skipped${NC}"
echo -e "Failed: ${RED}$failed${NC}"