From cd50db3a7f286381628714a6f63755c16c0877a6 Mon Sep 17 00:00:00 2001 From: Florian Schwalm Date: Wed, 29 Jul 2020 22:18:50 +0200 Subject: [PATCH 1/4] Use ERRORLEVEL instead of %errorlevel% to compare git versions %errorlevel% was always 0, even if the vendored git version was more current than the installed one Usually exiting a batch script with "exit /b exitCode" as used in :compare_versions sets %errorlevel% to the specified exit code However, this may not work if %errorlevel% was set before with "Set errorlevel=" I didn't find the location where this might have happened, but I saw the consequence of %errorlevel% always being 0 Thus I decided to use ERRORLEVEL instead as this will always work regardless of environment variable For more information check https://ss64.com/nt/errorlevel.html --- vendor/lib/lib_git.cmd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vendor/lib/lib_git.cmd b/vendor/lib/lib_git.cmd index 239e853..a78badf 100644 --- a/vendor/lib/lib_git.cmd +++ b/vendor/lib/lib_git.cmd @@ -231,15 +231,15 @@ exit /b :::------------------------------------------------------------------------------- :compare_git_versions - if %errorlevel% geq 0 ( + if ERRORLEVEL 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" ( + if ERRORLEVEL 0 if exist "%test_dir:~0,-4%\cmd\git.exe" ( set "GIT_INSTALL_ROOT=%test_dir:~0,-4%" set test_dir= - ) else if %errorlevel% geq 0 ( + ) else if ERRORLEVEL 0 ( set "GIT_INSTALL_ROOT=%test_dir%" set test_dir= ) else ( @@ -249,7 +249,7 @@ exit /b ) else ( :: compare the user git version against the vendored version :: if the user provided git executable is not found - if %errorlevel% equ -255 ( + IF ERRORLEVEL -255 IF NOT ERRORLEVEL -254 ( call :verbose_output No git at "%git_executable%" found. set test_dir= ) From 0ed10e5e890316920b746c8d3a3f4b9a292c4b0b Mon Sep 17 00:00:00 2001 From: Florian Schwalm Date: Wed, 29 Jul 2020 22:39:46 +0200 Subject: [PATCH 2/4] Reorder if-else-clauses in :compare_git_versions so last else block can be reached It is hard to spot without the brackets, but the last else block - that resets %test_dir% and logs in verbose mode that an older user git version will be ignored - can't actually be reached. The else block is considered to belong to the if clause "if exist "%test_dir:~0,-4%\cmd\git.exe"" that will only ever be executed if ERRORLEVEL is greather than or equal to 0, thus if the test fails, the following else if clause "else if ERRORLEVEL 0" will always succeed and the last else block will be ignored. Using the vendored git version may still have worked because %GIT_INSTALL_ROOT% isn't set either way, but to enable the log message I reordered if-else-clauses and brackets in the way I think the original author intended them to work. --- vendor/lib/lib_git.cmd | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/vendor/lib/lib_git.cmd b/vendor/lib/lib_git.cmd index a78badf..f61c4b2 100644 --- a/vendor/lib/lib_git.cmd +++ b/vendor/lib/lib_git.cmd @@ -236,12 +236,14 @@ exit /b %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 0 if exist "%test_dir:~0,-4%\cmd\git.exe" ( - set "GIT_INSTALL_ROOT=%test_dir:~0,-4%" - set test_dir= - ) else if ERRORLEVEL 0 ( - set "GIT_INSTALL_ROOT=%test_dir%" - set test_dir= + if ERRORLEVEL 0 ( + if exist "%test_dir:~0,-4%\cmd\git.exe" ( + set "GIT_INSTALL_ROOT=%test_dir:~0,-4%" + set test_dir= + ) else ( + set "GIT_INSTALL_ROOT=%test_dir%" + set test_dir= + ) ) else ( call :verbose_output Found old %GIT_VERSION_USER% in "%test_dir%", but not using... set test_dir= From 167c49ee6da67ca336b20a172f6b9b8a5602c09f Mon Sep 17 00:00:00 2001 From: Florian Schwalm Date: Wed, 29 Jul 2020 22:46:35 +0200 Subject: [PATCH 3/4] Rewrite old calls to :verbose_output to working %lib_console% verbose_output --- vendor/lib/lib_git.cmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/lib/lib_git.cmd b/vendor/lib/lib_git.cmd index f61c4b2..b55ff6a 100644 --- a/vendor/lib/lib_git.cmd +++ b/vendor/lib/lib_git.cmd @@ -245,14 +245,14 @@ exit /b set test_dir= ) ) else ( - call :verbose_output Found old %GIT_VERSION_USER% in "%test_dir%", but not using... + %lib_console% verbose_output "Found old %GIT_VERSION_USER% in %test_dir%, but not using..." set test_dir= ) ) else ( :: compare the user git version against the vendored version :: if the user provided git executable is not found IF ERRORLEVEL -255 IF NOT ERRORLEVEL -254 ( - call :verbose_output No git at "%git_executable%" found. + %lib_console% verbose_output "No git at "%git_executable%" found." set test_dir= ) ) From fc90722faaa26fa73e75b0e262950be659aedbf3 Mon Sep 17 00:00:00 2001 From: Florian Schwalm Date: Wed, 29 Jul 2020 22:48:01 +0200 Subject: [PATCH 4/4] Prepend %GIT_INSTALL_ROOT%\cmd to path instead of appending it The default setting for path enhancing is appending, so the provided unix tools don't overwrite windows tools we may want to keep. For Git this is undesired behavior, though, as we just compared git versions to decide which one we want to use. The git directory thus needs to be prepended to the path to make sure a call to git uses the version we selected. --- vendor/init.bat | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index 43683fc..4671ad0 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -231,7 +231,9 @@ goto :CONFIGURE_GIT :CONFIGURE_GIT %lib_console% debug_output "Using Git from '%GIT_INSTALL_ROOT%..." :: Add git to the path -rem add the unix commands at the end to not shadow windows commands like more +if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" %lib_path% enhance_path "%GIT_INSTALL_ROOT%\cmd" "" + +:: Add the unix commands at the end to not shadow windows commands like more if %nix_tools% equ 1 ( %lib_console% debug_output init.bat "Preferring Windows commands" set "path_position=append" @@ -240,7 +242,6 @@ if %nix_tools% equ 1 ( set "path_position=" ) -if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" %lib_path% enhance_path "%GIT_INSTALL_ROOT%\cmd" %path_position% if %nix_tools% geq 1 ( if exist "%GIT_INSTALL_ROOT%\mingw32" ( %lib_path% enhance_path "%GIT_INSTALL_ROOT%\mingw32\bin" %path_position%