Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better git path handling #865

Merged
merged 5 commits into from
Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions vendor/init.bat
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,55 @@ 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"
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%"
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"
:: 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"
)

: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%\"

Expand Down
2 changes: 2 additions & 0 deletions vendor/profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 <GIT>\usr\bin\bash.exe
$env:Path += $(";" + $env:CMDER_ROOT + "\vendor\git-for-windows\bin")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure if this is a nice thing to keep the ...\bin version: the problem is that if the user has added git to the path (via the git for windows installer), then bash is not found as the installer does not add bin to the path.

IMO both version should result in the same apps visible in path... Not sure how to ensure that, probably by setting GIT_INSTALL_PATH and then unconditionally adding the bin path?

}

Expand Down