Blame Raw
Cohee · 51ad27fb · · 110 lines (2.8 KB)
1 contributor
1@echo off
2@setlocal enabledelayedexpansion
3pushd %~dp0
4
5echo Checking Git installation
6git --version > nul 2>&1
7if %errorlevel% neq 0 (
8 echo Git is not installed on this system.
9 echo Install it from https://git-scm.com/downloads
10 goto end
11)
12
13if not exist .git (
14 echo Not running from a Git repository. Reinstall using an officially supported method to get updates.
15 echo See: https://docs.sillytavern.app/installation/windows/
16 goto end
17)
18
19REM Checking current branch
20FOR /F "tokens=*" %%i IN ('git rev-parse --abbrev-ref HEAD') DO SET CURRENT_BRANCH=%%i
21echo Current branch: %CURRENT_BRANCH%
22
23REM Checking for automatic branch switching configuration
24set AUTO_SWITCH=
25FOR /F "tokens=*" %%j IN ('git config --local script.autoSwitch') DO SET AUTO_SWITCH=%%j
26
27SET TARGET_BRANCH=%CURRENT_BRANCH%
28
29if NOT "!AUTO_SWITCH!"=="" (
30 if "!AUTO_SWITCH!"=="s" (
31 goto autoswitch-staging
32 )
33 if "!AUTO_SWITCH!"=="r" (
34 goto autoswitch-release
35 )
36
37 if "!AUTO_SWITCH!"=="staging" (
38 :autoswitch-staging
39 echo Auto-switching to staging branch
40 git checkout staging
41 SET TARGET_BRANCH=staging
42 goto update
43 )
44 if "!AUTO_SWITCH!"=="release" (
45 :autoswitch-release
46 echo Auto-switching to release branch
47 git checkout release
48 SET TARGET_BRANCH=release
49 goto update
50 )
51
52 echo Auto-switching defined to stay on current branch
53 goto update
54)
55
56if "!CURRENT_BRANCH!"=="staging" (
57 echo Staying on the current branch
58 goto update
59)
60if "!CURRENT_BRANCH!"=="release" (
61 echo Staying on the current branch
62 goto update
63)
64
65echo You are not on 'staging' or 'release'. You are on '!CURRENT_BRANCH!'.
66set /p "CHOICE=Do you want to switch to 'staging' (s), 'release' (r), or stay (any other key)? "
67if /i "!CHOICE!"=="s" (
68 echo Switching to staging branch
69 git checkout staging
70 SET TARGET_BRANCH=staging
71 goto update
72)
73if /i "!CHOICE!"=="r" (
74 echo Switching to release branch
75 git checkout release
76 SET TARGET_BRANCH=release
77 goto update
78)
79
80echo Staying on the current branch
81
82:update
83REM Checking for 'upstream' remote
84git remote | findstr "upstream" > nul
85if %errorlevel% equ 0 (
86 echo Updating and rebasing against 'upstream'
87 git fetch upstream
88 git rebase upstream/%TARGET_BRANCH% --autostash
89 goto install
90)
91
92echo Updating and rebasing against 'origin'
93git pull --rebase --autostash origin %TARGET_BRANCH%
94
95
96:install
97if %errorlevel% neq 0 (
98 echo There were errors while updating.
99 echo See the update FAQ at https://docs.sillytavern.app/usage/update/#common-update-problems
100 goto end
101)
102
103echo Installing npm packages and starting server
104set NODE_ENV=production
105call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
106node server.js %*
107
108:end
109pause
110popd