Skip to content

Commit

Permalink
t5813: allow for $PWD to be a Windows path
Browse files Browse the repository at this point in the history
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 <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Sep 16, 2022
1 parent a1fad28 commit f47e268
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions t/t5813-proto-disable-ssh.sh
Expand Up @@ -14,8 +14,23 @@ test_expect_success 'setup repository to clone' '
'

test_proto "host:path" ssh "remote:repo.git"
test_proto "ssh://" ssh "ssh://remote$PWD/remote/repo.git"
test_proto "git+ssh://" ssh "git+ssh://remote$PWD/remote/repo.git"

hostdir="$PWD"
if test_have_prereq MINGW && test "/${PWD#/}" != "$PWD"
then
case "$PWD" in
[A-Za-z]:/*)
hostdir="${PWD#?:}"
;;
*)
skip_all="Unhandled PWD '$PWD'; skipping rest"
test_done
;;
esac
fi

test_proto "ssh://" ssh "ssh://remote$hostdir/remote/repo.git"
test_proto "git+ssh://" ssh "git+ssh://remote$hostdir/remote/repo.git"

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

0 comments on commit f47e268

Please sign in to comment.