mirror of
				https://github.com/cmderdev/cmder.git
				synced 2025-11-04 11:22:13 +08:00 
			
		
		
		
	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 <GIT>\cmd\git.exe)
This commit is contained in:
		
							
								
								
									
										44
									
								
								vendor/init.bat
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										44
									
								
								vendor/init.bat
									
									
									
									
										vendored
									
									
								
							@@ -40,17 +40,40 @@ if not exist "%CMDER_ROOT%\config\settings" (
 | 
				
			|||||||
set PLINK_PROTOCOL=ssh
 | 
					set PLINK_PROTOCOL=ssh
 | 
				
			||||||
if not defined TERM set TERM=cygwin
 | 
					if not defined TERM set TERM=cygwin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
:: Check if msysgit is installed
 | 
					:: The idea:
 | 
				
			||||||
if exist "%ProgramFiles%\Git" (
 | 
					:: * if the users points as to a specific git, use that
 | 
				
			||||||
    set "GIT_INSTALL_ROOT=%ProgramFiles%\Git"
 | 
					:: * test if a git is in path and if yes, use that
 | 
				
			||||||
) else if exist "%ProgramFiles(x86)%\Git" (
 | 
					:: * last, use our vendored git
 | 
				
			||||||
    set "GIT_INSTALL_ROOT=%ProgramFiles(x86)%\Git"
 | 
					:: also check that we have a recent enough version of git (e.g. test for GIT\cmd\git.exe)
 | 
				
			||||||
) else if exist "%USERPROFILE%\AppData\Local\Programs\Git" (
 | 
					@if defined GIT_INSTALL_ROOT (
 | 
				
			||||||
    set "GIT_INSTALL_ROOT=%USERPROFILE%\AppData\Local\Programs\Git"
 | 
					    if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" (goto :FOUND_GIT)
 | 
				
			||||||
) else if exist "%CMDER_ROOT%\vendor\git-for-windows" (
 | 
					 | 
				
			||||||
    set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					:: 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
 | 
					:: Add git to the path
 | 
				
			||||||
if defined GIT_INSTALL_ROOT (
 | 
					if defined GIT_INSTALL_ROOT (
 | 
				
			||||||
    set "PATH=%GIT_INSTALL_ROOT%\bin;%GIT_INSTALL_ROOT%\usr\bin;%GIT_INSTALL_ROOT%\usr\share\vim\vim74;%PATH%"
 | 
					    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"
 | 
					    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
 | 
					:: Enhance Path
 | 
				
			||||||
set "PATH=%CMDER_ROOT%\bin;%PATH%;%CMDER_ROOT%\"
 | 
					set "PATH=%CMDER_ROOT%\bin;%PATH%;%CMDER_ROOT%\"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user