#!/bin/bash echo "========================================================" echo " HomAroma Omnichannel - Git Push All Remotes" echo "========================================================" if [[ "$1" == "--help" || "$1" == "-h" ]]; then echo "" echo "Usage:" echo " ./push_all.sh [OPTIONS] [BRANCH]" echo "" echo "Options:" echo " demo, --demo Push only to showcase demo remotes (demo-*)" echo " --dry-run, -n Simulate push without modifying remotes" echo " --help, -h Show this help message" echo "" echo "Examples:" echo " ./push_all.sh Push current branch to ALL remotes" echo " ./push_all.sh demo Push current branch only to demo-* remotes" echo " ./push_all.sh master Push 'master' branch to ALL remotes" echo " ./push_all.sh --dry-run Test push to all remotes without changing anything" echo "" exit 0 fi CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "master") TARGET_BRANCH="$CURRENT_BRANCH" FILTER_PREFIX="" DRY_RUN=0 for arg in "$@"; do case "$arg" in demo|--demo) FILTER_PREFIX="demo-" ;; --dry-run|-n) DRY_RUN=1 ;; *) TARGET_BRANCH="$arg" ;; esac done echo "Target Branch : [$TARGET_BRANCH]" if [[ -n "$FILTER_PREFIX" ]]; then echo "Filter Mode : Only remotes starting with '$FILTER_PREFIX'" fi if [[ $DRY_RUN -eq 1 ]]; then echo "Mode : [DRY-RUN] (Will not actually push)" fi echo "" ALL_REMOTES=$(git remote) REMOTES=() for r in $ALL_REMOTES; do if [[ -z "$FILTER_PREFIX" || "$r" == "$FILTER_PREFIX"* ]]; then REMOTES+=("$r") fi done if [[ ${#REMOTES[@]} -eq 0 ]]; then echo "[ERROR] No matching git remotes found." exit 1 fi echo "Remotes queued for push:" for r in "${REMOTES[@]}"; do echo " * $r" done echo "========================================================" echo "" SUCCESS_LIST=() FAIL_LIST=() for r in "${REMOTES[@]}"; do echo "--------------------------------------------------------" echo "[>] Pushing branch '$TARGET_BRANCH' to remote '$r'..." echo "--------------------------------------------------------" if [[ $DRY_RUN -eq 1 ]]; then git push --dry-run "$r" "$TARGET_BRANCH" else git push "$r" "$TARGET_BRANCH" fi if [[ $? -eq 0 ]]; then echo "[OK] Successfully pushed to $r" SUCCESS_LIST+=("$r") else echo "[FAILED] Push failed for $r" FAIL_LIST+=("$r") fi echo "" done echo "========================================================" echo " PUSH SUMMARY" echo "========================================================" echo "Total: ${#SUCCESS_LIST[@]} succeeded, ${#FAIL_LIST[@]} failed" echo "" if [[ ${#SUCCESS_LIST[@]} -gt 0 ]]; then echo "[SUCCESS]: ${SUCCESS_LIST[*]}" fi if [[ ${#FAIL_LIST[@]} -gt 0 ]]; then echo "[FAILED] : ${FAIL_LIST[*]}" fi echo "========================================================" echo "Done." echo ""