autogit.bat 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. @echo off
  2. REM ================================================================
  3. REM autogit - one-click commit and push (double-click to run)
  4. REM
  5. REM KEEP THIS FILE PURE ASCII. No Chinese, no accents, nothing.
  6. REM cmd.exe parses .bat using the OEM code page. A UTF-8 file with
  7. REM non-ASCII bytes gets read as mojibake, and a mangled comment line
  8. REM can end up being executed as a command.
  9. REM Every Chinese message is printed by autogit.py instead.
  10. REM ================================================================
  11. chcp 65001 >nul 2>nul
  12. setlocal
  13. cd /d "%~dp0"
  14. REM Tell python that this .bat owns the final "press any key" pause,
  15. REM so python does not ask for a key twice.
  16. set "AUTOGIT_WRAPPED=1"
  17. set "PY="
  18. REM ---- 1) prefer the py launcher, Microsoft's multi-version entry ----
  19. py -3 -c "import sys;sys.exit(0 if sys.version_info>=(3,8) else 1)" >nul 2>nul
  20. if not errorlevel 1 set "PY=py -3"
  21. REM ---- 2) fall back to python on PATH ----
  22. REM WindowsApps\python.exe is the Microsoft Store stub. It exists on
  23. REM disk but fails unless Python came from the Store, so we must really
  24. REM run it once instead of just checking that the file is present.
  25. if not defined PY (
  26. python -c "import sys;sys.exit(0 if sys.version_info>=(3,8) else 1)" >nul 2>nul
  27. if not errorlevel 1 set "PY=python"
  28. )
  29. if not defined PY (
  30. echo.
  31. echo [FAIL] Python 3.8 or newer was not found.
  32. echo.
  33. echo Install Python, or make sure "py" or "python" is on PATH.
  34. echo Then run this file again.
  35. echo.
  36. pause
  37. exit /b 9009
  38. )
  39. %PY% "%~dp0autogit.py" %*
  40. set "RC=%ERRORLEVEL%"
  41. if not "%RC%"=="0" echo [autogit] exit code %RC%
  42. echo.
  43. pause
  44. exit /b %RC%