forked from Comfy-Org/ComfyUI
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathcfz_update_utility.bat
More file actions
378 lines (347 loc) · 11.8 KB
/
Copy pathcfz_update_utility.bat
File metadata and controls
378 lines (347 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
@echo off
title ComfyUI-Zluda Update Utility v0.5
setlocal enabledelayedexpansion
set "LOG_FILE=cfz_update_utility_log.txt"
set "ENABLE_LOGGING=1"
set "DEFAULT_BRANCH=master"
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
)
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
:manual_git
cls
echo :manual_git=====================================================================
call :log Entered manual_git
echo [INFO] Type any git command below, without "git" prefix, e.g.:
echo --version
echo --help
echo status
echo.
set /p gitcmd=Enter git command:
if /i "%gitcmd:~0,4%"=="git " (
set "gitcmd=%gitcmd:~4%"
)
if "%gitcmd%"=="" (
echo [INFO] No command entered.
call :pausefix
goto manual_git
)
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
)
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.
set /p confirm=Run this command? (Y/N):
call :log User confirmation for git command: %confirm%
if /I not "%confirm%"=="Y" (
echo [INFO] Command canceled.
call :log User canceled the command
call :pausefix
goto show_menu
)
set "fullgitcmd=git %gitcmd%"
echo [EXEC] %fullgitcmd%
echo --------------------------------------------------------------------------------
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 --------------------------------------------------------------------------------
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=" %%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 "tokens=1,2 delims=T" %%x in ("!FULL_DATE!") do (
set "COMMIT_DATE=%%x"
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
: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
call :get_local_version_info
call :get_remote_version_info
goto menu
:menu
cls
echo :menu===========================================================================
echo ComfyUI-Zluda Update Utility v0.5 branch: !BRANCH!
echo ================================================================================
call :log Entered menu
echo 1. Show Updates [Safe] - git fetch, git log
echo 2. Download Updates [Safe] - git fetch, git log, git pull
echo 3. Fix Broken Update [WARN] - git fetch, git reset [Destructive]
echo 4. Force Reset Branch [WARN] - git fetch, git reset, git clean [Destructive]
echo 5. Branch Info [Safe] - git status
echo 6. View Last 50 Commits [Safe] - git log --oneline
echo 7. Switch Branch [Safe] - git checkout
echo 8. Git Command [Adv.] - input a raw git command manually
echo.
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.
set choice=
set /p choice=Choose an option (0-8):
if "%choice%"=="1" goto check_update
if "%choice%"=="2" goto regular_update
if "%choice%"=="3" goto fix_update
if "%choice%"=="4" goto force_reset
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
echo Invalid choice. Please try again...
pause
goto show_menu
:switch_branch
cls
echo :switch_branch==================================================================
call :log Entered switch_branch
echo [INFO] Available branches:
git branch -a
echo.
set /p target_branch=Enter branch name to switch to:
call :log User selected branch: %target_branch%
if "%target_branch%"=="" (
echo [INFO] No branch entered.
call :log User did not enter a branch to switch to
call :pausefix
goto show_menu
)
git checkout "%target_branch%"
call :log Switched to branch: %target_branch%
call :pausefix
goto show_menu
:view_commits
cls
echo :view_commits===================================================================
call :log Entered view_commits
echo [INFO] Last 50 commits:
git --no-pager log --oneline -n 50
call :pausefix
goto show_menu
:status
cls
echo :status=========================================================================
echo LOCAL: !COMMIT_DATE! !COMMIT_TIME! hash: !COMMIT:~0,8!
echo REMOTE: !REMOTE_COMMIT_DATE! !REMOTE_COMMIT_TIME! hash: !REMOTE_COMMIT:~0,8!
echo --------------------------------------------------------------------------------
call :log Entered status
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
echo --------------------------------------------------------------------------------
echo [INFO] Git status (ignored):
git status --ignored -s
echo ================================================================================
call :pausefix
goto show_menu
:check_update
cls
echo :check_update===================================================================
call :log Entered check_update
echo [INFO] Checking for available updates...
git fetch >NUL
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
if NOT "%LOCAL%"=="%REMOTE%" (
echo.
echo [INFO] Update available. New commits:
git --no-pager log --oneline %LOCAL%..%REMOTE%
echo.
echo [INFO] If your branch is "behind", you can run option 2 to update.
) else (
echo [INFO] 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
)
:regular_update
cls
echo :regular_update=================================================================
call :log Entered regular_update
echo [INFO] Checking and updating to a new version if possible...
copy comfy\customzluda\zluda-default.py comfy\zluda.py /y >NUL
call :log Copied zluda-default.py to zluda.py
git fetch >NUL
call :log Starting regular update
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
if NOT "%LOCAL%"=="%REMOTE%" (
echo.
echo [INFO] Update available. New commits:
git --no-pager log --oneline %LOCAL%..%REMOTE% > temp_log_output.txt 2>&1
type temp_log_output.txt
type temp_log_output.txt >> "%LOG_FILE%"
del temp_log_output.txt
call :log New commits between %LOCAL% and %REMOTE%
echo.
echo [INFO] Pulling updates...
git --no-pager pull > temp_pull_output.txt 2>&1
type temp_pull_output.txt
type temp_pull_output.txt >> "%LOG_FILE%"
del temp_pull_output.txt
call :log Pulled updates
echo.
echo [DONE] Update complete.
call :log Update process completed
) else (
echo [INFO] Already up to date.
call :log No update necessary
)
call :pausefix
goto show_menu
:fix_update
cls
echo :fix_update=====================================================================
call :log Entered fix_update
echo [INFO] Fixing broken Git state...
echo.
git fetch --all >> "%LOG_FILE%" 2>&1
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 [INFO] If you see a successful update now, it is done.
call :log fix_update complete
call :pausefix
goto show_menu
:force_reset
cls
echo :force_reset====================================================================
call :log Entered force_reset
echo.
echo WARNING: This will completely reset all changes
echo.
echo --------------------------------------------------------------------------------
echo.
echo This will hard RESET to origin/%DEFAULT_BRANCH%.
echo This includes deleting ALL untracked AND ignored files.
echo.
echo --- Dry run: showing what would be deleted ---
git clean -n -f -d -x
echo --------------------------------------------------------------------------------
echo.
set /p confirm=Are you sure? Type YES to proceed with full reset:
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 [INFO] Proceeding with force reset...
git fetch --all >> "%LOG_FILE%" 2>&1
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%
git clean -fdx >> "%LOG_FILE%" 2>&1
call :log Ran git clean -fdx
echo.
echo [INFO] Full force reset complete.
call :pausefix
goto show_menu
:end
call :log Exiting...
endlocal
exit