Skip to content

Commit fc56c7b

Browse files
dschogitster
authored andcommitted
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 t0060-path-utils.sh 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3064d5a commit fc56c7b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

t/t0060-path-utils.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,21 @@ if test $rootoff = 2; then
3636
rootoff= # we are on Unix
3737
else
3838
rootoff=$(($rootoff-1))
39+
# In MSYS2, the root directory "/" is translated into a Windows
40+
# directory *with* trailing slash. Let's test for that and adjust
41+
# our expected longest ancestor length accordingly.
42+
case "$(test-path-utils print_path /)" in
43+
*/) rootslash=1;;
44+
*) rootslash=0;;
45+
esac
3946
fi
4047

4148
ancestor() {
4249
# We do some math with the expected ancestor length.
4350
expected=$3
4451
if test -n "$rootoff" && test "x$expected" != x-1; then
52+
expected=$(($expected-$rootslash))
53+
test $expected -lt 0 ||
4554
expected=$(($expected+$rootoff))
4655
fi
4756
test_expect_success "longest ancestor: $1 $2 => $expected" \

0 commit comments

Comments
 (0)