Update readme with fully working process.

This commit is contained in:
2024-12-05 12:56:37 +00:00
parent 90404ab44f
commit d288115757
3 changed files with 38 additions and 25 deletions

View File

@@ -20,39 +20,48 @@ if %ERRORLEVEL% NEQ 0 (
exit /b 1
)
:: Process each folder
:: Create a temporary directory for the git operations
set "TEMP_GIT_DIR=%TEMP%\mc_git_sync"
if exist "%TEMP_GIT_DIR%" rd /s /q "%TEMP_GIT_DIR%"
mkdir "%TEMP_GIT_DIR%"
cd "%TEMP_GIT_DIR%"
:: Initialize git repo
git init
git remote add origin "%REPO_URL%"
git config core.sparseCheckout true
:: Set up sparse checkout for selected folders
del /q .git\info\sparse-checkout 2>nul
for %%F in (%SYNC_FOLDERS%) do (
echo Processing %%F...
:: Create directory if it doesn't exist
if not exist "%~dp0%%F" mkdir "%~dp0%%F"
:: Initialize git in the directory if not already done
if not exist "%~dp0%%F\.git" (
cd "%~dp0%%F"
git init
git remote add origin "%REPO_URL%"
:: Configure sparse checkout
git config core.sparseCheckout true
:: Set up sparse checkout to only get this directory
echo %%F> .git/info/sparse-checkout
:: Initial fetch of just this directory
git fetch --depth 1 origin main
git checkout main
) else (
:: Just pull updates if git is already initialized
cd "%~dp0%%F"
git fetch origin main
git reset --hard origin/main
echo %%F/>> .git\info\sparse-checkout
)
:: Fetch latest content
git fetch --depth 1 origin main
git checkout main
:: Copy contents to instance folders
for %%F in (%SYNC_FOLDERS%) do (
if exist "%TEMP_GIT_DIR%\%%F" (
echo Syncing %%F...
:: Create target directory if it doesn't exist
if not exist "%~dp0%%F" mkdir "%~dp0%%F"
:: Copy contents, updating only newer files
robocopy "%TEMP_GIT_DIR%\%%F" "%~dp0%%F" /E /XO /NP /NFL /NDL
)
)
:: Clean up
cd "%~dp0"
rd /s /q "%TEMP_GIT_DIR%"
echo.
echo Sync completed successfully!
echo.
echo This sync has:
echo - Updated all tracked files from the repository
echo - Kept your local untracked files intact
echo - Preserved your local untracked files
echo.
pause