Update cfz_update_utility.bat (logging)

- added basic logging in case batch skips pause on critical option
  (e.g. pulling update or on force reset)
This commit is contained in:
Rando717 2025-10-09 11:29:35 +02:00 committed by GitHub
parent 54186b1225
commit 033932ba4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,10 @@
@echo off @echo off
title ComfyUI-Zluda Update Utility v0.4 title ComfyUI-Zluda Update Utility v0.5
setlocal enabledelayedexpansion setlocal enabledelayedexpansion
set "LOG_FILE=cfz_update_utility_log.txt"
set "ENABLE_LOGGING=1"
set "DEFAULT_BRANCH=master" set "DEFAULT_BRANCH=master"
set "BRANCH=" set "BRANCH="
@ -20,17 +23,37 @@ if ERRORLEVEL 1 (
pause pause
exit /b exit /b
) )
for /f "tokens=2,3 delims= " %%a in ("%date% %time%") do (
set "LOG_DATE=%%a"
set "LOG_TIME=%%b"
)
set "LOG_TIME=!LOG_TIME:~0,8!"
>> "%LOG_FILE%" (
echo.
echo [START] ComfyUI-Zluda Update Utility Log
echo [DATE] !LOG_DATE! !LOG_TIME!
echo ========================================================
)
goto show_menu goto show_menu
:manual_git :manual_git
cls cls
echo :manual_git===================================================================== echo :manual_git=====================================================================
echo [INFO] Type any git command below, e.g.: call :log Entered manual_git
echo [INFO] Type any git command below, without "git" prefix, e.g.:
echo --version echo --version
echo --help echo --help
echo status echo status
echo. echo.
set /p gitcmd=git
set /p gitcmd=Enter git command:
if /i "%gitcmd:~0,4%"=="git " (
set "gitcmd=%gitcmd:~4%"
)
if "%gitcmd%"=="" ( if "%gitcmd%"=="" (
echo [INFO] No command entered. echo [INFO] No command entered.
@ -38,7 +61,6 @@ if "%gitcmd%"=="" (
goto manual_git goto manual_git
) )
echo.
echo %gitcmd% | findstr /R /I "\<reset\> \<clean\> \<rebase\>" >nul echo %gitcmd% | findstr /R /I "\<reset\> \<clean\> \<rebase\>" >nul
if %errorlevel%==0 ( if %errorlevel%==0 (
echo [WARN] Destructive commands are not allowed here. echo [WARN] Destructive commands are not allowed here.
@ -46,17 +68,34 @@ if %errorlevel%==0 (
goto show_menu goto show_menu
) )
set "CHECK_HELP=%gitcmd:--help=%"
if not "%CHECK_HELP%"=="%gitcmd%" (
echo [WARN] 'git --help' may open a separate window or fail to display in this console.
)
echo. echo.
set /p confirm=Run this command? (Y/N): set /p confirm=Run this command? (Y/N):
call :log User confirmation for git command: %confirm%
if /I not "%confirm%"=="Y" ( if /I not "%confirm%"=="Y" (
echo [INFO] Command canceled. echo [INFO] Command canceled.
call :log User canceled the command
call :pausefix call :pausefix
goto show_menu goto show_menu
) )
echo [EXEC] git %gitcmd% set "fullgitcmd=git %gitcmd%"
echo [EXEC] %fullgitcmd%
echo -------------------------------------------------------------------------------- echo --------------------------------------------------------------------------------
git %gitcmd% set "TMP_FILE=%TEMP%\git_output.tmp"
%fullgitcmd% > "%TMP_FILE%" 2>&1
if exist "%TMP_FILE%" (
type "%TMP_FILE%"
type "%TMP_FILE%" >> "%LOG_FILE%"
del "%TMP_FILE%"
) else (
echo [WARN] Output file not found. Git may have launched an external viewer.
)
call :log Ran manual git command: %fullgitcmd%
echo -------------------------------------------------------------------------------- echo --------------------------------------------------------------------------------
call :pausefix call :pausefix
goto show_menu goto show_menu
@ -91,6 +130,19 @@ if %errorlevel%==0 (
) )
exit /b exit /b
:log
if "%ENABLE_LOGGING%"=="1" (
setlocal enabledelayedexpansion
for /f "tokens=2,3 delims= " %%a in ("%date% %time%") do (
set "LOG_DATE=%%a"
set "LOG_TIME=%%b"
)
set "LOG_TIME=!LOG_TIME:~0,8!"
echo [!LOG_DATE! !LOG_TIME!] %* >> "%LOG_FILE%"
endlocal
)
exit /b
:show_menu :show_menu
call :get_local_version_info call :get_local_version_info
call :get_remote_version_info call :get_remote_version_info
@ -99,8 +151,9 @@ goto menu
:menu :menu
cls cls
echo :menu=========================================================================== echo :menu===========================================================================
echo ComfyUI-Zluda Update Utility v0.4 branch: !BRANCH! echo ComfyUI-Zluda Update Utility v0.5 branch: !BRANCH!
echo ================================================================================ echo ================================================================================
call :log Entered menu
echo 1. Show Updates [Safe] - git fetch, git log echo 1. Show Updates [Safe] - git fetch, git log
echo 2. Download Updates [Safe] - git fetch, git log, git pull echo 2. Download Updates [Safe] - git fetch, git log, git pull
echo 3. Fix Broken Update [WARN] - git fetch, git reset [Destructive] echo 3. Fix Broken Update [WARN] - git fetch, git reset [Destructive]
@ -142,22 +195,27 @@ goto show_menu
:switch_branch :switch_branch
cls cls
echo :switch_branch================================================================== echo :switch_branch==================================================================
call :log Entered switch_branch
echo [INFO] Available branches: echo [INFO] Available branches:
git branch -a git branch -a
echo. echo.
set /p target_branch=Enter branch name to switch to: set /p target_branch=Enter branch name to switch to:
call :log User selected branch: %target_branch%
if "%target_branch%"=="" ( if "%target_branch%"=="" (
echo [INFO] No branch entered. echo [INFO] No branch entered.
call :log User did not enter a branch to switch to
call :pausefix call :pausefix
goto show_menu goto show_menu
) )
git checkout "%target_branch%" git checkout "%target_branch%"
call :log Switched to branch: %target_branch%
call :pausefix call :pausefix
goto show_menu goto show_menu
:view_commits :view_commits
cls cls
echo :view_commits=================================================================== echo :view_commits===================================================================
call :log Entered view_commits
echo [INFO] Last 50 commits: echo [INFO] Last 50 commits:
git --no-pager log --oneline -n 50 git --no-pager log --oneline -n 50
call :pausefix call :pausefix
@ -169,7 +227,7 @@ echo :status====================================================================
echo LOCAL: !COMMIT_DATE! !COMMIT_TIME! hash: !COMMIT:~0,8! echo LOCAL: !COMMIT_DATE! !COMMIT_TIME! hash: !COMMIT:~0,8!
echo REMOTE: !REMOTE_COMMIT_DATE! !REMOTE_COMMIT_TIME! hash: !REMOTE_COMMIT:~0,8! echo REMOTE: !REMOTE_COMMIT_DATE! !REMOTE_COMMIT_TIME! hash: !REMOTE_COMMIT:~0,8!
echo -------------------------------------------------------------------------------- echo --------------------------------------------------------------------------------
call :log Entered status
git rev-parse --abbrev-ref --symbolic-full-name @{u} >nul 2>&1 git rev-parse --abbrev-ref --symbolic-full-name @{u} >nul 2>&1
if errorlevel 1 ( if errorlevel 1 (
echo [WARN] No upstream tracking branch set. echo [WARN] No upstream tracking branch set.
@ -203,6 +261,7 @@ goto show_menu
:check_update :check_update
cls cls
echo :check_update=================================================================== echo :check_update===================================================================
call :log Entered check_update
echo [INFO] Checking for available updates... echo [INFO] Checking for available updates...
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
@ -227,22 +286,30 @@ for /f %%s in ('git status --porcelain') do (
:regular_update :regular_update
cls cls
echo :regular_update================================================================= echo :regular_update=================================================================
call :log Entered regular_update
echo [INFO] Checking and updating to a new version if possible... echo [INFO] Checking and updating to a new version if possible...
copy comfy\customzluda\zluda-default.py comfy\zluda.py /y >NUL copy comfy\customzluda\zluda-default.py comfy\zluda.py /y >NUL
call :log Copied zluda-default.py to zluda.py
git fetch >NUL git fetch >NUL
call :log Starting regular update
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 [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%
git --no-pager log --oneline %LOCAL%..%REMOTE% >> "%LOG_FILE%" 2>&1
call :log New commits between %LOCAL% and %REMOTE%
echo. echo.
echo [INFO] Pulling updates... echo [INFO] Pulling updates...
git --no-pager pull git --no-pager pull >> "%LOG_FILE%" 2>&1
call :log Pulled updates
echo. echo.
echo [DONE] Update complete. echo [DONE] Update complete.
call :log Update process completed
) else ( ) else (
echo [INFO] Already up to date. echo [INFO] Already up to date.
call :log No update necessary
) )
call :pausefix call :pausefix
goto show_menu goto show_menu
@ -250,18 +317,23 @@ goto show_menu
:fix_update :fix_update
cls cls
echo :fix_update===================================================================== echo :fix_update=====================================================================
call :log Entered fix_update
echo [INFO] Fixing broken Git state... echo [INFO] Fixing broken Git state...
echo. echo.
git fetch --all git fetch --all >> "%LOG_FILE%" 2>&1
git reset --hard origin/%DEFAULT_BRANCH% call :log Ran git fetch --all
git reset --hard origin/%DEFAULT_BRANCH% >> "%LOG_FILE%" 2>&1
call :log Ran git reset --hard origin/%DEFAULT_BRANCH%
echo. echo.
echo [INFO] If you see a successful update now, it is done. echo [INFO] If you see a successful update now, it is done.
call :log fix_update complete
call :pausefix call :pausefix
goto show_menu goto show_menu
:force_reset :force_reset
cls cls
echo :force_reset==================================================================== echo :force_reset====================================================================
call :log Entered force_reset
echo. echo.
echo WARNING: This will completely reset all changes echo WARNING: This will completely reset all changes
echo. echo.
@ -275,17 +347,27 @@ 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 show_menu
if /I not "%confirm%"=="YES" (
call :log User canceled force reset with input: %confirm%
goto show_menu
)
call :log User confirmed force reset: %confirm%
echo. echo.
echo [INFO] Proceeding with force reset... echo [INFO] Proceeding with force reset...
git fetch --all git fetch --all >> "%LOG_FILE%" 2>&1
git reset --hard origin/%DEFAULT_BRANCH% call :log Ran git fetch --all
git clean -fdx git reset --hard origin/%DEFAULT_BRANCH% >> "%LOG_FILE%" 2>&1
call :log Ran git reset --hard origin/%DEFAULT_BRANCH%
git clean -fdx >> "%LOG_FILE%" 2>&1
call :log Ran git clean -fdx
echo. echo.
echo [INFO] Full force reset complete. echo [INFO] Full force reset complete.
call :pausefix call :pausefix
goto show_menu goto show_menu
:end :end
call :log Exiting...
endlocal endlocal
exit exit