mirror of
https://github.com/cmderdev/cmder.git
synced 2024-11-10 17:59:11 +08:00
fixes
This commit is contained in:
parent
db42252ef2
commit
468dba474e
101
vendor/init.bat
vendored
101
vendor/init.bat
vendored
@ -181,54 +181,14 @@ if defined GIT_INSTALL_ROOT (
|
|||||||
%lib_git% validate_version VENDORED %GIT_VERSION_VENDORED%
|
%lib_git% validate_version VENDORED %GIT_VERSION_VENDORED%
|
||||||
|
|
||||||
:: check if git is in path...
|
:: check if git is in path...
|
||||||
setlocal enabledelayedexpansion
|
|
||||||
for /F "delims=" %%F in ('where git.exe 2^>nul') do (
|
for /F "delims=" %%F in ('where git.exe 2^>nul') do (
|
||||||
:: get the absolute path to the user provided git binary
|
:: get the absolute path to the user provided git binary
|
||||||
pushd %%~dpF
|
call :is_git_shim "%%~dpF"
|
||||||
:: check if there's shim - and if yes follow the path
|
call :get_user_git_version
|
||||||
if exist git.shim (
|
call :compare_git_versions
|
||||||
for /F "tokens=2 delims== " %%I in (git.shim) do (
|
|
||||||
pushd %%~dpI
|
|
||||||
set "test_dir=!CD!"
|
|
||||||
popd
|
|
||||||
)
|
)
|
||||||
) else (
|
|
||||||
set "test_dir=!CD!"
|
|
||||||
)
|
|
||||||
popd
|
|
||||||
|
|
||||||
:: get the version information for the user provided git binary
|
|
||||||
%lib_git% read_version USER "!test_dir!"
|
|
||||||
%lib_git% validate_version USER !GIT_VERSION_USER!
|
|
||||||
|
|
||||||
if !errorlevel! geq 0 (
|
|
||||||
:: compare the user git version against the vendored version
|
|
||||||
%lib_git% compare_versions USER VENDORED
|
|
||||||
|
|
||||||
:: use the user provided git if its version is greater than, or equal to the vendored git
|
|
||||||
if !errorlevel! geq 0 if exist "!test_dir:~0,-4!\cmd\git.exe" (
|
|
||||||
set "GIT_INSTALL_ROOT=!test_dir:~0,-4!"
|
|
||||||
set test_dir=
|
|
||||||
goto :FOUND_GIT
|
|
||||||
) else if !errorlevel! geq 0 (
|
|
||||||
set "GIT_INSTALL_ROOT=!test_dir!"
|
|
||||||
set test_dir=
|
|
||||||
goto :FOUND_GIT
|
|
||||||
) else (
|
|
||||||
call :verbose_output Found old !GIT_VERSION_USER! in "!test_dir!", but not using...
|
|
||||||
set test_dir=
|
|
||||||
)
|
|
||||||
) else (
|
|
||||||
:: if the user provided git executable is not found
|
|
||||||
if !errorlevel! equ -255 (
|
|
||||||
call :verbose_output No git at "!git_executable!" found.
|
|
||||||
set test_dir=
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
endlocal & set "GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT%" & set "GIT_VERSION_VENDORED=%GIT_VERSION_VENDORED%"
|
|
||||||
|
|
||||||
:: our last hope: our own git...
|
|
||||||
:VENDORED_GIT
|
:VENDORED_GIT
|
||||||
if exist "%CMDER_ROOT%\vendor\git-for-windows" (
|
if exist "%CMDER_ROOT%\vendor\git-for-windows" (
|
||||||
set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows"
|
set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows"
|
||||||
@ -242,7 +202,7 @@ if exist "%CMDER_ROOT%\vendor\git-for-windows" (
|
|||||||
goto :CONFIGURE_GIT
|
goto :CONFIGURE_GIT
|
||||||
|
|
||||||
:FOUND_GIT
|
:FOUND_GIT
|
||||||
%lib_console% debug_output "Using found Git '!GIT_VERSION_USER!' from '%GIT_INSTALL_ROOT%..."
|
%lib_console% debug_output "Using found Git '%GIT_VERSION_USER%' from '%GIT_INSTALL_ROOT%..."
|
||||||
goto :CONFIGURE_GIT
|
goto :CONFIGURE_GIT
|
||||||
|
|
||||||
:CONFIGURE_GIT
|
:CONFIGURE_GIT
|
||||||
@ -407,3 +367,56 @@ if %time_init% gtr 0 (
|
|||||||
"%cmder_root%\vendor\bin\timer.cmd" %CMDER_INIT_START% %CMDER_INIT_END%
|
"%cmder_root%\vendor\bin\timer.cmd" %CMDER_INIT_START% %CMDER_INIT_END%
|
||||||
)
|
)
|
||||||
exit /b
|
exit /b
|
||||||
|
|
||||||
|
:is_git_shim
|
||||||
|
pushd "%~1"
|
||||||
|
:: check if there's shim - and if yes follow the path
|
||||||
|
setlocal enabledelayedexpansion
|
||||||
|
if exist git.shim (
|
||||||
|
for /F "tokens=2 delims== " %%I in (git.shim) do (
|
||||||
|
pushd %%~dpI
|
||||||
|
set "test_dir=!CD!"
|
||||||
|
popd
|
||||||
|
)
|
||||||
|
) else (
|
||||||
|
set "test_dir=!CD!"
|
||||||
|
)
|
||||||
|
endlocal & set "test_dir=%test_dir%"
|
||||||
|
|
||||||
|
popd
|
||||||
|
exit /b
|
||||||
|
|
||||||
|
:compare_git_versions
|
||||||
|
if %errorlevel% geq 0 (
|
||||||
|
:: compare the user git version against the vendored version
|
||||||
|
%lib_git% compare_versions USER VENDORED
|
||||||
|
|
||||||
|
:: use the user provided git if its version is greater than, or equal to the vendored git
|
||||||
|
if %errorlevel% geq 0 if exist "%test_dir:~0,-4%\cmd\git.exe" (
|
||||||
|
set "GIT_INSTALL_ROOT=%test_dir:~0,-4%"
|
||||||
|
set test_dir=
|
||||||
|
goto :FOUND_GIT
|
||||||
|
) else if %errorlevel% geq 0 (
|
||||||
|
set "GIT_INSTALL_ROOT=%test_dir%"
|
||||||
|
set test_dir=
|
||||||
|
goto :FOUND_GIT
|
||||||
|
) else (
|
||||||
|
call :verbose_output Found old %GIT_VERSION_USER% in "%test_dir%", but not using...
|
||||||
|
set test_dir=
|
||||||
|
)
|
||||||
|
) else (
|
||||||
|
:: if the user provided git executable is not found
|
||||||
|
if %errorlevel% equ -255 (
|
||||||
|
call :verbose_output No git at "%git_executable%" found.
|
||||||
|
set test_dir=
|
||||||
|
)
|
||||||
|
)
|
||||||
|
exit /b
|
||||||
|
|
||||||
|
:get_user_git_version
|
||||||
|
|
||||||
|
:: get the version information for the user provided git binary
|
||||||
|
%lib_git% read_version USER "%test_dir%"
|
||||||
|
%lib_git% validate_version USER %GIT_VERSION_USER%
|
||||||
|
exit /b
|
||||||
|
|
||||||
|
55
vendor/lib/lib_git.cmd
vendored
55
vendor/lib/lib_git.cmd
vendored
@ -34,7 +34,6 @@ exit /b
|
|||||||
::: GIT_VERSION_[GIT SCOPE] <out> Env variable containing Git semantic version string
|
::: GIT_VERSION_[GIT SCOPE] <out> Env variable containing Git semantic version string
|
||||||
:::-------------------------------------------------------------------------------
|
:::-------------------------------------------------------------------------------
|
||||||
|
|
||||||
setlocal enabledelayedexpansion
|
|
||||||
:: clear the variables
|
:: clear the variables
|
||||||
set GIT_VERSION_%~1=
|
set GIT_VERSION_%~1=
|
||||||
|
|
||||||
@ -49,18 +48,20 @@ exit /b
|
|||||||
)
|
)
|
||||||
|
|
||||||
:: get the git version in the provided directory
|
:: get the git version in the provided directory
|
||||||
for /F "tokens=1,2,3 usebackq" %%A in (`"%git_executable%" --version 2^>nul`) do (
|
|
||||||
|
"%git_executable%" --version > "%temp%\git_version.txt"
|
||||||
|
setlocal enabledelayedexpansion
|
||||||
|
for /F "tokens=1,2,3 usebackq" %%A in (`type "%temp%\git_version.txt" 2^>nul`) do (
|
||||||
if /i "%%A %%B" == "git version" (
|
if /i "%%A %%B" == "git version" (
|
||||||
set "GIT_VERSION=%%C"
|
set "GIT_VERSION=%%C"
|
||||||
%lib_console% debug_output :read_version "Env Var - GIT_VERSION_%~1=!GIT_VERSION!"
|
|
||||||
) else (
|
) else (
|
||||||
%lib_console% show_error "git --version" returned an inproper version string!
|
echo "'git --version' returned an inproper version string!"
|
||||||
pause
|
pause
|
||||||
exit /b
|
exit /b
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
endlocal & set "GIT_VERSION_%~1=%GIT_VERSION%" & %lib_console% debug_output :read_version "Env Var - GIT_VERSION_%~1=%GIT_VERSION%"
|
||||||
|
|
||||||
endlocal & set "GIT_VERSION_%~1=%GIT_VERSION%"
|
|
||||||
exit /b
|
exit /b
|
||||||
|
|
||||||
:parse_version
|
:parse_version
|
||||||
@ -88,9 +89,10 @@ exit /b
|
|||||||
::: [SCOPE]_BUILD <out> Scoped Build version.
|
::: [SCOPE]_BUILD <out> Scoped Build version.
|
||||||
:::-------------------------------------------------------------------------------
|
:::-------------------------------------------------------------------------------
|
||||||
|
|
||||||
setlocal enabledelayedexpansion
|
|
||||||
:: process a `x.x.x.xxxx.x` formatted string
|
:: process a `x.x.x.xxxx.x` formatted string
|
||||||
%lib_console% debug_output :parse_version "ARGV[1]=%~1, ARGV[2]=%~2"
|
%lib_console% debug_output :parse_version "ARGV[1]=%~1, ARGV[2]=%~2"
|
||||||
|
|
||||||
|
setlocal enabledelayedexpansion
|
||||||
for /F "tokens=1-3* delims=.,-" %%A in ("%2") do (
|
for /F "tokens=1-3* delims=.,-" %%A in ("%2") do (
|
||||||
set "%~1_MAJOR=%%A"
|
set "%~1_MAJOR=%%A"
|
||||||
set "%~1_MINOR=%%B"
|
set "%~1_MINOR=%%B"
|
||||||
@ -98,9 +100,17 @@ exit /b
|
|||||||
set "%~1_BUILD=%%D"
|
set "%~1_BUILD=%%D"
|
||||||
)
|
)
|
||||||
|
|
||||||
endlocal & set "%~1_MAJOR=!%~1_MAJOR!" & set "%~1_MINOR=!%~1_MINOR!" & set "%~1_PATCH=!%~1_PATCH!" & set "%~1_BUILD=!%~1_BUILD!"
|
REM endlocal & set "%~1_MAJOR=!%~1_MAJOR!" & set "%~1_MINOR=!%~1_MINOR!" & set "%~1_PATCH=!%~1_PATCH!" & set "%~1_BUILD=!%~1_BUILD!"
|
||||||
|
if "%~1" == "VENDORED" (
|
||||||
|
endlocal & set "%~1_MAJOR=%VENDORED_MAJOR%" & set "%~1_MINOR=%VENDORED_MINOR%" & set "%~1_PATCH=%VENDORED_PATCH%" & set "%~1_BUILD=%VENDORED_BUILD%"
|
||||||
|
) else (
|
||||||
|
endlocal & set "%~1_MAJOR=%USER_MAJOR%" & set "%~1_MINOR=%USER_MINOR%" & set "%~1_PATCH=%USER_PATCH%" & set "%~1_BUILD=%USER_BUILD%"
|
||||||
|
)
|
||||||
|
|
||||||
exit /b
|
exit /b
|
||||||
|
|
||||||
|
:endlocal_set_git_version
|
||||||
|
|
||||||
:validate_version
|
:validate_version
|
||||||
:::===============================================================================
|
:::===============================================================================
|
||||||
:::validate_version - Validate semantic version string 'x.x.x.x'.
|
:::validate_version - Validate semantic version string 'x.x.x.x'.
|
||||||
@ -121,10 +131,16 @@ exit /b
|
|||||||
|
|
||||||
:: now parse the version information into the corresponding variables
|
:: now parse the version information into the corresponding variables
|
||||||
%lib_console% debug_output :validate_version "ARGV[1]=%~1, ARGV[2]=%~2"
|
%lib_console% debug_output :validate_version "ARGV[1]=%~1, ARGV[2]=%~2"
|
||||||
|
|
||||||
call :parse_version %~1 %~2
|
call :parse_version %~1 %~2
|
||||||
|
|
||||||
:: ... and maybe display it, for debugging purposes.
|
:: ... and maybe display it, for debugging purposes.
|
||||||
%lib_console% debug_output :validate_version "Found Git Version for %~1: !%~1_MAJOR!.!%~1_MINOR!.!%~1_PATCH!.!%~1_BUILD!"
|
REM %lib_console% debug_output :validate_version "Found Git Version for %~1: !%~1_MAJOR!.!%~1_MINOR!.!%~1_PATCH!.!%~1_BUILD!"
|
||||||
|
if "%~1" == "VENDORED" (
|
||||||
|
%lib_console% debug_output :validate_version "Found Git Version for %~1: %VENDORED_MAJOR%.%VENDORED_MINOR%.%VENDORED_PATCH%.%VENDORED_BUILD%"
|
||||||
|
) else (
|
||||||
|
%lib_console% debug_output :validate_version "Found Git Version for %~1: %USER_MAJOR%.%USER_MINOR%.%USER_PATCH%.%USER_BUILD%"
|
||||||
|
)
|
||||||
exit /b
|
exit /b
|
||||||
|
|
||||||
:compare_versions
|
:compare_versions
|
||||||
@ -149,20 +165,21 @@ exit /b
|
|||||||
:: whichever binary that has the most recent version will be used based on the return code.
|
:: whichever binary that has the most recent version will be used based on the return code.
|
||||||
|
|
||||||
%lib_console% debug_output Comparing:
|
%lib_console% debug_output Comparing:
|
||||||
%lib_console% debug_output %~1: !%~1_MAJOR!.!%~1_MINOR!.!%~1_PATCH!.!%~1_BUILD!
|
%lib_console% debug_output %~1: %USER_MAJOR%.%USER_MINOR%.%USER_PATCH%.%USER_BUILD%
|
||||||
%lib_console% debug_output %~2: !%~2_MAJOR!.!%~2_MINOR!.!%~2_PATCH!.!%~2_BUILD!
|
%lib_console% debug_output %~2: %VENDORED_MAJOR%.%VENDORED_MINOR%.%VENDORED_PATCH%.%VENDORED_BUILD%
|
||||||
|
|
||||||
if !%~1_MAJOR! GTR !%~2_MAJOR! (exit /b 1)
|
setlocal enabledelayedexpansion
|
||||||
if !%~1_MAJOR! LSS !%~2_MAJOR! (exit /b -1)
|
if !%~1_MAJOR! GTR !%~2_MAJOR! (endlocal & exit /b 1)
|
||||||
|
if !%~1_MAJOR! LSS !%~2_MAJOR! (endlocal & exit /b -1)
|
||||||
|
|
||||||
if !%~1_MINOR! GTR !%~2_MINOR! (exit /b 1)
|
if !%~1_MINOR! GTR !%~2_MINOR! (endlocal & exit /b 1)
|
||||||
if !%~1_MINOR! LSS !%~2_MINOR! (exit /b -1)
|
if !%~1_MINOR! LSS !%~2_MINOR! (endlocal & exit /b -1)
|
||||||
|
|
||||||
if !%~1_PATCH! GTR !%~2_PATCH! (exit /b 1)
|
if !%~1_PATCH! GTR !%~2_PATCH! (endlocal & exit /b 1)
|
||||||
if !%~1_PATCH! LSS !%~2_PATCH! (exit /b -1)
|
if !%~1_PATCH! LSS !%~2_PATCH! (endlocal & exit /b -1)
|
||||||
|
|
||||||
if !%~1_BUILD! GTR !%~2_BUILD! (exit /b 1)
|
if !%~1_BUILD! GTR !%~2_BUILD! (endlocal & exit /b 1)
|
||||||
if !%~1_BUILD! LSS !%~2_BUILD! (exit /b -1)
|
if !%~1_BUILD! LSS !%~2_BUILD! (endlocal & exit /b -1)
|
||||||
|
|
||||||
:: looks like we have the same versions.
|
:: looks like we have the same versions.
|
||||||
exit /b 0
|
endlocal & exit /b 0
|
||||||
|
55
vendor/lib/lib_path.cmd
vendored
55
vendor/lib/lib_path.cmd
vendored
@ -64,7 +64,7 @@ exit /b
|
|||||||
exit /b
|
exit /b
|
||||||
)
|
)
|
||||||
|
|
||||||
setlocal enabledelayedexpansion
|
rem setlocal enabledelayedexpansion
|
||||||
|
|
||||||
set found=0
|
set found=0
|
||||||
set "find_query=%add_path%"
|
set "find_query=%add_path%"
|
||||||
@ -74,20 +74,22 @@ exit /b
|
|||||||
if "%CMDER_CONFIGURED%" == "1" (
|
if "%CMDER_CONFIGURED%" == "1" (
|
||||||
%lib_console% debug_output :enhance_path "Env Var - find_query=%find_query%"
|
%lib_console% debug_output :enhance_path "Env Var - find_query=%find_query%"
|
||||||
echo "%path%"|%WINDIR%\System32\findstr >nul /I /R ";%find_query%\"$"
|
echo "%path%"|%WINDIR%\System32\findstr >nul /I /R ";%find_query%\"$"
|
||||||
if "!ERRORLEVEL!" == "0" set found=1
|
REM if "!ERRORLEVEL!" == "0" set found=1
|
||||||
|
call :set_found
|
||||||
)
|
)
|
||||||
%lib_console% debug_output :enhance_path "Env Var 1 - found=!found!"
|
%lib_console% debug_output :enhance_path "Env Var 1 - found=%found%"
|
||||||
|
|
||||||
if "!found!" == "0" (
|
if "%found%" == "0" (
|
||||||
if "%CMDER_CONFIGURED%" == "1" (
|
if "%CMDER_CONFIGURED%" == "1" (
|
||||||
echo "%path%"|%WINDIR%\System32\findstr >nul /i /r ";%find_query%;"
|
echo "%path%"|%WINDIR%\System32\findstr >nul /i /r ";%find_query%;"
|
||||||
if "!ERRORLEVEL!" == "0" set found=1
|
REM if "!ERRORLEVEL!" == "0" set found=1
|
||||||
|
call :set_found
|
||||||
)
|
)
|
||||||
%lib_console% debug_output :enhance_path "Env Var 2 - found=!found!"
|
%lib_console% debug_output :enhance_path "Env Var 2 - found=%found%"
|
||||||
)
|
)
|
||||||
|
|
||||||
if "%found%" == "0" (
|
if "%found%" == "0" (
|
||||||
%lib_console% debug_output :enhance_path "BEFORE Env Var - PATH=!path!"
|
%lib_console% debug_output :enhance_path "BEFORE Env Var - PATH=%path%"
|
||||||
if /i "%position%" == "append" (
|
if /i "%position%" == "append" (
|
||||||
%lib_console% debug_output :enhance_path "Appending '%add_path%'"
|
%lib_console% debug_output :enhance_path "Appending '%add_path%'"
|
||||||
set "PATH=%PATH%;%add_path%"
|
set "PATH=%PATH%;%add_path%"
|
||||||
@ -96,11 +98,16 @@ exit /b
|
|||||||
set "PATH=%add_path%;%PATH%"
|
set "PATH=%add_path%;%PATH%"
|
||||||
)
|
)
|
||||||
|
|
||||||
%lib_console% debug_output :enhance_path "AFTER Env Var - PATH=!path!"
|
%lib_console% debug_output :enhance_path "AFTER Env Var - PATH=%path%"
|
||||||
)
|
)
|
||||||
|
|
||||||
:end_enhance_path
|
rem :end_enhance_path
|
||||||
endlocal & set "PATH=%PATH:;;=;%"
|
rem endlocal & set "PATH=%PATH:;;=;%"
|
||||||
|
set "PATH=%PATH:;;=;%"
|
||||||
|
exit /b
|
||||||
|
|
||||||
|
:set_found
|
||||||
|
if "!ERRORLEVEL!" == "0" set found=1
|
||||||
exit /b
|
exit /b
|
||||||
|
|
||||||
:enhance_path_recursive
|
:enhance_path_recursive
|
||||||
@ -158,26 +165,36 @@ exit /b
|
|||||||
exit /b
|
exit /b
|
||||||
)
|
)
|
||||||
|
|
||||||
setlocal enabledelayedexpansion
|
rem setlocal enabledelayedexpansion
|
||||||
if "%depth%" == "" set depth=0
|
if "%depth%" == "" set depth=0
|
||||||
|
|
||||||
%lib_console% debug_output :enhance_path_recursive "Env Var - add_path=%add_path%"
|
%lib_console% debug_output :enhance_path_recursive "Env Var - add_path=%add_path%"
|
||||||
%lib_console% debug_output :enhance_path_recursive "Env Var - position=%position%"
|
%lib_console% debug_output :enhance_path_recursive "Env Var - position=%position%"
|
||||||
%lib_console% debug_output :enhance_path_recursive "Env Var - max_depth=%max_depth%"
|
%lib_console% debug_output :enhance_path_recursive "Env Var - max_depth=%max_depth%"
|
||||||
|
|
||||||
if %max_depth% gtr !depth! (
|
if %max_depth% gtr %depth% (
|
||||||
%lib_console% debug_output :enhance_path_recursive "Adding parent directory - '%add_path%'"
|
%lib_console% debug_output :enhance_path_recursive "Adding parent directory - '%add_path%'"
|
||||||
call :enhance_path "%add_path%" %position%
|
call :enhance_path "%add_path%" %position%
|
||||||
set /a "depth=!depth!+1"
|
REM set /a "depth=!depth!+1"
|
||||||
|
call :set_depth
|
||||||
|
call :loop_depth
|
||||||
|
)
|
||||||
|
|
||||||
|
rem :end_enhance_path_recursive
|
||||||
|
rem endlocal & set "PATH=%PATH%"
|
||||||
|
set "PATH=%PATH%"
|
||||||
|
exit /b
|
||||||
|
|
||||||
|
: set_depth
|
||||||
|
set /a "depth=%depth%+1"
|
||||||
|
exit /b
|
||||||
|
|
||||||
|
:loop_depth
|
||||||
for /d %%i in ("%add_path%\*") do (
|
for /d %%i in ("%add_path%\*") do (
|
||||||
%lib_console% debug_output :enhance_path_recursive "Env Var BEFORE - depth=!depth!"
|
%lib_console% debug_output :enhance_path_recursive "Env Var BEFORE - depth=%depth%"
|
||||||
%lib_console% debug_output :enhance_path_recursive "Found Subdirectory - '%%~fi'"
|
%lib_console% debug_output :enhance_path_recursive "Found Subdirectory - '%%~fi'"
|
||||||
call :enhance_path_recursive "%%~fi" %max_depth% %position%
|
call :enhance_path_recursive "%%~fi" %max_depth% %position%
|
||||||
%lib_console% debug_output :enhance_path_recursive "Env Var AFTER- depth=!depth!"
|
%lib_console% debug_output :enhance_path_recursive "Env Var AFTER- depth=%depth%"
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
:end_enhance_path_recursive
|
|
||||||
endlocal & set "PATH=%PATH%"
|
|
||||||
exit /b
|
exit /b
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user