Skip to content

Commit 8abfdf4

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ed306e4 commit 8abfdf4

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,6 +2591,7 @@ GIT-BUILD-OPTIONS: FORCE
25912591
@echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@+
25922592
@echo PAGER_ENV=\''$(subst ','\'',$(subst ','\'',$(PAGER_ENV)))'\' >>$@+
25932593
@echo DC_SHA1=\''$(subst ','\'',$(subst ','\'',$(DC_SHA1)))'\' >>$@+
2594+
@echo X=\'$(X)\' >>$@+
25942595
ifdef TEST_OUTPUT_DIRECTORY
25952596
@echo TEST_OUTPUT_DIRECTORY=\''$(subst ','\'',$(subst ','\'',$(TEST_OUTPUT_DIRECTORY)))'\' >>$@+
25962597
endif

t/test-lib-functions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ test_create_repo () {
923923
mkdir -p "$repo"
924924
(
925925
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 \
927927
"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
928928
error "cannot run git init -- have you built things yet?"
929929
mv .git/hooks .git/hooks-disabled

t/test-lib.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,17 @@ export ASAN_OPTIONS
4949
: ${LSAN_OPTIONS=abort_on_error=1}
5050
export LSAN_OPTIONS
5151

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+
5260
################################################################
5361
# 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
5563
if test $? != 1
5664
then
5765
if test -n "$GIT_TEST_INSTALLED"
@@ -63,9 +71,6 @@ then
6371
exit 1
6472
fi
6573

66-
. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
67-
export PERL_PATH SHELL_PATH
68-
6974
# if --tee was passed, write the output not only to the terminal, but
7075
# additionally to the file test-results/$BASENAME.out, too.
7176
case "$GIT_TEST_TEE_STARTED, $* " in

0 commit comments

Comments
 (0)