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.

To work with both 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.

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.

Thanks to Ray Donnelly for his patient help with this issue.

Signed-off-by: Johannes Schindelin <johannes.schinde...@gmx.de>
---
 t/t0060-path-utils.sh | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index f0152a7..89d03e7 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -7,6 +7,13 @@ test_description='Test various path utilities'
 
 . ./test-lib.sh
 
+# On Windows, the root directory "/" is translated into a Windows directory.
+# As it is not well-defined whether that Windows directory should end in a
+# slash or not, let's test for that and adjust our expected longest ancestor
+# length accordingly.
+root_offset=0
+case "$(test-path-utils print_path /)" in ?*/) root_offset=-1;; esac
+
 norm_path() {
        expected=$(test-path-utils print_path "$2")
        test_expect_success $3 "normalize path: $1 => $2" \
@@ -112,30 +119,30 @@ norm_path /d1/.../d2 /d1/.../d2
 norm_path /d1/..././../d2 /d1/d2
 
 ancestor / / -1
-ancestor /foo / 0
+ancestor /foo / $root_offset
 ancestor /foo /fo -1
 ancestor /foo /foo -1
 ancestor /foo /bar -1
 ancestor /foo /foo/bar -1
 ancestor /foo /foo:/bar -1
-ancestor /foo /:/foo:/bar 0
-ancestor /foo /foo:/:/bar 0
-ancestor /foo /:/bar:/foo 0
-ancestor /foo/bar / 0
+ancestor /foo /:/foo:/bar $root_offset
+ancestor /foo /foo:/:/bar $root_offset
+ancestor /foo /:/bar:/foo $root_offset
+ancestor /foo/bar / $root_offset
 ancestor /foo/bar /fo -1
-ancestor /foo/bar /foo 4
+ancestor /foo/bar /foo $((4+$root_offset))
 ancestor /foo/bar /foo/ba -1
-ancestor /foo/bar /:/fo 0
-ancestor /foo/bar /foo:/foo/ba 4
+ancestor /foo/bar /:/fo $root_offset
+ancestor /foo/bar /foo:/foo/ba $((4+$root_offset))
 ancestor /foo/bar /bar -1
 ancestor /foo/bar /fo -1
-ancestor /foo/bar /foo:/bar 4
-ancestor /foo/bar /:/foo:/bar 4
-ancestor /foo/bar /foo:/:/bar 4
-ancestor /foo/bar /:/bar:/fo 0
-ancestor /foo/bar /:/bar 0
-ancestor /foo/bar /foo 4
-ancestor /foo/bar /foo:/bar 4
+ancestor /foo/bar /foo:/bar $((4+$root_offset))
+ancestor /foo/bar /:/foo:/bar $((4+$root_offset))
+ancestor /foo/bar /foo:/:/bar $((4+$root_offset))
+ancestor /foo/bar /:/bar:/fo $root_offset
+ancestor /foo/bar /:/bar $root_offset
+ancestor /foo/bar /foo $((4+$root_offset))
+ancestor /foo/bar /foo:/bar $((4+$root_offset))
 ancestor /foo/bar /bar -1
 
 test_expect_success 'strip_path_suffix' '
-- 
2.7.0.windows.1.7.g55a05c8


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to