@echo off
chcp 65001
color a

echo Starting UPM package update...
echo Please make sure all changes are committed!

:: Get version from package.json
for /f "tokens=2 delims=:, " %%i in ('findstr "version" Assets\package.json') do (
    set version=%%i
)
set version=%version:"=%

echo.
echo Current version: %version%
echo.
set /p confirm=Confirm to create UPM branch and tag %version% (y/n): 

if /i not "%confirm%"=="y" (
    echo Operation cancelled.
    goto :END
)

:: Clean and prepare
git checkout -f master
git branch -D upm 2>nul

:: Create and push upm branch
git subtree split --prefix Assets --branch upm
git push -f origin upm

:: Create and push tag
git tag -d %version% 2>nul
git tag %version% upm
git push origin %version%

:: Return to master
git checkout -f master

echo.
echo Successfully created UPM branch and tag %version%

:END
pause