#!/usr/bin/env bash # # git-push-all.sh - Push all git repos to their remotes # # Usage: # git-push-all.sh [root_path] # git-push-all.sh --dry-run # show what would be pushed # set -euo pipefail ROOT_PATH="${1:-/var/home/lilith/Code/@packages}" DRY_RUN=false [[ "${1:-}" == "--dry-run" ]] && DRY_RUN=true && ROOT_PATH="${2:-/var/home/lilith/Code/@packages}" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' BLUE='\033[0;34m' NC='\033[0m' echo -e "${BLUE}=== Pushing all repos ===${NC}" echo "" pushed=0 skipped=0 failed=0 # Find all git repos while IFS= read -r gitdir; do repo=$(dirname "$gitdir") rel_path="${repo#$ROOT_PATH/}" cd "$repo" # Check if ahead of remote ahead=$(git rev-list --count @{u}..HEAD 2>/dev/null || echo "0") if [[ "$ahead" == "0" ]]; then skipped=$((skipped + 1)) continue fi branch=$(git branch --show-current) if [[ "$DRY_RUN" == "true" ]]; then echo -e "${YELLOW}[DRY-RUN]${NC} $rel_path: would push $ahead commits to $branch" pushed=$((pushed + 1)) else echo -ne "${BLUE}Pushing${NC} $rel_path ($ahead commits)... " if git push origin "$branch" 2>/dev/null; then echo -e "${GREEN}✓${NC}" pushed=$((pushed + 1)) else echo -e "${RED}✗${NC}" failed=$((failed + 1)) fi fi done < <(find "$ROOT_PATH" -name ".git" -type d 2>/dev/null) echo "" echo -e "${BLUE}Summary:${NC} ${GREEN}$pushed pushed${NC}, $skipped up-to-date, ${RED}$failed failed${NC}"