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

Should we really be preferring externally installed Git? #782

Closed
daxgames opened this issue Dec 30, 2015 · 30 comments
Closed

Should we really be preferring externally installed Git? #782

daxgames opened this issue Dec 30, 2015 · 30 comments

Comments

@daxgames
Copy link
Member

Should we be doing this in the vendor\init.bat:

:: 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" (
    set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows"
)

and this in the vendor\profile.ps1:

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\bin")
}

Both of these could lead to running a different version of Git in cmd.exe/powershell.exe shells vs. the bash.exe shell shipped with Cmder.

If you really think we should, the vendor\init.bat code should be altered to the below:

:: Maintain compatibility with externally installed git for windows 1.9.5
@if defined GIT_INSTALL_ROOT (
    if exist "%GIT_INSTALL_ROOT%\share\vim\vim74\vim.exe" (
        set "PATH=%GIT_INSTALL_ROOT%\share\vim\vim74;%PATH%"
    ) else if exist "%GIT_INSTALL_ROOT%\usr\bin\vim.exe" (
        set "PATH=%GIT_INSTALL_ROOT%\usr\bin;%PATH%"
    )
)

:: Add git to the path
if defined GIT_INSTALL_ROOT (
    set "PATH=%GIT_INSTALL_ROOT%\bin;%PATH%"
    :: 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"
)

@daxgames
Copy link
Member Author

if not then I suggest:

vendor\init.bat

if exist "%CMDER_ROOT%\vendor\git-for-windows" (
    set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows"
)

vendor\profile.ps1

if ( test-path $($env:CMDER_ROOT + "\vendor\git-for-windows\bin\git.exe") ) {
    $env:Path += $(";" + $env:CMDER_ROOT + "\vendor\git-for-windows\bin")
}

@daxgames
Copy link
Member Author

I would think we would only use externally installed Git if Cmder Mini was in use and thus did not include the vendor\git-for-windows folder.

@daxgames
Copy link
Member Author

So maybe the best code would be:

vendor\init.bat:

:: Check if msysgit is installed if running Cmder Mini
@if exist "%CMDER_ROOT%\vendor\git-for-windows" (
    set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows"
) else 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"
)

vendor\profile.ps1

if ( test-path $($env:CMDER_ROOT + "\vendor\git-for-windows\bin\git.exe") ) {
    $env:Path += $(";" + $env:CMDER_ROOT + "\vendor\git-for-windows\bin")
} else {
    try {
        # Check if git is on PATH, i.e. Git already installed on system
        Get-command -Name "git" -ErrorAction Stop >$null
    } catch {
        Write-Warning "Missing git support, download the full Cmder that includes Git or install Git for Windows."
    }
}

@Stanzilla
Copy link
Member

Do we actually really need the package without git?

@daxgames
Copy link
Member Author

Git and the *nix like environment is why I use cmder so I personally would say no.

@Djabx Djabx mentioned this issue Jan 2, 2016
@rmorrin
Copy link
Contributor

rmorrin commented Jan 5, 2016

@Stanzilla @daxgames I think it's important to allow users to use their installed version of Git if they have it. Certain dev tools also require Git to be installed in the default location, so sometimes the choice is not your own.

@jankatins
Copy link
Contributor

I also have git extras installed in the user installed location, so I would prefer if the logic prefers a user installed location.

@vladimir-kotikov
Copy link
Contributor

I'll add my opinion: IMO if the user has Git already installed, Cmder shouldn't change user experience around Git in any way, i.e. 1) do not force user to use bundled Git instead of already installed one; 2) do not modify GIT_INSTALL_PATH, as this potentially may affect other tools/commands, launched from Cmder session.

So my proposal about detecting alghoritm is:

  1. Check if GIT_INSTALL_PATH is set and use that Git instalation
  2. If it doesn't - check if where git returns anything and use returned path as a Git installation
  3. If nothing returned - use bundled Git

@jankatins
Copy link
Contributor

BTW: this is from another project where the git install path was needed:

:: find a git.exe in path and use that as a default dir
where /Q git.exe
if errorlevel 1 goto :nogitfound

for /F "delims=" %%F in ('where git.exe') do (
    set bindir=%%~dpF
    rem break after the first, so that we get the first in path
    goto :break
)
goto :nogitfound

:break
rem remove the last slash
SET bindir=%bindir:~0,-1%
for %%G in ("%bindir%") do set GIT_INSTALL_PATH=%%~dpG

@MartiUK
Copy link
Member

MartiUK commented Jan 7, 2016

There's no reason why we can't just run the powershell profile script within init.bat.

@kblomqvist
Copy link

+1 for @vladimir-kotikov 's proposal. I just found cmder and was immediately confused whether I should use mini or full as I already have Git installed.

@vBm
Copy link

vBm commented Jan 8, 2016

+1 for @vladimir-kotikov as well but with one slight change. Don't prepend git to %PATH%, instead append to it.

Since cmder was prepending git and vim via init.bat#L39 to path I had issues using some of the apps that are shipped with Windows, like EXPAND (app for extracting the contents of a CAB archive). Instead, EXPAND that is shipped with git is used (utility for converting tabs to spaces)

Pretty much there's a lot of conflicting when using utilities from Windows.

So instead of set "PATH=%GIT_INSTALL_ROOT%\bin;%GIT_INSTALL_ROOT%\share\vim\vim74;%PATH%"
do set "PATH=%PATH%;%GIT_INSTALL_ROOT%\bin;%GIT_INSTALL_ROOT%\share\vim\vim74"

@wgv-sethlivingston
Copy link

+1, cannot afford to wonder which version of Git I'm using.

@Stanzilla
Copy link
Member

@wgv-sethlivingston type which git

@wgv-sethlivingston
Copy link

Yes, I understand that. What I meant of course was that if I have installed Git on my system, then that is the Git I want to use.

@t5k6
Copy link

t5k6 commented Mar 2, 2016

For people who prefer "GitHub for Windows" over other git packages below code should be added to "init.bat".

@else if exist "%USERPROFILE%\AppData\Local\GitHub\Portab~1" ( set "GIT_INSTALL_ROOT=%USERPROFILE%\AppData\Local\GitHub\Portab~1" )

This was referenced Mar 2, 2016
@jankatins
Copy link
Contributor

#865 implements the idea of #782 (comment) by @vladimir-kotikov

@jankatins
Copy link
Contributor

@t5k6 Could you download a version from that PR (go to #865, click on the appveyor link -> go to artifacts) and check if this works for you? I do hope that the github for windows version of git is recent enough to have a <git>\cmd\git.exe...

@t5k6
Copy link

t5k6 commented Mar 2, 2016

@JanSchulz cmder_mini gives this notification: INFO: Could not find files for the given pattern(s).
while cmder full starts with this message:

for /F "usebackq" %x in (`dir /b *.bat *.cmd`) do (
REM @echo Calling E:\cmder\config\profile.d\%x...

)
File Not Found

As for git I have to manually add the lines I have written earlier.
GitHub for Desktop version: 3.0.13.0
Git Shell version: 2.7.1

@jankatins
Copy link
Contributor

@t5k6 can you give me your path (cmd and path) and also if your Github for Windows dir has a cmd dir and a bin dir an in cmd is git + start-ssh-agent and in bin is git and a bash.exe?

@jankatins
Copy link
Contributor

The file not found problem should be fixed in a later version, I added a commit to fix that...

@t5k6
Copy link

t5k6 commented Mar 3, 2016

@JanSchulz
files/folders inside USERPROFILE%\AppData\Local\GitHub\Portab~1"
bin/ cmd/ dev/ etc/ git-bash.exe* git-cmd.exe* mingw32/ tmp/ usr/

files inside USERPROFILE%\AppData\Local\GitHub\Portab~1\cmd" folder:
git-gui.exe* git.exe* gitk.exe* start-ssh-agent.cmd

PATH output in vanilla cmder_mini (AppVeyor 1.0.216-development):
λ for %a in ("%path:;=";"%") do @echo %~a
E:\cmder_mini\bin
E:\cmder_mini\vendor\conemu-maximus5
E:\cmder_mini\vendor\conemu-maximus5\ConEmu
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0
C:\Users\Tahsin.dnx\bin
C:\Program Files\Microsoft DNX\Dnvm
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Program Files\Microsoft SQL Server\120\Tools\Binn
E:\Applications\Development\Vagrant\bin
C:\Users\Tahsin.dnx\bin
E:\cmder_mini\

PATH output in vanilla cmder_full (AppVeyor 1.0.216-development):
λ for %a in ("%path:;=";"%") do @echo %~a
E:\cmder\bin
E:\cmder\vendor\git-for-windows\bin
E:\cmder\vendor\git-for-windows\usr\bin
E:\cmder\vendor\git-for-windows\usr\share\vim\vim74
E:\cmder\vendor\conemu-maximus5
E:\cmder\vendor\conemu-maximus5\ConEmu
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0
C:\Users\Tahsin.dnx\bin
C:\Program Files\Microsoft DNX\Dnvm
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Program Files\Microsoft SQL Server\120\Tools\Binn
E:\Applications\Development\Vagrant\bin
C:\Users\Tahsin.dnx\bin
E:\cmder\

BTW with Github for Windows, git package is in portable state and is not added to path (instead only activated with Github application) as can be seen from my 'path' output. That is why I add
@else if exist "%USERPROFILE%\AppData\Local\GitHub\Portab~1" ( set "GIT_INSTALL_ROOT=%USERPROFILE%\AppData\Local\GitHub\Portab~1" ) code to init.bat in cmder.

Sorry for not clearly explaining that before.

@jankatins
Copy link
Contributor

@t5k6 You installed github for windows and it didn't add itself to the path? Is "%USERPROFILE%\AppData\Local\GitHub\Portab~1" the default path?

I don't really want to add a special case for this: IMO:

  • If a userhas git in cmd, it should be available in cmder
  • if a user does not add git to the path, cmder has no right to do so and should use the one from vendor...

The help text then becomes If a git.exe from "git for Windows 2.x" is in path, it will be used. If not, and you have downloaded a full cmder release, the git which is included with cmder is used. If you have a portable installation of git and want that used, either include <git_path>\cmd in path (setx PATH=%PATH%;<git_path>\cmd) or use the user_profile.cmd to add it (and maybe the unix tools in <gitpath>\usr\bin) to the path via set path=%path%;<git_path>\cmd;<git_path>\usr\bin

@thomthom
Copy link

My VS2015 installation ended up installing standalone git on my machine. This version doesn't include all the UNIX commands - and I wouldn't want them being available for my normal cmd console either.

But I do want them for my Cmder console. But as things are now where it checks for standalone Git first this setup won't work. I'm looking for a way to force cmder to always use vendor git - separate from my sans-UNIX-standalone-Git install. Is this currently possible, or would there need to be alternations to cmder?

@jankatins
Copy link
Contributor

@thomgit Can you show us where VC2015 installs git too?

The current (aka next release) version of the cmd init.bat script will let you overwrite these git in two ways:

  • put your own git into path in front of the VS2015 git
  • Set %GIT_INSTALL_ROOT% env variable (outside of cmders config files!) so that %GIT_INSTALL_ROOT%\cmd\git.exe exist.

https://github.com/cmderdev/cmder/blob/development/vendor/init.bat#L44

@thomthom
Copy link

It installed Git into ProgramFiles (the 64bit variant). I ended up temporarily disabling the lines in init.bat and that worked for now:

:: 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 "%CMDER_ROOT%\vendor" (
@if exist "%CMDER_ROOT%\vendor" (
    set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\msysgit"
)

@JanSchulz - with the changes you describe I'd then just add cmder's vendor git into the ENV: %GIT_INSTALL_ROOT%? And this is a ENV variable only cmder use? Or is this one used by Git itself to announce its location?

@jankatins
Copy link
Contributor

This is a variable which is used in init.bat, I think it is only used there. It is not set by git itself.

If you want to have a preview, try the builds available here: https://ci.appveyor.com/project/MartiUK/cmder/build/1.0.256-development/artifacts They contain the "where is git" changes.

@Jackbennett
Copy link
Contributor

I would say if git's already installed use that. If someone gets cmder+git with git already I'd assume they made a mistake. Perhaps we make a config function to help you flip over the env settings to a portable git if for whatever reason a user might not want to use the installed one.

If we don't prefer the external version of packages we would need to start asking questions like "Ignore external config files?". I don't think anyone wants to have a .cmder/.gitconfig as well as their normal ones. Not by default anyway. I'm already not crazy about ignoring users PS Profiles but that's off topic.

@thomthom
Copy link

In my case I used cmder with git - then Visual Studio installed standalone git along with the ride for their installer - without all the UNIX commands.

So in my case the stand-alone git isn't what I wanted cmder to be using - and it was out of my control.

@jankatins
Copy link
Contributor

jankatins commented May 25, 2016

IMO for most users, preferring the user installed version over the included one is a good idea. There are several ways to overwrite that:

  • Just set %GIT_INSTALL_ROOT% to the git base dir so that %GIT_INSTALL_ROOT%\cmd\git.exe exists (source) -> setx "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows"
  • just add the "right" git in front of the "wrong" git or even remove the wrong path in your user-profile.cmd:
SET "PATH=%PATH:C:\Program Files\Git\cmd\;=%"; 
:: maybe also remove the /usr/bin and /usr/share/vom stuff...
set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows"; 
set "PATH=%GIT_INSTALL_ROOT%\cmd;%PATH%"; 
set "PATH=%PATH%;%GIT_INSTALL_ROOT%\usr\bin;%GIT_INSTALL_ROOT%\usr\share\vim\vim74"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests