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