refactor: simplify update.bat output

Minimal display, concise success/fail/up-to-date banner.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
This commit is contained in:
o1key
2026-04-03 16:33:04 +08:00
co-authored by Claude Sonnet 4.5
parent 0b9a1ebf7a
commit 2b64a45b8e
+48 -103
View File
@@ -1,128 +1,73 @@
@echo off @echo off
setlocal EnableDelayedExpansion setlocal EnableDelayedExpansion
title comfyui_o1key Updater title comfyui_o1key Updater
:: Change to the directory where this .bat file lives
cd /d "%~dp0" cd /d "%~dp0"
echo. echo.
echo ================================================ echo [ comfyui_o1key Updater ]
echo comfyui_o1key Auto Updater
echo ================================================
echo. echo.
:: ── 1. Check git is installed ───────────────────────────────────────── :: Check git
where git >nul 2>&1 where git >nul 2>&1
if errorlevel 1 ( if errorlevel 1 ( set "ERR=Git not found in PATH." & goto :fail )
set "STATUS=FAILED"
set "REASON=Git is not installed or not in PATH."
goto :done
)
:: ── 2. Confirm this is a git repo ───────────────────────────────────── :: Check repo
if not exist ".git" ( if not exist ".git" ( set "ERR=Not a git repo. Place this file in the plugin root." & goto :fail )
set "STATUS=FAILED"
set "REASON=.git folder not found. Make sure this .bat is in the plugin root."
goto :done
)
:: ── 3. Show current version ─────────────────────────────────────────── :: Save old hash
echo [INFO] Current version: for /f %%i in ('git rev-parse --short HEAD 2^>nul') do set "OLD=%%i"
for /f %%i in ('git rev-parse --short HEAD 2^>nul') do set "OLD_HASH=%%i"
for /f "delims=" %%i in ('git log -1 --format^="%%ci" 2^>nul') do set "OLD_DATE=%%i"
echo Hash : %OLD_HASH%
echo Date : %OLD_DATE%
echo.
:: ── 4. Back up .config if it exists ─────────────────────────────────── :: Backup .config
if exist ".config" ( if exist ".config" copy /y ".config" ".config.bak" >nul 2>&1
copy /y ".config" ".config.bak" >nul 2>&1
echo [INFO] .config backed up (API key will be restored after update)
echo.
)
:: ── 5. Fetch latest from GitHub ─────────────────────────────────────── :: Fetch
echo [INFO] Fetching from GitHub... echo Fetching...
git fetch origin 2>&1 git fetch origin >nul 2>&1
if errorlevel 1 ( if errorlevel 1 ( set "ERR=Network error. Check GitHub access." & goto :fail )
set "STATUS=FAILED"
set "REASON=git fetch failed. Check your network / GitHub access."
goto :restore_config
)
echo.
:: ── 6. Check if already up to date ─────────────────────────────────── :: Already up to date?
for /f %%i in ('git rev-parse HEAD 2^>nul') do set "LOCAL=%%i" for /f %%i in ('git rev-parse HEAD 2^>nul') do set "LOCAL=%%i"
for /f %%i in ('git rev-parse origin/main 2^>nul') do set "REMOTE=%%i" for /f %%i in ('git rev-parse origin/main 2^>nul') do set "REMOTE=%%i"
if "%LOCAL%"=="%REMOTE%" ( if "%LOCAL%"=="%REMOTE%" ( goto :uptodate )
set "STATUS=UP-TO-DATE"
set "REASON=Already on the latest version. No update needed."
goto :restore_config
)
:: ── 7. Show incoming changes ────────────────────────────────────────── :: Switch branch & force reset
echo [INFO] Incoming changes:
git log HEAD..origin/main --oneline 2>&1
echo.
:: ── 8. Switch to / create local main branch ───────────────────────────
git branch --list main | findstr "main" >nul 2>&1 git branch --list main | findstr "main" >nul 2>&1
if errorlevel 1 ( if errorlevel 1 ( git checkout -b main origin/main >nul 2>&1 ) else ( git checkout main >nul 2>&1 )
git checkout -b main origin/main >nul 2>&1
) else (
git checkout main >nul 2>&1
)
:: ── 9. Force reset to remote main (handles cross-version gaps) ──────── echo Updating...
echo [INFO] Applying update... git reset --hard origin/main >nul 2>&1
git reset --hard origin/main 2>&1 if errorlevel 1 ( set "ERR=git reset failed." & goto :fail )
if errorlevel 1 ( git clean -fd -e ".config" -e ".config.bak" >nul 2>&1
set "STATUS=FAILED"
set "REASON=git reset --hard failed."
goto :restore_config
)
:: ── 10. Clean untracked files (keep .config) ────────────────────────── :: Restore .config
git clean -fd -e ".config" -e ".config.bak" 2>&1 if exist ".config.bak" ( copy /y ".config.bak" ".config" >nul 2>&1 & del /f /q ".config.bak" >nul 2>&1 )
for /f %%i in ('git rev-parse --short HEAD 2^>nul') do set "NEW=%%i"
echo. echo.
echo +---------------------------+
set "STATUS=SUCCESS" echo ^| SUCCESS ^|
echo ^| %OLD% -> %NEW% ^|
:restore_config echo ^| Restart ComfyUI ^|
:: ── Restore .config ─────────────────────────────────────────────────── echo +---------------------------+
if exist ".config.bak" (
copy /y ".config.bak" ".config" >nul 2>&1
del /f /q ".config.bak" >nul 2>&1
if "%STATUS%"=="SUCCESS" (
echo [INFO] .config restored (API key unchanged)
echo. echo.
) pause & exit /b 0
)
:done :uptodate
:: ── Final status banner ─────────────────────────────────────────────── if exist ".config.bak" ( copy /y ".config.bak" ".config" >nul 2>&1 & del /f /q ".config.bak" >nul 2>&1 )
echo. echo.
if "%STATUS%"=="SUCCESS" ( echo +---------------------------+
echo ================================================ echo ^| Already up to date ^|
echo RESULT : UPDATE SUCCESSFUL echo ^| %LOCAL:~0,7% (no change) ^|
for /f %%i in ('git rev-parse --short HEAD 2^>nul') do set "NEW_HASH=%%i" echo +---------------------------+
for /f "delims=" %%i in ('git log -1 --format^="%%ci" 2^>nul') do set "NEW_DATE=%%i"
echo Old : %OLD_HASH% ^(%OLD_DATE%^)
echo New : !NEW_HASH! ^(!NEW_DATE!^)
echo Action : Please restart ComfyUI to load the new plugin.
echo ================================================
) else if "%STATUS%"=="UP-TO-DATE" (
echo ================================================
echo RESULT : ALREADY UP TO DATE
echo Hash : %LOCAL%
echo Info : %REASON%
echo ================================================
) else (
echo ================================================
echo RESULT : UPDATE FAILED
echo Reason : %REASON%
echo ================================================
)
echo. echo.
pause pause & exit /b 0
endlocal
:fail
if exist ".config.bak" ( copy /y ".config.bak" ".config" >nul 2>&1 & del /f /q ".config.bak" >nul 2>&1 )
echo.
echo +---------------------------+
echo ^| FAILED ^|
echo ^| %ERR%
echo +---------------------------+
echo.
pause & exit /b 1