forked from SillyTavern/SillyTavern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateForkAndStart.bat
103 lines (87 loc) · 2.57 KB
/
UpdateForkAndStart.bat
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
@echo off
@setlocal enabledelayedexpansion
pushd %~dp0
echo Checking Git installation
git --version > nul 2>&1
if %errorlevel% neq 0 (
echo Git is not installed on this system. Skipping update.
echo If you installed with a zip file, you will need to download the new zip and install it manually.
goto end
)
REM Checking current branch
FOR /F "tokens=*" %%i IN ('git rev-parse --abbrev-ref HEAD') DO SET CURRENT_BRANCH=%%i
echo Current branch: %CURRENT_BRANCH%
REM Checking for automatic branch switching configuration
set AUTO_SWITCH=
FOR /F "tokens=*" %%j IN ('git config --local script.autoSwitch') DO SET AUTO_SWITCH=%%j
SET TARGET_BRANCH=%CURRENT_BRANCH%
if NOT "!AUTO_SWITCH!"=="" (
if "!AUTO_SWITCH!"=="s" (
goto autoswitch-staging
)
if "!AUTO_SWITCH!"=="r" (
goto autoswitch-release
)
if "!AUTO_SWITCH!"=="staging" (
:autoswitch-staging
echo Auto-switching to staging branch
git checkout staging
SET TARGET_BRANCH=staging
goto update
)
if "!AUTO_SWITCH!"=="release" (
:autoswitch-release
echo Auto-switching to release branch
git checkout release
SET TARGET_BRANCH=release
goto update
)
echo Auto-switching defined to stay on current branch
goto update
)
if "!CURRENT_BRANCH!"=="staging" (
echo Staying on the current branch
goto update
)
if "!CURRENT_BRANCH!"=="release" (
echo Staying on the current branch
goto update
)
echo You are not on 'staging' or 'release'. You are on '!CURRENT_BRANCH!'.
set /p "CHOICE=Do you want to switch to 'staging' (s), 'release' (r), or stay (any other key)? "
if /i "!CHOICE!"=="s" (
echo Switching to staging branch
git checkout staging
SET TARGET_BRANCH=staging
goto update
)
if /i "!CHOICE!"=="r" (
echo Switching to release branch
git checkout release
SET TARGET_BRANCH=release
goto update
)
echo Staying on the current branch
:update
REM Checking for 'upstream' remote
git remote | findstr "upstream" > nul
if %errorlevel% equ 0 (
echo Updating and rebasing against 'upstream'
git fetch upstream
git rebase upstream/%TARGET_BRANCH% --autostash
goto install
)
echo Updating and rebasing against 'origin'
git pull --rebase --autostash origin %TARGET_BRANCH%
:install
if %errorlevel% neq 0 (
echo There were errors while updating. Please check manually.
goto end
)
echo Installing npm packages and starting server
set NODE_ENV=production
call npm install --no-audit --no-fund --loglevel=error --no-progress --omit=dev
node server.js %*
:end
pause
popd