tests: explicitly use `git.exe` on Windows

On Windows, when we refer to `/an/absolute/path/to/git`, it magically resolves `git.exe` at that location. Except if something of the name `git` exists next to that `git.exe`. So if we call `$BUILD_DIR/git`, it will find `$BUILD_DIR/git.exe` *only* if there is not, say, a directory called `$BUILD_DIR/git`. Such a directory, however, exists in Git for Windows when building with Visual Studio (our Visual Studio project generator defaults to putting the build files into a directory whose name is the base name of the corresponding `.exe`). In the bin-wrappers/* scripts, we already take pains to use `git.exe` rather than `git`, as this could pick up the wrong thing on Windows (i.e. if there exists a `git` file or directory in the build directory). Now we do the same in the tests' start-up code. This also helps when testing an installed Git, as there might be even more likely some stray file or directory in the way. Note: the only way we can record whether the `.exe` suffix is by writing it to the `GIT-BUILD-OPTIONS` file and sourcing it at the beginning of `t/test-lib.sh`. This is not a requirement introduced by this patch, but we move the call to be able to use the `$X` variable that holds the file extension, if any. Note also: the many, many calls to `git this` and `git that` are unaffected, as the regular PATH search will find the `.exe` files on Windows (and not be confused by a directory of the name `git` that is in one of the directories listed in the `PATH` variable), while `/path/to/git` would not, per se, know that it is looking for an executable and happily prefer such a directory. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Nov 14, 2018 at 08:32 UTC 8abfdf44c882ad5d31bd8d0a0f1bfb67f8a9e39f
3 files changed +11 -5
Makefile
+1
@@ -2591,6 +2591,7 @@ GIT-BUILD-OPTIONS: FORCE
2591 @echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@+
2592 @echo PAGER_ENV=\''$(subst ','\'',$(subst ','\'',$(PAGER_ENV)))'\' >>$@+
2593 @echo DC_SHA1=\''$(subst ','\'',$(subst ','\'',$(DC_SHA1)))'\' >>$@+
2594 + @echo X=\'$(X)\' >>$@+
2595 ifdef TEST_OUTPUT_DIRECTORY
2596 @echo TEST_OUTPUT_DIRECTORY=\''$(subst ','\'',$(subst ','\'',$(TEST_OUTPUT_DIRECTORY)))'\' >>$@+
2597 endif
t/test-lib-functions.sh
+1 -1
@@ -923,7 +923,7 @@ test_create_repo () {
923 mkdir -p "$repo"
924 (
925 cd "$repo" || error "Cannot setup test environment"
926 - "${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git" init \
926 + "${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" init \
927 "--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
928 error "cannot run git init -- have you built things yet?"
929 mv .git/hooks .git/hooks-disabled
t/test-lib.sh
+9 -4
@@ -49,9 +49,17 @@ export ASAN_OPTIONS
49 : ${LSAN_OPTIONS=abort_on_error=1}
50 export LSAN_OPTIONS
51
52 +if test ! -f "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
53 +then
54 + echo >&2 'error: GIT-BUILD-OPTIONS missing (has Git been built?).'
55 + exit 1
56 +fi
57 +. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
58 +export PERL_PATH SHELL_PATH
59 +
60 ################################################################
61 # It appears that people try to run tests without building...
54 -"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git" >/dev/null
62 +"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
63 if test $? != 1
64 then
65 if test -n "$GIT_TEST_INSTALLED"
@@ -63,9 +71,6 @@ then
71 exit 1
72 fi
73
66 -. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
67 -export PERL_PATH SHELL_PATH
68 -
74 # if --tee was passed, write the output not only to the terminal, but
75 # additionally to the file test-results/$BASENAME.out, too.
76 case "$GIT_TEST_TEE_STARTED, $* " in