Files
homaroma/push_all.bat

152 lines
3.6 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
echo ========================================================
echo HomAroma Omnichannel - Git Push All Remotes
echo ========================================================
:: Check for help flags
if "%~1"=="--help" goto SHOW_HELP
if "%~1"=="-h" goto SHOW_HELP
if "%~1"=="/?" goto SHOW_HELP
:: Detect current git branch
for /f "tokens=*" %%b in ('git rev-parse --abbrev-ref HEAD 2^>nul') do (
set CURRENT_BRANCH=%%b
)
if "%CURRENT_BRANCH%"=="" set CURRENT_BRANCH=master
set TARGET_BRANCH=%CURRENT_BRANCH%
set FILTER_PREFIX=
set DRY_RUN=0
:: Parse arguments
:PARSE_ARGS
if "%~1"=="" goto AFTER_ARGS
if /i "%~1"=="demo" (
set FILTER_PREFIX=demo-
shift
goto PARSE_ARGS
)
if /i "%~1"=="--demo" (
set FILTER_PREFIX=demo-
shift
goto PARSE_ARGS
)
if /i "%~1"=="--dry-run" (
set DRY_RUN=1
shift
goto PARSE_ARGS
)
if /i "%~1"=="-n" (
set DRY_RUN=1
shift
goto PARSE_ARGS
)
set TARGET_BRANCH=%~1
shift
goto PARSE_ARGS
:AFTER_ARGS
echo Target Branch : [%TARGET_BRANCH%]
if not "%FILTER_PREFIX%"=="" (
echo Filter Mode : Only remotes starting with '%FILTER_PREFIX%'
)
if "%DRY_RUN%"=="1" (
echo Mode : [DRY-RUN] ^(Will not actually push^)
)
echo.
:: Collect remotes
set REMOTES=
for /f "tokens=*" %%r in ('git remote') do (
set R_NAME=%%r
if "%FILTER_PREFIX%"=="" (
set REMOTES=!REMOTES! %%r
) else (
echo !R_NAME! | findstr /b /c:"%FILTER_PREFIX%" >nul
if !errorlevel! equ 0 (
set REMOTES=!REMOTES! %%r
)
)
)
if "%REMOTES%"=="" (
echo [ERROR] No matching git remotes found.
pause
exit /b 1
)
echo Remotes to push (%REMOTES% ):
for %%r in (%REMOTES%) do (
echo * %%r
)
echo ========================================================
echo.
set SUCCESS_COUNT=0
set FAIL_COUNT=0
set SUCCESS_LIST=
set FAIL_LIST=
for %%r in (%REMOTES%) do (
echo --------------------------------------------------------
echo [^>] Pushing branch '%TARGET_BRANCH%' to remote '%%r'...
echo --------------------------------------------------------
if "%DRY_RUN%"=="1" (
git push --dry-run %%r %TARGET_BRANCH%
) else (
git push %%r %TARGET_BRANCH%
)
if !errorlevel! equ 0 (
echo [OK] Successfully pushed to %%r
set /a SUCCESS_COUNT+=1
set SUCCESS_LIST=!SUCCESS_LIST! %%r
) else (
echo [FAILED] Push failed for %%r
set /a FAIL_COUNT+=1
set FAIL_LIST=!FAIL_LIST! %%r
)
echo.
)
echo ========================================================
echo PUSH SUMMARY
echo ========================================================
echo Total: %SUCCESS_COUNT% succeeded, %FAIL_COUNT% failed
echo.
if not "!SUCCESS_LIST!"=="" (
echo [SUCCESS]:!SUCCESS_LIST!
)
if not "!FAIL_LIST!"=="" (
echo [FAILED] :!FAIL_LIST!
)
echo ========================================================
echo Done.
echo.
pause
exit /b 0
:SHOW_HELP
echo.
echo Usage:
echo push_all.bat [OPTIONS] [BRANCH]
echo.
echo Options:
echo demo, --demo Push only to showcase demo remotes (demo-wellness, demo-fashion, etc.)
echo --dry-run, -n Simulate push without modifying remotes
echo --help, -h, /? Show this help message
echo.
echo Examples:
echo push_all.bat Push current branch to ALL remotes
echo push_all.bat demo Push current branch only to demo-* remotes
echo push_all.bat master Push 'master' branch to ALL remotes
echo push_all.bat demo master Push 'master' branch to demo-* remotes
echo push_all.bat --dry-run Test push to all remotes without changing anything
echo.
pause
exit /b 0