Files
git-mirror-zip/git-mirror-zip.bat
2026-08-05 21:28:43 +03:00

31 lines
747 B
Batchfile

@echo off
setlocal enabledelayedexpansion
:: Clone a git repo as a full mirror and pack it into a zip archive.
:: Works on Windows (PowerShell 5.0+).
if "%~1"=="" (
echo Usage: %~nx0 ^<git-repo-url^> [output.zip]
exit /b 1
)
set "URL=%~1"
set "OUT=%~2"
if "!OUT!"=="" set "OUT=repo.zip"
set "WORK_DIR=.tmp_git_mirror"
echo [1/3] Cloning mirror of %URL% ...
git clone --mirror "%URL%" "%WORK_DIR%"
if errorlevel 1 (
echo Git clone failed.
rmdir /s /q "%WORK_DIR%" >nul 2>&1
exit /b 1
)
echo [2/3] Creating %OUT% with maximum compression ...
powershell -NoProfile -Command ^
"Compress-Archive -Path '%WORK_DIR%\*' -DestinationPath '%OUT%' -CompressionLevel Optimal -Force"
echo [3/3] Done: %OUT%
rmdir /s /q "%WORK_DIR%" >nul 2>&1