From 182629d59a763609f59240bd55fc6851b572c0be Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Wed, 2 Mar 2016 17:30:45 +0100 Subject: [PATCH 1/5] init.bat: check for git in path The idea is: * if the users points as to a specific git, use that * test if a git is in path and if yes, use that * last, use our vendored git We don't make any attempt to guess a different location, if a user wants their own git install, they have to choose "add git to path". Also check that we have a recent enough version of git (e.g. test for \cmd\git.exe) --- vendor/init.bat | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index c792f94cc..a7bf662c7 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -40,17 +40,40 @@ if not exist "%CMDER_ROOT%\config\settings" ( set PLINK_PROTOCOL=ssh if not defined TERM set TERM=cygwin -:: Check if msysgit is installed -if exist "%ProgramFiles%\Git" ( - set "GIT_INSTALL_ROOT=%ProgramFiles%\Git" -) else if exist "%ProgramFiles(x86)%\Git" ( - set "GIT_INSTALL_ROOT=%ProgramFiles(x86)%\Git" -) else if exist "%USERPROFILE%\AppData\Local\Programs\Git" ( - set "GIT_INSTALL_ROOT=%USERPROFILE%\AppData\Local\Programs\Git" -) else if exist "%CMDER_ROOT%\vendor\git-for-windows" ( +:: The idea: +:: * if the users points as to a specific git, use that +:: * test if a git is in path and if yes, use that +:: * last, use our vendored git +:: also check that we have a recent enough version of git (e.g. test for GIT\cmd\git.exe) +@if defined GIT_INSTALL_ROOT ( + if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" (goto :FOUND_GIT) +) + +:: check if git is in path... +@setlocal enabledelayedexpansion +@for /F "delims=" %%F in ('where git.exe') do @( + pushd %%~dpF + cd .. + set "test_dir=!CD!" + popd + if exist "!test_dir!\cmd\git.exe" ( + set GIT_INSTALL_ROOT=!test_dir! + set test_dir= + goto :FOUND_GIT + ) else ( + echo Found old git version in "!test_dir!", but not using... + set test_dir= + ) +) +:: our last hope: our own git... +:VENDORED_GIT +@if exist "%CMDER_ROOT%\vendor\git-for-windows" ( set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows" +) else ( + goto :NO_GIT ) +:FOUND_GIT :: Add git to the path if defined GIT_INSTALL_ROOT ( set "PATH=%GIT_INSTALL_ROOT%\bin;%GIT_INSTALL_ROOT%\usr\bin;%GIT_INSTALL_ROOT%\usr\share\vim\vim74;%PATH%" @@ -58,6 +81,9 @@ if defined GIT_INSTALL_ROOT ( if not defined SVN_SSH set "SVN_SSH=%GIT_INSTALL_ROOT:\=\\%\\bin\\ssh.exe" ) +:NO_GIT +@endlocal & set PATH=%PATH% & set SVN_SSH=%SVN_SSH% & set GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT% + :: Enhance Path set "PATH=%CMDER_ROOT%\bin;%PATH%;%CMDER_ROOT%\" From 2ccc06e63930ece3cf0df1313d48fb2a1847a5b9 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Wed, 2 Mar 2016 17:51:15 +0100 Subject: [PATCH 2/5] init.bat: integrate the unix commands at the end of PATH Some unix commands shadow windows commands and therefor the unix commands should be at the end of the PATH --- vendor/init.bat | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index a7bf662c7..1e1005bb2 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -65,18 +65,23 @@ if not defined TERM set TERM=cygwin set test_dir= ) ) + :: our last hope: our own git... :VENDORED_GIT @if exist "%CMDER_ROOT%\vendor\git-for-windows" ( set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows" + rem add the minimal git commands to the front of the path + set "PATH=%GIT_INSTALL_ROOT%\cmd;%PATH%" ) else ( goto :NO_GIT ) :FOUND_GIT :: Add git to the path -if defined GIT_INSTALL_ROOT ( - set "PATH=%GIT_INSTALL_ROOT%\bin;%GIT_INSTALL_ROOT%\usr\bin;%GIT_INSTALL_ROOT%\usr\share\vim\vim74;%PATH%" +@if defined GIT_INSTALL_ROOT ( + rem add the unix commands including bash in GIT\bin at the end to not shadow windows commands like more + echo Enhancing PATH with unix commands from git [%GIT_INSTALL_ROOT%] + set "PATH=%PATH%;%GIT_INSTALL_ROOT%\bin;%GIT_INSTALL_ROOT%\usr\bin;%GIT_INSTALL_ROOT%\usr\share\vim\vim74" :: define SVN_SSH so we can use git svn with ssh svn repositories if not defined SVN_SSH set "SVN_SSH=%GIT_INSTALL_ROOT:\=\\%\\bin\\ssh.exe" ) From fbccc6b7906b642f0633a9f5375b3efa89088af1 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Wed, 2 Mar 2016 18:25:25 +0100 Subject: [PATCH 3/5] init.bat: remove GIT\bin from path The only reason was bash but bash.exe is also in \usr\bin. --- vendor/init.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index 1e1005bb2..a7b03caa9 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -79,9 +79,9 @@ if not defined TERM set TERM=cygwin :FOUND_GIT :: Add git to the path @if defined GIT_INSTALL_ROOT ( - rem add the unix commands including bash in GIT\bin at the end to not shadow windows commands like more + rem add the unix commands at the end to not shadow windows commands like more echo Enhancing PATH with unix commands from git [%GIT_INSTALL_ROOT%] - set "PATH=%PATH%;%GIT_INSTALL_ROOT%\bin;%GIT_INSTALL_ROOT%\usr\bin;%GIT_INSTALL_ROOT%\usr\share\vim\vim74" + set "PATH=%PATH%;%GIT_INSTALL_ROOT%\usr\bin;%GIT_INSTALL_ROOT%\usr\share\vim\vim74" :: define SVN_SSH so we can use git svn with ssh svn repositories if not defined SVN_SSH set "SVN_SSH=%GIT_INSTALL_ROOT:\=\\%\\bin\\ssh.exe" ) From 1e7f15100f43c389defef5af0fee83ff4c0c504b Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Wed, 2 Mar 2016 18:59:12 +0100 Subject: [PATCH 4/5] PS: also add cmd and bin version of git to the path This ensures that the "normal" path entry (cmd) is first and bash is still reachable via the bin path. --- vendor/profile.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vendor/profile.ps1 b/vendor/profile.ps1 index 0d830f568..a2f75b509 100644 --- a/vendor/profile.ps1 +++ b/vendor/profile.ps1 @@ -41,6 +41,8 @@ try { # Check if git is on PATH, i.e. Git already installed on system Get-command -Name "git" -ErrorAction Stop >$null } catch { + $env:Path += $(";" + $env:CMDER_ROOT + "\vendor\git-for-windows\cmd") + # for bash.exe, which in the cmd version is found as \usr\bin\bash.exe $env:Path += $(";" + $env:CMDER_ROOT + "\vendor\git-for-windows\bin") } From 6c6268e968ae4549b9e6389a0636ccc0bbfc9601 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Fri, 8 Apr 2016 16:55:49 +0200 Subject: [PATCH 5/5] Remove @ in new code, echo off is enough --- vendor/init.bat | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index a7b03caa9..50d4a4e1a 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -45,13 +45,13 @@ if not defined TERM set TERM=cygwin :: * test if a git is in path and if yes, use that :: * last, use our vendored git :: also check that we have a recent enough version of git (e.g. test for GIT\cmd\git.exe) -@if defined GIT_INSTALL_ROOT ( +if defined GIT_INSTALL_ROOT ( if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" (goto :FOUND_GIT) ) :: check if git is in path... -@setlocal enabledelayedexpansion -@for /F "delims=" %%F in ('where git.exe') do @( +setlocal enabledelayedexpansion +for /F "delims=" %%F in ('where git.exe') do @( pushd %%~dpF cd .. set "test_dir=!CD!" @@ -68,7 +68,7 @@ if not defined TERM set TERM=cygwin :: our last hope: our own 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" rem add the minimal git commands to the front of the path set "PATH=%GIT_INSTALL_ROOT%\cmd;%PATH%" @@ -78,7 +78,7 @@ if not defined TERM set TERM=cygwin :FOUND_GIT :: Add git to the path -@if defined GIT_INSTALL_ROOT ( +if defined GIT_INSTALL_ROOT ( rem add the unix commands at the end to not shadow windows commands like more echo Enhancing PATH with unix commands from git [%GIT_INSTALL_ROOT%] set "PATH=%PATH%;%GIT_INSTALL_ROOT%\usr\bin;%GIT_INSTALL_ROOT%\usr\share\vim\vim74" @@ -87,7 +87,7 @@ if not defined TERM set TERM=cygwin ) :NO_GIT -@endlocal & set PATH=%PATH% & set SVN_SSH=%SVN_SSH% & set GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT% +endlocal & set PATH=%PATH% & set SVN_SSH=%SVN_SSH% & set GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT% :: Enhance Path set "PATH=%CMDER_ROOT%\bin;%PATH%;%CMDER_ROOT%\"