Find Git and Node when they are installed but off PATH
Git for Windows only adds itself to PATH when "Git from the command line" is selected during install, and an already-open Command Prompt keeps its old PATH regardless — so a correct install still failed the check. Probe the standard install locations before giving up, and when that also fails, say which directories were searched and call out the just-installed case explicitly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
d378712e79
commit
8e64d8a34f
+35
-9
@@ -21,21 +21,47 @@ echo ============================================
|
||||
echo.
|
||||
|
||||
REM ---------------------------------------------------------------- git check
|
||||
REM Git for Windows only adds itself to PATH if "Git from the command line" was
|
||||
REM chosen at install time, and an already-open cmd keeps its old PATH anyway.
|
||||
REM So probe the usual install homes before giving up.
|
||||
where git >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [X] Git is not installed, or not on PATH.
|
||||
echo Install it from https://git-scm.com/download/win then re-run.
|
||||
goto :fail
|
||||
if not errorlevel 1 goto :git_ok
|
||||
if exist "%ProgramFiles%\Git\cmd\git.exe" set "PATH=%ProgramFiles%\Git\cmd;%PATH%"
|
||||
if exist "%ProgramFiles(x86)%\Git\cmd\git.exe" set "PATH=%ProgramFiles(x86)%\Git\cmd;%PATH%"
|
||||
if exist "%LOCALAPPDATA%\Programs\Git\cmd\git.exe" set "PATH=%LOCALAPPDATA%\Programs\Git\cmd;%PATH%"
|
||||
where git >nul 2>&1
|
||||
if not errorlevel 1 (
|
||||
echo [ok] git ^(found off PATH, added for this run^)
|
||||
goto :git_done
|
||||
)
|
||||
echo [X] Git not found on PATH, and not in any of:
|
||||
echo %ProgramFiles%\Git\cmd
|
||||
echo %LOCALAPPDATA%\Programs\Git\cmd
|
||||
echo.
|
||||
echo If Git is NOT installed: https://git-scm.com/download/win
|
||||
echo If you JUST installed it: close this window, open a new Command
|
||||
echo Prompt and run the script again - an open window keeps its old PATH.
|
||||
echo If it is installed elsewhere: check with where git
|
||||
goto :fail
|
||||
:git_ok
|
||||
echo [ok] git
|
||||
:git_done
|
||||
|
||||
REM --------------------------------------------------------------- node check
|
||||
where node >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [X] Node.js is not installed, or not on PATH.
|
||||
echo Install Node 22 LTS from https://nodejs.org/ then re-run.
|
||||
goto :fail
|
||||
)
|
||||
if not errorlevel 1 goto :node_found
|
||||
if exist "%ProgramFiles%\nodejs\node.exe" set "PATH=%ProgramFiles%\nodejs;%PATH%"
|
||||
if exist "%LOCALAPPDATA%\Programs\nodejs\node.exe" set "PATH=%LOCALAPPDATA%\Programs\nodejs;%PATH%"
|
||||
where node >nul 2>&1
|
||||
if not errorlevel 1 goto :node_found
|
||||
echo [X] Node.js not found on PATH, and not in any of:
|
||||
echo %ProgramFiles%\nodejs
|
||||
echo %LOCALAPPDATA%\Programs\nodejs
|
||||
echo.
|
||||
echo Install Node 22 LTS from https://nodejs.org/ then re-run.
|
||||
echo If you JUST installed it, open a NEW Command Prompt first.
|
||||
goto :fail
|
||||
:node_found
|
||||
for /f "tokens=* usebackq" %%v in (`node -p "process.versions.node"`) do set "NODEVER=%%v"
|
||||
for /f "tokens=1 delims=." %%m in ("%NODEVER%") do set "NODEMAJOR=%%m"
|
||||
echo [ok] node v%NODEVER%
|
||||
|
||||
Reference in New Issue
Block a user