What is the rule of MSYS/MinGW path translation?
The rules are officially documented with msys2 "Filesystem Paths".
See for instance "Automatic Unix ⟶ Windows Path Conversion"
Process Arguments
When calling native executable from the context of Cygwin then all
the arguments that look like Unix paths will get auto converted to
Windows.
For example when calling native Python from the context of
bash:
$ python3 -c "import sys; print(sys.argv)" --dir=/foo ['-c',
'--dir=C:/msys64/foo'] $ python3 -c "import sys; print(sys.argv)"
--dir=/foo:/bla ['-c', '--dir=C:\\msys64\\foo;C:\\msys64\\bla']
While this is helpful in many cases it's also not perfect and in
corner cases converts arguments that look like Unix paths while they
are not, or detects lists of Unix paths where there are none.
For
these cases you can exclude certain arguments via the
MSYS2_ARG_CONV_EXCL
environment variable:
$ MSYS2_ARG_CONV_EXCL='--dir=' python3 -c "import sys;
print(sys.argv)" --dir=/foo ['-c', '--dir=/foo']
MSYS2_ARG_CONV_EXCL
can either be * to mean exclude everything, or a
list of one or more arguments prefixes separated by ;
, like
MSYS2_ARG_CONV_EXCL=--dir=;--bla=;/test
.
It matches the prefix
against the whole argument string.
This is also illustrated with Git 2.40 (Q1 2023), which illustrates those rules in the context of a test fix:
See commit 95494c6 (06 Dec 2022) by Johannes Schindelin (dscho
).
(Merged by Junio C Hamano -- gitster
-- in commit 26f8123, 14 Dec 2022)
t0021
: use Windows-friendly pwd
Signed-off-by: Johannes Schindelin
In Git for Windows, when passing paths from shell scripts to regular Win32 executables, thanks to the MSYS2 runtime a somewhat magic path conversion happens that lets the shell script think that there is a file at /git/Makefile
and the Win32 process it spawned thinks that the shell script said C:/git-sdk-64/git/Makefile
instead.
This conversion is documented in detail over here: https://www.msys2.org/docs/filesystem-paths/#automatic-unix-windows-path-conversion
As all automatic conversions, there are gaps.
For example, to avoid mistaking command-line options like /LOG=log.txt
(which are quite common in the Windows world) from being mistaken for a Unix-style absolute path, the MSYS2 runtime specifically exempts arguments containing a =
character from that conversion.
We are about to change test_cmp
to use git diff --no-index
(man), which involves spawning precisely such a Win32 process.
In combination, this would cause a failure in t0021-conversion.sh
where we pass an absolute path containing an equal character to the test_cmp
function.
Seeing as the Unix tools like cp
and diff
that are used by Git's test suite in the Git for Windows SDK (thanks to the MSYS2 project) understand both Unix-style as well as Windows-style paths, we can stave off this problem by simply switching to Windows-style paths and side-stepping the need for any automatic path conversion.
Note: The PATH
variable is obviously special, as it is colon-separated in the MSYS2 Bash used by Git for Windows, and therefore cannot contain absolute Windows-style paths, lest the colon after the drive letter is mistaken for a path separator.
Therefore, we need to be careful to keep the Unix-style when modifying the PATH
variable.