path: root/t/
diff options
authorJohannes Schindelin <>2016-01-27 16:19:40 (GMT)
committerJunio C Hamano <>2016-01-27 22:27:19 (GMT)
commitfc56c7b34bd8027fb89ee432233f54028d71fb9e (patch)
tree2e5c9e3ebaf7e3360d547e55e8930d8781430b2d /t/
parent3064d5a38c72532e603faed4c63042b375ded2c7 (diff)
mingw: accomodate t0060-path-utils for MSYS2
On Windows, there are no POSIX paths, only Windows ones (an absolute Windows path looks like "C:\Program Files\Git\ReleaseNotes.html", under most circumstances, forward slashes are also allowed and synonymous to backslashes). So when a POSIX shell (such as MSYS2's Bash, which is used by Git for Windows to execute all those shell scripts that are part of Git) passes a POSIX path to test-path-utils.exe (which is not POSIX-aware), the path is translated into a Windows path. For example, /etc/profile becomes C:/Program Files/Git/etc/profile. This path translation poses a problem when passing the root directory as parameter to test-path-utils.exe, as it is not well defined whether the translated root directory should end in a slash or not. MSys1 stripped the trailing slash, but MSYS2 does not. Originally, the Git for Windows project patched MSYS2's runtime to accomodate Git's regression test, but we really should do it the other way round. To work with both of MSys1's and MSYS2's behaviors, we simply test what the current system does in the beginning of and then adjust the expected longest ancestor length accordingly. It looks quite a bit tricky what we actually do in this patch: first, we adjust the expected length for the trailing slash we did not originally expect (subtracting one). So far, so good. But now comes the part where things work in a surprising way: when the expected length was 0, the prefix to match is the root directory. If the root directory is converted into a path with a trailing slash, however, we know that the logic in longest_ancestor_length() cannot match: to avoid partial matches of the last directory component, it verifies that the character after the matching prefix is a slash (but because the slash was part of the matching prefix, the next character cannot be a slash). So the return value is -1. Alas, this is exactly what the expected length is after subtracting the value of $rootslash! So we skip adding the $rootoff value in that case (and only in that case). Directories other than the root directory are handled fine (as they are specified without a trailing slash, something not possible for the root directory, and MSYS2 converts them into Windows paths that also lack trailing slashes), therefore we do not need any more special handling. Thanks to Ray Donnelly for his patient help with this issue. Signed-off-by: Johannes Schindelin <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 't/')
1 files changed, 9 insertions, 0 deletions
diff --git a/t/ b/t/
index 627ef85..602b08b 100755
--- a/t/
+++ b/t/
@@ -36,12 +36,21 @@ if test $rootoff = 2; then
rootoff= # we are on Unix
+ # In MSYS2, the root directory "/" is translated into a Windows
+ # directory *with* trailing slash. Let's test for that and adjust
+ # our expected longest ancestor length accordingly.
+ case "$(test-path-utils print_path /)" in
+ */) rootslash=1;;
+ *) rootslash=0;;
+ esac
ancestor() {
# We do some math with the expected ancestor length.
if test -n "$rootoff" && test "x$expected" != x-1; then
+ expected=$(($expected-$rootslash))
+ test $expected -lt 0 ||
test_expect_success "longest ancestor: $1 $2 => $expected" \