Olivier Mengué | 023ed69 | 2011-03-20 20:22:51 +0100 | [diff] [blame] | 1 | @echo off
|
| 2 | setlocal
|
| 3 | if not "%~1"=="" set GIT_HOME=%~f1
|
| 4 | if "%GIT_HOME%"=="" call :FindGitHome "git.cmd"
|
| 5 |
|
| 6 | if exist "%GIT_HOME%" goto :GitHomeOK
|
| 7 |
|
| 8 | echo MsysGit installation directory not found.>&2
|
| 9 | echo Try to give the directory name on the command line:>&2
|
| 10 | echo %0 "%ProgramFiles%\Git"
|
| 11 | endlocal
|
| 12 | exit /B 1
|
| 13 |
|
| 14 | :GitHomeOK
|
| 15 | set ERR=0
|
| 16 |
|
| 17 | echo Installing gitflow into "%GIT_HOME%"...
|
| 18 |
|
| 19 | call :ChkGetopt getopt.exe || set ERR=1
|
| 20 | if %ERR%==1 goto :End
|
| 21 | echo getopt.exe... Found
|
| 22 |
|
| 23 | if not exist "%GIT_HOME%\bin\git-flow" goto :Install
|
| 24 | echo GitFlow is already installed.>&2
|
| 25 | choice /C YN /M "Do you want to replace it"
|
| 26 | if errorlevel 255 goto :Abort
|
| 27 | if errorlevel 2 goto :Abort
|
| 28 | if not errorlevel 1 goto :Abort
|
| 29 |
|
| 30 | echo Deleting old files...
|
| 31 | for /F %%i in ("%GIT_HOME%\git-flow*" "%GIT_HOME%\gitflow-*") do if exist "%%~fi" del /F /Q "%%~fi"
|
| 32 |
|
| 33 | :Install
|
| 34 | echo Copying files...
|
| 35 | ::goto :EOF
|
| 36 | xcopy "%~dp0\..\git-flow" "%GIT_HOME%\bin" /Y /R /F
|
| 37 | if errorlevel 4 if not errorlevel 5 goto :AccessDenied
|
| 38 | if errorlevel 1 set ERR=1
|
| 39 | xcopy "%~dp0\..\git-flow*" "%GIT_HOME%\bin" /Y /R /F || set ERR=1
|
| 40 | xcopy "%~dp0\..\gitflow-*" "%GIT_HOME%\bin" /Y /R /F || set ERR=1
|
| 41 | xcopy "%~dp0\..\shFlags\src\shflags" "%GIT_HOME%\bin\gitflow-shFlags" /Y /R /F || set ERR=1
|
| 42 |
|
| 43 | if %ERR%==1 choice /T 30 /C Y /D Y /M "Some unexpected errors happened. Sorry, you'll have to fix them by yourself."
|
| 44 |
|
| 45 | :End
|
| 46 | endlocal & exit /B %ERR%
|
| 47 | goto :EOF
|
| 48 |
|
| 49 | :AccessDenied
|
| 50 | set ERR=1
|
| 51 | echo.
|
| 52 | echo You should run this script with "Full Administrator" rights:>&2
|
| 53 | echo - Right-click with Shift on the script from the Explorer>&2
|
| 54 | echo - Select "Run as administrator">&2
|
| 55 | choice /T 30 /C YN /D Y /N >nul
|
| 56 | goto :End
|
| 57 |
|
| 58 | :Abort
|
| 59 | echo Installation canceled.>&2
|
| 60 | set ERR=1
|
| 61 | goto :End
|
| 62 |
|
| 63 | :ChkGetopt
|
| 64 | :: %1 is getopt.exe
|
| 65 | if exist "%GIT_HOME%\bin\%1" goto :EOF
|
| 66 | if exist "%~f$PATH:1" goto :EOF
|
| 67 | echo %GIT_HOME%\bin\%1 not found.>&2
|
| 68 | echo You have to install this file manually. See the GitFlow README.
|
| 69 | exit /B 1
|
| 70 |
|
| 71 | :FindGitHome
|
| 72 | setlocal
|
| 73 | set GIT_CMD_DIR=%~dp$PATH:1
|
| 74 | if "%GIT_CMD_DIR%"=="" endlocal & goto :EOF
|
| 75 | endlocal & set GIT_HOME=%GIT_CMD_DIR:~0,-5%
|
| 76 | goto :EOF
|