Skip to content

Commit 2d32983

Browse files
committed
t9700: accommodate for Windows paths
Ever since fe53bbc (Git.pm: Always set Repository to absolute path if autodetecting, 2009-05-07), the t9700 test _must_ fail on Windows because of that age-old Unix paths vs Windows paths problem. The underlying root cause is that Git cannot run with a regular Win32 variant of Perl, the assumption that every path is a Unix path is just too strong in Git's Perl code. As a consequence, Git for Windows is basically stuck with using the MSYS2 variant of Perl which uses a POSIX emulation layer (which is a friendly fork of Cygwin) _and_ a best-effort Unix <-> Windows paths conversion whenever crossing the boundary between MSYS2 and regular Win32 processes. It is best effort only, though, using heuristics to automagically convert correctly in most cases, but not in all cases. In the context of this here patch, this means that asking `git.exe` for the absolute path of the `.git/` directory will return a Win32 path because `git.exe` is a regular Win32 executable that has no idea about Unix-ish paths. But above-mentioned commit introduced a test that wants to verify that this path is identical to the one that the Git Perl module reports (which refuses to use Win32 paths and uses Unix-ish paths instead). Obviously, this must fail because no heuristics can kick in at that layer. This test failure has not even been caught when Git introduced Windows support in its CI definition in 2e90484 (ci: add a Windows job to the Azure Pipelines definition, 2019-01-29), as all tests relying on Perl had to be disabled even from the start (because the CI runs would otherwise have resulted in prohibitively long runtimes, not because Windows is super slow per se, but because Git's test suite keeps insisting on using technology that requires a POSIX emulation layer, which _is_ super slow on Windows). To work around this failure, let's use the `cygpath` utility to convert the absolute `gitdir` path into the form that the Perl code expects. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 9a2fb14 commit 2d32983

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

t/t9700/test.pl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ sub adjust_dirsep {
117117
unlink $tmpfile;
118118

119119
# paths
120-
is($r->repo_path, $abs_repo_dir . "/.git", "repo_path");
120+
my $abs_git_dir = $abs_repo_dir . "/.git";
121+
if ($^O eq 'msys' or $^O eq 'cygwin') {
122+
$abs_git_dir = `cygpath -am "$abs_repo_dir/.git"`;
123+
$abs_git_dir =~ s/\r?\n?$//;
124+
}
125+
is($r->repo_path, $abs_git_dir, "repo_path");
121126
is($r->wc_path, $abs_repo_dir . "/", "wc_path");
122127
is($r->wc_subdir, "", "wc_subdir initial");
123128
$r->wc_chdir("directory1");
@@ -127,7 +132,7 @@ sub adjust_dirsep {
127132
# Object generation in sub directory
128133
chdir("directory2");
129134
my $r2 = Git->repository();
130-
is($r2->repo_path, $abs_repo_dir . "/.git", "repo_path (2)");
135+
is($r2->repo_path, $abs_git_dir, "repo_path (2)");
131136
is($r2->wc_path, $abs_repo_dir . "/", "wc_path (2)");
132137
is($r2->wc_subdir, "directory2/", "wc_subdir initial (2)");
133138

0 commit comments

Comments
 (0)