Update cfz_update_utility.bat

- cleanup
- more safety checks
- attempt at fixing pause skip (double-click execution)
- warning about not staged changes
- added more options:
(view last 50 commits, manual git command, switch branch)
This commit is contained in:
Rando717 2025-10-09 10:09:13 +02:00 committed by GitHub
parent 2920f79bcc
commit 54186b1225
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,72 +1,209 @@
@echo off @echo off
title ComfyUI-Zluda Update Utility v0.1 title ComfyUI-Zluda Update Utility v0.4
setlocal enabledelayedexpansion setlocal enabledelayedexpansion
set "PYTHON=%~dp0venv\Scripts\python.exe" set "DEFAULT_BRANCH=master"
set "GIT="
set "VENV_DIR=.\venv"
:get_version_info set "BRANCH="
set "COMMIT="
set "COMMIT_DATE="
set "COMMIT_TIME="
set "REMOTE_COMMIT="
set "REMOTE_COMMIT_DATE="
set "REMOTE_COMMIT_TIME="
set "AHEAD=0"
set "BEHIND=0"
git rev-parse --is-inside-work-tree >NUL 2>&1
if ERRORLEVEL 1 (
echo This directory is not a Git repository.
pause
exit /b
)
goto show_menu
:manual_git
cls
echo :manual_git=====================================================================
echo [INFO] Type any git command below, e.g.:
echo --version
echo --help
echo status
echo.
set /p gitcmd=git
if "%gitcmd%"=="" (
echo [INFO] No command entered.
call :pausefix
goto manual_git
)
echo.
echo %gitcmd% | findstr /R /I "\<reset\> \<clean\> \<rebase\>" >nul
if %errorlevel%==0 (
echo [WARN] Destructive commands are not allowed here.
call :pausefix
goto show_menu
)
echo.
set /p confirm=Run this command? (Y/N):
if /I not "%confirm%"=="Y" (
echo [INFO] Command canceled.
call :pausefix
goto show_menu
)
echo [EXEC] git %gitcmd%
echo --------------------------------------------------------------------------------
git %gitcmd%
echo --------------------------------------------------------------------------------
call :pausefix
goto show_menu
:get_local_version_info
for /f "delims=" %%b in ('git rev-parse --abbrev-ref HEAD') do set "BRANCH=%%b" for /f "delims=" %%b in ('git rev-parse --abbrev-ref HEAD') do set "BRANCH=%%b"
for /f "delims=" %%c in ('git rev-parse HEAD') do set "COMMIT=%%c" for /f "delims=" %%c in ('git rev-parse HEAD') do set "COMMIT=%%c"
for /f "delims=" %%d in ('git log -1 --format^="%%ad" --date=iso-strict') do set "FULL_DATE=%%d" for /f "delims=" %%d in ('git log -1 --format^="%%ad" --date=iso-strict') do set "FULL_DATE=%%d"
for /f "tokens=1 delims=T" %%x in ("!FULL_DATE!") do set "COMMIT_DATE=%%x" for /f "tokens=1,2 delims=T" %%x in ("!FULL_DATE!") do (
for /f "tokens=1 delims=+" %%y in ("!FULL_DATE!") do set "COMMIT_TIME=%%y" set "COMMIT_DATE=%%x"
set "COMMIT_TIME=!COMMIT_TIME:*T=!" set "COMMIT_TIME=%%y"
)
set "COMMIT_TIME=!COMMIT_TIME:~0,8!"
exit /b
:get_remote_version_info
for /f "delims=" %%r in ('git rev-parse @{u}') do set "REMOTE_COMMIT=%%r"
for /f "delims=" %%d in ('git log -1 --format^="%%ad" --date=iso-strict @{u}') do set "REMOTE_FULL_DATE=%%d"
for /f "tokens=1,2 delims=T" %%x in ("!REMOTE_FULL_DATE!") do (
set "REMOTE_COMMIT_DATE=%%x"
set "REMOTE_COMMIT_TIME=%%y"
)
set "REMOTE_COMMIT_TIME=!REMOTE_COMMIT_TIME:~0,8!"
exit /b
:pausefix
echo %cmdcmdline% | findstr /i "\/c" >nul
if %errorlevel%==0 (
pause
) else (
pause
)
exit /b
:show_menu
call :get_local_version_info
call :get_remote_version_info
goto menu
:get_version_info
:menu :menu
cls cls
echo ====================================================================== echo :menu===========================================================================
echo * * * ComfyUI-Zluda Update Utility v0.1 * * * echo ComfyUI-Zluda Update Utility v0.4 branch: !BRANCH!
echo ---------------------------------------------------------------------- echo ================================================================================
echo current version: !COMMIT_DATE! !COMMIT_TIME! hash: !COMMIT:~0,8! branch: !BRANCH! echo 1. Show Updates [Safe] - git fetch, git log
echo ====================================================================== echo 2. Download Updates [Safe] - git fetch, git log, git pull
echo 1. Check for Updates [Safe - check only] echo 3. Fix Broken Update [WARN] - git fetch, git reset [Destructive]
echo 2. Check and Download Updates [Safe - pull latest commits] echo 4. Force Reset Branch [WARN] - git fetch, git reset, git clean [Destructive]
echo 3. Fix Broken Update [Force reset to origin/master] echo 5. Branch Info [Safe] - git status
echo 4. Force Reset Branch [WARNING - hard reset] echo 6. View Last 50 Commits [Safe] - git log --oneline
echo 5. Info [Safe - local branch state] echo 7. Switch Branch [Safe] - git checkout
echo 8. Git Command [Adv.] - input a raw git command manually
echo. echo.
echo 0. Exit echo 0. Exit
echo.
echo ---version----------------------------------------------------------------------
echo LOCAL: (!COMMIT:~0,8!) !COMMIT_DATE! !COMMIT_TIME!
echo REMOTE: (!REMOTE_COMMIT:~0,8!) !REMOTE_COMMIT_DATE! !REMOTE_COMMIT_TIME!
echo ---notes------------------------------------------------------------------------
echo a): Option 5 shows which files will be removed by option 4.
echo This includes: modified (not staged), untracked, and ignored files.
echo b): Option 3 removes modified files only.
echo Untracked and ignored files (per .gitignore) are preserved.
echo c): Batch scripts can behave unpredictably; sometimes the menu will refresh
echo without waiting. Pressing ENTER a few times before selection can help.
echo ================================================================================
echo. echo.
echo ======================================================================
REM (TODO: Auto-switch to master/main if not on correct branch, with a warning)
REM (TODO: Add check for staged/modified or uncommited changes when updating)
set choice= set choice=
set /p choice=Choose an option (0-5): set /p choice=Choose an option (0-8):
if "%choice%"=="1" goto check_update if "%choice%"=="1" goto check_update
if "%choice%"=="2" goto regular_update if "%choice%"=="2" goto regular_update
if "%choice%"=="3" goto fix_update if "%choice%"=="3" goto fix_update
if "%choice%"=="4" goto force_reset if "%choice%"=="4" goto force_reset
if "%choice%"=="5" goto status if "%choice%"=="5" goto status
if "%choice%"=="6" goto view_commits
if "%choice%"=="7" goto switch_branch
if "%choice%"=="8" goto manual_git
if "%choice%"=="0" goto end if "%choice%"=="0" goto end
echo Invalid choice. Please try again... echo Invalid choice. Please try again...
pause pause
goto menu goto show_menu
:switch_branch
cls
echo :switch_branch==================================================================
echo [INFO] Available branches:
git branch -a
echo.
set /p target_branch=Enter branch name to switch to:
if "%target_branch%"=="" (
echo [INFO] No branch entered.
call :pausefix
goto show_menu
)
git checkout "%target_branch%"
call :pausefix
goto show_menu
:view_commits
cls
echo :view_commits===================================================================
echo [INFO] Last 50 commits:
git --no-pager log --oneline -n 50
call :pausefix
goto show_menu
:status :status
cls cls
echo ====================================================================== echo :status=========================================================================
echo current version: !COMMIT_DATE! !COMMIT_TIME! hash: !COMMIT:~0,8! branch: !BRANCH! echo LOCAL: !COMMIT_DATE! !COMMIT_TIME! hash: !COMMIT:~0,8!
echo ---------------------------------------------------------------------- echo REMOTE: !REMOTE_COMMIT_DATE! !REMOTE_COMMIT_TIME! hash: !REMOTE_COMMIT:~0,8!
git status --ignored echo --------------------------------------------------------------------------------
echo.
git rev-parse --abbrev-ref --symbolic-full-name @{u} >nul 2>&1
if errorlevel 1 (
echo [WARN] No upstream tracking branch set.
echo [INFO] You can set it with:
echo git branch --set-upstream-to=origin/%DEFAULT_BRANCH% %DEFAULT_BRANCH%
) else (
for /f %%a in ('git rev-list --count HEAD..@{u}') do set "BEHIND=%%a"
for /f %%a in ('git rev-list --count @{u}..HEAD') do set "AHEAD=%%a"
if "!AHEAD!"=="0" if "!BEHIND!"=="0" (
echo [INFO] Your branch is up to date with the remote.
) else (
echo [INFO] Branch Status: Ahead by !AHEAD! / Behind by !BEHIND!
)
)
echo --------------------------------------------------------------------------------
echo [INFO] Summary of changes (git diff --stat):
git --no-pager diff --stat 2>nul
echo --------------------------------------------------------------------------------
echo [INFO] Git status:
git status
echo --------------------------------------------------------------------------------
echo [INFO] Git status (porcelain):
git status --porcelain git status --porcelain
echo. echo --------------------------------------------------------------------------------
echo M = Modified files ?? = Untracked files echo [INFO] Git status (ignored):
echo ====================================================================== git status --ignored -s
pause echo ================================================================================
goto menu call :pausefix
goto show_menu
:check_update :check_update
cls cls
echo ====================================================================== echo :check_update===================================================================
echo * * * Checking for available updates... echo [INFO] Checking for available updates...
echo.
git fetch >NUL git fetch >NUL
for /f "delims=" %%L in ('git rev-parse @') do set LOCAL=%%L for /f "delims=" %%L in ('git rev-parse @') do set LOCAL=%%L
for /f "delims=" %%R in ('git rev-parse @{u}') do set REMOTE=%%R for /f "delims=" %%R in ('git rev-parse @{u}') do set REMOTE=%%R
@ -75,103 +212,80 @@ if NOT "%LOCAL%"=="%REMOTE%" (
echo [INFO] Update available. New commits: echo [INFO] Update available. New commits:
git --no-pager log --oneline %LOCAL%..%REMOTE% git --no-pager log --oneline %LOCAL%..%REMOTE%
echo. echo.
echo * * * If your branch is "behind", you can run option 2 to update. echo [INFO] If your branch is "behind", you can run option 2 to update.
) else ( ) else (
echo. echo [INFO] Already up to date.
echo * * * Already up to date. )
echo.
echo [INFO] Checking for uncommitted changes...
for /f %%s in ('git status --porcelain') do (
echo [WARN] You have uncommitted changes. Please commit or stash them before updating.
call :pausefix
goto show_menu
) )
echo ======================================================================
pause
goto menu
:regular_update :regular_update
cls cls
echo ====================================================================== echo :regular_update=================================================================
echo * * * Checking and updating to a new version if possible... echo [INFO] Checking and updating to a new version if possible...
echo.
copy comfy\customzluda\zluda-default.py comfy\zluda.py /y >NUL copy comfy\customzluda\zluda-default.py comfy\zluda.py /y >NUL
git fetch >NUL git fetch >NUL
for /f "delims=" %%L in ('git rev-parse @') do set LOCAL=%%L for /f "delims=" %%L in ('git rev-parse @') do set LOCAL=%%L
for /f "delims=" %%R in ('git rev-parse @{u}') do set REMOTE=%%R for /f "delims=" %%R in ('git rev-parse @{u}') do set REMOTE=%%R
if NOT "%LOCAL%"=="%REMOTE%" ( if NOT "%LOCAL%"=="%REMOTE%" (
echo. echo.
echo Update available. New commits: echo [INFO] Update available. New commits:
git --no-pager log --oneline %LOCAL%..%REMOTE% git --no-pager log --oneline %LOCAL%..%REMOTE%
echo. echo.
echo Pulling updates... echo [INFO] Pulling updates...
git --no-pager pull git --no-pager pull
echo. echo.
echo * * * Update complete. echo [DONE] Update complete.
) else ( ) else (
echo. echo [INFO] Already up to date.
echo * * * Already up to date.
) )
call :pausefix
echo ====================================================================== goto show_menu
:get_version_info
pause
goto menu
:fix_update :fix_update
cls cls
echo ====================================================================== echo :fix_update=====================================================================
echo * * * Fixing broken Git state... echo [INFO] Fixing broken Git state...
echo. echo.
call "%VENV_DIR%\Scripts\activate" >NUL 2>&1
git fetch --all git fetch --all
git reset --hard origin/master git reset --hard origin/%DEFAULT_BRANCH%
git --no-pager pull
echo. echo.
echo * * * If you see a successful update now, it is done. echo [INFO] If you see a successful update now, it is done.
echo ====================================================================== call :pausefix
:get_version_info goto show_menu
pause
goto menu
:force_reset :force_reset
cls cls
echo ====================================================================== echo :force_reset====================================================================
echo. echo.
echo * * * WARNING: This will completely reset all changes * * * echo WARNING: This will completely reset all changes
echo. echo.
echo ---------------------------------------------------------------------- echo --------------------------------------------------------------------------------
echo. echo.
echo This will hard RESET to origin/master. echo This will hard RESET to origin/%DEFAULT_BRANCH%.
echo This includes deleting ALL untracked AND ignored files. echo This includes deleting ALL untracked AND ignored files.
echo. echo.
echo --- Dry run: showing what would be deleted --- echo --- Dry run: showing what would be deleted ---
git clean -n -f -d -x git clean -n -f -d -x
echo ---------------------------------------------------------------------- echo --------------------------------------------------------------------------------
echo. echo.
set /p confirm=Are you sure? Type YES to proceed with full reset: set /p confirm=Are you sure? Type YES to proceed with full reset:
if /I not "%confirm%"=="YES" goto menu if /I not "%confirm%"=="YES" goto show_menu
echo. echo.
echo *** Proceeding with force reset *** echo [INFO] Proceeding with force reset...
git fetch --all git fetch --all
git reset --hard origin/master git reset --hard origin/%DEFAULT_BRANCH%
git clean -fdx git clean -fdx
echo. echo.
echo * * * Full force reset complete. echo [INFO] Full force reset complete.
echo ====================================================================== call :pausefix
:get_version_info goto show_menu
pause
goto menu
:end :end
cls
echo ======================================================================
echo.
echo Goodbye! ComfyUI-Zluda Update Utility has exited.
echo.
echo ======================================================================
endlocal endlocal
timeout /t 3
exit exit