Skip to content

Commit c8abd5a

Browse files
committed
t5813: allow for $PWD to be a Windows path
Git for Windows uses MSYS2's Bash to run the test suite, which comes with benefits but also at a heavy price: on the plus side, MSYS2's POSIX emulation layer allows us to continue pretending that we are on a Unix system, e.g. use Unix paths instead of Windows ones, yet this is bought at a rather noticeable performance penalty. There *are* some more native ports of Unix shells out there, though, most notably BusyBox-w32's ash. These native ports do not use any POSIX emulation layer (or at most a *very* thin one, choosing to avoid features such as fork() that are expensive to emulate on Windows), and they use native Windows paths (usually with forward slashes instead of backslashes, which is perfectly legal in almost all use cases). And here comes the problem: with a $PWD looking like, say, C:/git-sdk-64/usr/src/git/t/trash directory.t5813-proto-disable-ssh Git's test scripts get quite a bit confused, as their assumptions have been shattered. Not only does this path contain a colon (oh no!), it also does not start with a slash. This is a problem e.g. when constructing a URL as t5813 does it: ssh://remote$PWD. Not only is it impossible to separate the "host" from the path with a $PWD as above, even prefixing $PWD by a slash won't work, as /C:/git-sdk-64/... is not a valid path. As a workaround, detect when $PWD does not start with a slash on Windows, and simply strip the drive prefix, using an obscure feature of Windows paths: if an absolute Windows path starts with a slash, it is implicitly prefixed by the drive prefix of the current directory. As we are talking about the current directory here, anyway, that strategy works. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent dd72cd0 commit c8abd5a

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

t/t5813-proto-disable-ssh.sh

+17-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,23 @@ test_expect_success 'setup repository to clone' '
1414
'
1515

1616
test_proto "host:path" ssh "remote:repo.git"
17-
test_proto "ssh://" ssh "ssh://remote$PWD/remote/repo.git"
18-
test_proto "git+ssh://" ssh "git+ssh://remote$PWD/remote/repo.git"
17+
18+
hostdir="$PWD"
19+
if test_have_prereq MINGW && test "/${PWD#/}" != "$PWD"
20+
then
21+
case "$PWD" in
22+
[A-Za-z]:/*)
23+
hostdir="${PWD#?:}"
24+
;;
25+
*)
26+
skip_all="Unhandled PWD '$PWD'; skipping rest"
27+
test_done
28+
;;
29+
esac
30+
fi
31+
32+
test_proto "ssh://" ssh "ssh://remote$hostdir/remote/repo.git"
33+
test_proto "git+ssh://" ssh "git+ssh://remote$hostdir/remote/repo.git"
1934

2035
# Don't even bother setting up a "-remote" directory, as ssh would generally
2136
# complain about the bogus option rather than completing our request. Our

0 commit comments

Comments
 (0)