From a20d4bc890baefe49b06e4110c3c0f9018db700c Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Wed, 6 Jan 2016 15:38:46 +0100 Subject: [PATCH 1/3] install.cmd: properly escape the ! in the shebang line This was a regression introduced by the useage of `enabledelayedexpansion`, which results in `!` treated as variable identifier like `%`. The result was that git didn't treat the scripts as git commands... --- install.cmd | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/install.cmd b/install.cmd index 07541b0..e39fb1d 100644 --- a/install.cmd +++ b/install.cmd @@ -2,6 +2,7 @@ :: don't leak env variables into the calling interperter... setlocal :: better defaults for dealing with quotes... +:: You need to escape ! afterwards with ^^! or "^!" SETLOCAL enabledelayedexpansion :: A comment on quotes around file path variables: @@ -86,7 +87,7 @@ SET COMMANDS_WITHOUT_REPO=git-alias git-extras git-fork git-setup echo Installing binaries... FOR /R "%GITEXTRAS%\bin" %%i in (*.*) DO ( - ECHO #!/usr/bin/env bash > "%PREFIX%\bin\%%~ni" + ECHO #^^!/usr/bin/env bash > "%PREFIX%\bin\%%~ni" TYPE "%GITEXTRAS%\helper\reset-env" >> "%PREFIX%\bin\%%~ni" TYPE "%GITEXTRAS%\helper\git-extra-utility" >> "%PREFIX%\bin\%%~ni" TYPE "%GITEXTRAS%\helper\is-git-repo" >> "%PREFIX%\bin\%%~ni" @@ -94,7 +95,7 @@ FOR /R "%GITEXTRAS%\bin" %%i in (*.*) DO ( ) FOR %%i in (%COMMANDS_WITHOUT_REPO%) DO ( - ECHO #!/usr/bin/env bash > "%PREFIX%\bin\%%i" + ECHO #^^!/usr/bin/env bash > "%PREFIX%\bin\%%i" TYPE "%GITEXTRAS%\helper\reset-env" >> "%PREFIX%\bin\%%i" TYPE "%GITEXTRAS%\helper\git-extra-utility" >> "%PREFIX%\bin\%%i" MORE +2 "%GITEXTRAS%\bin\%%i" >> "%PREFIX%\bin\%%i" From 6bf64fbb23510101811400499228592714874491 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Wed, 6 Jan 2016 15:47:27 +0100 Subject: [PATCH 2/3] install.cmd: add a check for write rights to the install folder This was happening earlier as well, but the error messages were the raw messages from the failed writes... --- install.cmd | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/install.cmd b/install.cmd index e39fb1d..984441b 100644 --- a/install.cmd +++ b/install.cmd @@ -7,7 +7,7 @@ SETLOCAL enabledelayedexpansion :: A comment on quotes around file path variables: :: only add quotes around the variable when you use the variable -:: as a file path (exists, type, pipe,...) and teh parenthesis of a +:: as a file path (exists, type, pipe,...) and the parenthesis of a :: for, not when used as a string (-> setting variables) :: more does not work if the codepage is set to unicode 65001 @@ -69,7 +69,7 @@ set GIT_INSTALL_DIR=!GIT_INSTALL_DIR:"=! IF %GIT_INSTALL_DIR:~-1%==\ SET GIT_INSTALL_DIR=%GIT_INSTALL_DIR:~0,-1% if not exist "%GIT_INSTALL_DIR%\mingw64" ( - echo No mingw64 folder found in %GIT_INSTALL_DIR%. + echo No mingw64 folder found in %GIT_INSTALL_DIR%. echo. echo Please supply a proper "Git for Windows 2.x" install path: echo "install.cmd c:\[git-install-path]" @@ -83,6 +83,24 @@ SET GITEXTRAS=%~dp0 IF NOT EXIST "%PREFIX%\bin" MKDIR "%PREFIX%\bin" +:: Check that we can install into that dir or need admin rights... +set _testfile=%PREFIX%\bin\testfile_to_check_if_dir_is_writeable-577423947123.~ +copy NUL "%_testfile%" >NUL 2>&1 +IF EXIST "%_testfile%" ( + set IS_WRITEABLE=yes + del "%_testfile%" +) else ( + set IS_WRITEABLE=no +) +if "%IS_WRITEABLE%"=="no" ( + echo. + echo Directory for binaries ["%PREFIX%\bin"] is not writeable by install.cmd. + echo. + echo You probably need to run install.cmd from an admin prompt. + set ERROR=1 + goto :exit +) + SET COMMANDS_WITHOUT_REPO=git-alias git-extras git-fork git-setup echo Installing binaries... @@ -104,6 +122,13 @@ FOR %%i in (%COMMANDS_WITHOUT_REPO%) DO ( echo Installing man pages... set _QUIET=/NP /NFL /NDL /NJS /NJH ROBOCOPY %_QUIET% /IS "%GITEXTRAS%\man" "%HTMLDIR%" *.html +IF %ERRORLEVEL% GTR 7 ( + echo Not all html docs could be copied to "%GITEXTRAS%\man". + echo. + echo You probably need to run the install.cmd script from an admin prompt. + set ERROR=1 + goto :exit +) echo done if not exist "%GIT_INSTALL_DIR%\usr\bin\column.exe" ( From 64f9e4d797b42c17dfead8b5e721fee78c0d44b0 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Wed, 6 Jan 2016 15:49:57 +0100 Subject: [PATCH 3/3] installation.md: Update information about column.exe column.exe will be available in the next git release: https://github.com/git-for-windows/build-extra/pull/92 Also convert tabs to spaces... Was mixed up to now :-/ --- Installation.md | 2 +- install.cmd | 78 ++++++++++++++++++++++++------------------------- 2 files changed, 39 insertions(+), 41 deletions(-) diff --git a/Installation.md b/Installation.md index 040230d..1be393a 100644 --- a/Installation.md +++ b/Installation.md @@ -39,7 +39,7 @@ install.cmd "C:\git" Last, to use `git line-summary`, `git summary` and `git ignore-io`, you need to copy `column.exe` from a [msys2][1] installation from `folder-your-msys2-installed/usr/bin` -to `folder-your-git-installed/usr/bin`. +to `folder-your-git-installed/usr/bin` or wait for git 2.7.1, which will include column.exe. ## Building from source diff --git a/install.cmd b/install.cmd index 984441b..ac674cf 100644 --- a/install.cmd +++ b/install.cmd @@ -12,7 +12,7 @@ SETLOCAL enabledelayedexpansion :: more does not work if the codepage is set to unicode 65001 for /F "tokens=*" %%F in ('chcp') do ( - for %%A in (%%F) do (set _last=%%A) + for %%A in (%%F) do (set _last=%%A) ) SET CP=%_last:~0,-1% chcp 850 > NUL @@ -26,9 +26,9 @@ where /Q git.exe if errorlevel 1 goto :defaultpath 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 + set bindir=%%~dpF + rem break after the first, so that we get the first in path + goto :break ) goto :defaultpath @@ -48,16 +48,16 @@ if exist "%ProgramFiles%\Git" ( :foundprefix :: overwrite with whatever the user supplied... IF NOT "%~1"=="" ( - REM make it easier for the user to specify a prefix: - REM just supplying the git dir is enough... - if exist "%~1\mingw64" ( - set PREFIX=%~1\mingw64 - ) else ( - echo Using git install path "%~1" as PREFIX, please make sure it's really a - echo path to the mingw64 directory... - echo. - SET PREFIX=%~1 - ) + REM make it easier for the user to specify a prefix: + REM just supplying the git dir is enough... + if exist "%~1\mingw64" ( + set PREFIX=%~1\mingw64 + ) else ( + echo Using git install path "%~1" as PREFIX, please make sure it's really a + echo path to the mingw64 directory... + echo. + SET PREFIX=%~1 + ) ) :: remove a trailing slash, but only after removing quotes... set PREFIX=!PREFIX:"=! @@ -69,12 +69,12 @@ set GIT_INSTALL_DIR=!GIT_INSTALL_DIR:"=! IF %GIT_INSTALL_DIR:~-1%==\ SET GIT_INSTALL_DIR=%GIT_INSTALL_DIR:~0,-1% if not exist "%GIT_INSTALL_DIR%\mingw64" ( - echo No mingw64 folder found in %GIT_INSTALL_DIR%. - echo. - echo Please supply a proper "Git for Windows 2.x" install path: - echo "install.cmd c:\[git-install-path]" - set ERROR=1 - goto :exit + echo No mingw64 folder found in %GIT_INSTALL_DIR%. + echo. + echo Please supply a proper "Git for Windows 2.x" install path: + echo "install.cmd c:\[git-install-path]" + set ERROR=1 + goto :exit ) echo Installing to %PREFIX% @@ -105,18 +105,18 @@ SET COMMANDS_WITHOUT_REPO=git-alias git-extras git-fork git-setup echo Installing binaries... FOR /R "%GITEXTRAS%\bin" %%i in (*.*) DO ( - ECHO #^^!/usr/bin/env bash > "%PREFIX%\bin\%%~ni" - TYPE "%GITEXTRAS%\helper\reset-env" >> "%PREFIX%\bin\%%~ni" - TYPE "%GITEXTRAS%\helper\git-extra-utility" >> "%PREFIX%\bin\%%~ni" - TYPE "%GITEXTRAS%\helper\is-git-repo" >> "%PREFIX%\bin\%%~ni" - MORE +2 "%GITEXTRAS%\bin\%%~ni" >> "%PREFIX%\bin\%%~ni" + ECHO #^^!/usr/bin/env bash > "%PREFIX%\bin\%%~ni" + TYPE "%GITEXTRAS%\helper\reset-env" >> "%PREFIX%\bin\%%~ni" + TYPE "%GITEXTRAS%\helper\git-extra-utility" >> "%PREFIX%\bin\%%~ni" + TYPE "%GITEXTRAS%\helper\is-git-repo" >> "%PREFIX%\bin\%%~ni" + MORE +2 "%GITEXTRAS%\bin\%%~ni" >> "%PREFIX%\bin\%%~ni" ) FOR %%i in (%COMMANDS_WITHOUT_REPO%) DO ( - ECHO #^^!/usr/bin/env bash > "%PREFIX%\bin\%%i" - TYPE "%GITEXTRAS%\helper\reset-env" >> "%PREFIX%\bin\%%i" - TYPE "%GITEXTRAS%\helper\git-extra-utility" >> "%PREFIX%\bin\%%i" - MORE +2 "%GITEXTRAS%\bin\%%i" >> "%PREFIX%\bin\%%i" + ECHO #^^!/usr/bin/env bash > "%PREFIX%\bin\%%i" + TYPE "%GITEXTRAS%\helper\reset-env" >> "%PREFIX%\bin\%%i" + TYPE "%GITEXTRAS%\helper\git-extra-utility" >> "%PREFIX%\bin\%%i" + MORE +2 "%GITEXTRAS%\bin\%%i" >> "%PREFIX%\bin\%%i" ) echo Installing man pages... @@ -132,17 +132,15 @@ IF %ERRORLEVEL% GTR 7 ( echo done if not exist "%GIT_INSTALL_DIR%\usr\bin\column.exe" ( - where /Q column.exe - if errorlevel 1 ( - echo. - echo column.exe is missing: Not in "%GIT_INSTALL_DIR%\usr\bin" or in PATH! - echo. - echo "git summary", "git summary-line" and "git ignore-io" do not work - echo without. If you need these commands, please install msys2 and - echo make column.exe available by copying it into the path or into - echo "%GIT_INSTALL_DIR%\usr\bin". - echo. - ) + where /Q column.exe + if errorlevel 1 ( + echo. + echo column.exe is missing: Not in "%GIT_INSTALL_DIR%\usr\bin" or in PATH! + echo. + echo "git summary", "git summary-line" and "git ignore-io" do not work without. + echo If you need these commands, please install Git for Windows > 2.7.0. + echo. + ) )