From 21991518de46fb85f3ac5280044476d8ef3faa94 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 9 Sep 2026 15:36:46 +0200 Subject: [PATCH 1/3] GIT-BUILD-OPTIONS: allow overriding the test template directory When cross-compiling Git for Windows under Linux, the generated build options embed a Linux template path that the Git SDK Bash cannot use (to that Bash, the Linux paths look like UNC paths of the form `//wsl.localhost/Ubuntu/home/git-dev/src/git`). This could be accommodated by editing the `bin-wrappers/*` files manually, but those changes would be lost when `make` regenerates the files. Allow the hard-coded value to be overridden via the environment variable `GIT_TEST_TEMPLATE_DIR` so that an SDK-readable path can be specified. Assisted-by: GPT-6 Signed-off-by: Johannes Schindelin --- GIT-BUILD-OPTIONS.in | 2 +- t/README | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/GIT-BUILD-OPTIONS.in b/GIT-BUILD-OPTIONS.in index 0a9884e0ade556..2537e2285bc893 100644 --- a/GIT-BUILD-OPTIONS.in +++ b/GIT-BUILD-OPTIONS.in @@ -16,7 +16,7 @@ GIT_TEST_GITPERLLIB=@GIT_TEST_GITPERLLIB@ GIT_TEST_INDEX_VERSION=@GIT_TEST_INDEX_VERSION@ GIT_TEST_OPTS=@GIT_TEST_OPTS@ GIT_TEST_PERL_FATAL_WARNINGS=@GIT_TEST_PERL_FATAL_WARNINGS@ -GIT_TEST_TEMPLATE_DIR=@GIT_TEST_TEMPLATE_DIR@ +GIT_TEST_TEMPLATE_DIR=${GIT_TEST_TEMPLATE_DIR:-@GIT_TEST_TEMPLATE_DIR@} GIT_TEST_TEXTDOMAINDIR=@GIT_TEST_TEXTDOMAINDIR@ GIT_TEST_UTF8_LOCALE=@GIT_TEST_UTF8_LOCALE@ LOCALEDIR=@LOCALEDIR@ diff --git a/t/README b/t/README index a02200615f59a0..b19c162408260f 100644 --- a/t/README +++ b/t/README @@ -356,6 +356,9 @@ that cannot be easily covered by a few specific test cases. These could be enabled by running the test suite with correct GIT_TEST_ environment set. +GIT_TEST_TEMPLATE_DIR= overrides the generated location of the +templates used by the tests. + GIT_TEST_FAIL_PREREQS= fails all prerequisites. This is useful for discovering issues with the tests where say a later test implicitly depends on an optional earlier test. From 7958e20fdb8e67379ccdb16c4f897e7466eae460 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 9 Sep 2026 16:38:16 +0200 Subject: [PATCH 2/3] test wrappers: support Windows executables under WSL WSL does not automatically forward all environment variables to Windows executables. The `WSLENV` variable controls which ones are forwarded. Also, conflicting `PATH` and `Path` values can select an installed Git in SDK subprocesses, and test repositories appear as non-local UNC paths. Provide opt-in `GIT_TEST_WSL=1` support for checking Windows cross-builds from WSL without hand-editing generated wrappers after each regeneration. Leave the default wrapper behavior unchanged. Assisted-by: GPT-6 Signed-off-by: Johannes Schindelin --- bin-wrappers/wrap-for-bin.sh | 20 ++++++++++++++++++++ t/README | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/bin-wrappers/wrap-for-bin.sh b/bin-wrappers/wrap-for-bin.sh index 4b658ffd2d0960..d6fc9d99817be3 100755 --- a/bin-wrappers/wrap-for-bin.sh +++ b/bin-wrappers/wrap-for-bin.sh @@ -21,6 +21,26 @@ PATH='@BUILD_DIR@/bin-wrappers:'"$PATH" export MERGE_TOOLS_DIR GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR +if test "$GIT_TEST_WSL" = 1 +then + export Path="$PATH" + if test -n "$TEST_OUTPUT_DIRECTORY" + then + safe=$(wslpath -m "$TEST_OUTPUT_DIRECTORY") || exit + safe=$(printf '%s' "$safe" | sed "s/'/'\\\\''/g") || exit + params="${GIT_CONFIG_PARAMETERS:+$GIT_CONFIG_PARAMETERS }" + export GIT_CONFIG_PARAMETERS="$params'safe.directory'='$safe/*'" + fi + WSLENV="$WSLENV:HOME/p:GITPERLLIB/pl:LANG:LC_ALL:TZ:TERM" + WSLENV="$WSLENV:EDITOR:PAGER:COLUMNS:$(env -0 | sed -zE ' + /^(TEST|GIT)_/!d + s/=.*// + s/^GIT_(EXEC_PATH|TEMPLATE_DIR|TEXTDOMAINDIR)$/&\/p/ + s/^GIT_CEILING_DIRECTORIES$/&\/pl/ + ' | tr '\0' :)" + export WSLENV +fi + case "$GIT_DEBUGGER" in '') exec "@PROG@" "$@" diff --git a/t/README b/t/README index b19c162408260f..4b20c029858036 100644 --- a/t/README +++ b/t/README @@ -359,6 +359,11 @@ environment set. GIT_TEST_TEMPLATE_DIR= overrides the generated location of the templates used by the tests. +GIT_TEST_WSL=1 forwards the test environment when the generated wrappers +run Windows executables from WSL. It also grants a command-scope +safe.directory exception for repositories under TEST_OUTPUT_DIRECTORY. +See CONTRIBUTING.md for the cross-build and runner setup. + GIT_TEST_FAIL_PREREQS= fails all prerequisites. This is useful for discovering issues with the tests where say a later test implicitly depends on an optional earlier test. From c53dc4dc9bf00ac86643b53ca1ceace124b03dce Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 9 Sep 2026 16:40:48 +0200 Subject: [PATCH 3/3] CONTRIBUTING: document cross-compiling/-testing in WSL Due to its heritage, Git works best on Linux. Git for Windows does its best to accommodate for the ecosystem expected by Git (also for building Git), but Linux is still the platform where developing Git is the easiest. To help with developing Git for Windows, we can use the Windows Subsystem for Linux (WSL, pronounced like "whistle"), if we cross-compile. With the changes leading up to this commit, we also have the infrastructure to allow running the tests in WSL, using the WSL Bash with the cross-compiled `git.exe`. For some tests, using WSL Bash cannot work (or does not test the actually supported scenario in a full Git for Windows installation); To support such circumstances, the built `git.exe` can also be tested using a Git SDK Bash from a Git for Windows SDK installed on a Windows drive. Assisted-by: GPT-6 Signed-off-by: Johannes Schindelin --- CONTRIBUTING.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 48ff9029374df3..4560774b2526bf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -85,6 +85,65 @@ CMake, either by letting Visual Studio configure it automatically (simply open G top-level directory via `File>Open>Folder...`) or by (downloading and) running [CMake](https://cmake.org) manually. +## Building and testing in Windows Subsystem for Linux ("WSL") + +Install the Linux packages `gcc-mingw-w64-x86-64` and +`libz-mingw-w64-dev`. From the source directory in Linux Bash: + +```bash +cross=x86_64-w64-mingw32 +MSYSTEM=MINGW64 make -j"$(nproc)" uname_S=MINGW \ + CC="$cross-gcc" AR="$cross-ar" RC="$cross-windres -O coff" \ + MINGW_CHOST="$cross" NO_CURL=1 NO_GETTEXT=1 \ + NO_ICONV=1 NO_OPENSSL=1 NO_PERL=1 NO_PYTHON=1 \ + NO_RUST=1 NO_TCLTK=1 USE_LIBPCRE= +``` + +Prefer WSL Bash for speed. Use SDK Bash for Windows-specific prerequisites, +MSYS path handling or integrations such as `git svn` with Perl/SVN enabled. + +### Run tests with WSL Bash + +Install the Git for Windows SDK before testing. + +```bash +sdk=/mnt/d/git-sdk-64 +script=t0014-alias.sh +zlib=/usr/$cross/lib +ssp=$(dirname "$("$cross-gcc" -print-file-name=libssp-0.dll)") +output=$(mktemp -d) +( + export MSYSTEM=MINGW64 GIT_TEST_WSL=1 + export TEST_OUTPUT_DIRECTORY="$output" + export PATH="$ssp:$zlib:$sdk/mingw64/bin:$sdk/usr/bin:$PATH" + export Path="$PATH" + export WSLENV=MSYSTEM:Path/pl + # -V will write the detailed output to t/test-results/.out + cd t && time bash "$script" -iVx +) +``` + +Use `Path/pl`, not `PATH/pl`, to avoid duplicate Windows path entries. + +### Run tests with Git SDK Bash + +```bash +# MSYS2 `mkdir` cannot create directories in UNC paths; use $env:Temp +scratch=$(wslpath -u "$("$sdk/usr/bin/cygpath.exe" -m /tmp)") +output=$(mktemp -d -p "$scratch") +runtime="$(wslpath -m "$ssp"):$(wslpath -m "$zlib")" + +( + cd t && + time "$sdk/usr/bin/env.exe" MSYSTEM=MINGW64 \ + "PATH=$runtime:/mingw64/bin:/usr/bin" \ + "TEST_OUTPUT_DIRECTORY=$(wslpath -m "$output")" \ + "GIT_TEST_TEMPLATE_DIR=$(wslpath -m "$PWD/../templates/blt")" \ + "$(wslpath -m "$sdk")/usr/bin/bash.exe" \ + "$script" -iVx --no-bin-wrappers +) +``` + What to Change? ---------------