Skip to content

Commit dffb15e

Browse files
committed
Improve testing on native Windows
Modify the testing infrastructure to better work with Git for Windows on native Windows. Due to limitations/bugs in the current implementation of Git.pm, git-svn-diff will not run in this environment. However, once those issues are addressed upstream, these changes will make it possible to validate git-svn-diff. When it all comes together, users will be able to run git-svn-diff in a native Windows environment (assuming they have Perl installed somewhere, with a modern Git.pm). Batch or PowerShell scripts will be possible; users can completely avoid Git Bash, if they so desire. Issue: #39
1 parent 6d05660 commit dffb15e

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

t/lib/Temp/Repo.pm

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ sub _initialize {
3232
my $dir = $self->{dir};
3333
__run_in($dir, qw(svnadmin create repo));
3434

35-
my $repo = "file://@{[File::Spec::Unix->canonpath($dir)]}/repo";
35+
my $base = File::Spec::Unix->canonpath($dir);
36+
if ($^O eq "MSWin32") {
37+
$base =~ s{\\}{/}g;
38+
$base = "/$base";
39+
}
40+
41+
my $repo = "file://$base/repo";
3642
$self->{repo} = $repo;
3743

3844
# Setup the standard layout, if requested.
@@ -44,6 +50,7 @@ sub _initialize {
4450

4551
# Clone SVN & Git repositories.
4652
__run_in($dir, qw(svn checkout -q), $repo, "svn");
53+
$repo =~ s{^(file:///\w):}{$1} if $^O eq "MSWin32"; # Workaround for https://github.com/git-for-windows/git/issues/1593
4754
__run_in($dir, qw(git svn init), @git_opts, $repo, "git");
4855
}
4956

@@ -150,7 +157,7 @@ sub svn_diff {
150157

151158
sub git_svn_diff {
152159
my ($self, @args) = @_;
153-
my ($out, $err) = __capture_cmd($self->get_git_wc(), $diff_bin, @args);
160+
my ($out, $err) = __capture_cmd($self->get_git_wc(), $^X, $diff_bin, @args);
154161
warn $err if $err;
155162
return $out;
156163
}
@@ -162,6 +169,7 @@ sub create_git_orderfile {
162169

163170
my $file = File::Spec->catfile($self->{dir}, "orderfile");
164171
open my $fh, '>', $file or die "Cannot open file “$file”: $!";
172+
binmode $fh or die "Cannot set binmode: $!"; # Needed for Git on Windows
165173
print {$fh} join "\n", @order, '';
166174
close $fh or warn "Cannot close file “$file”: $!";
167175

t/no-svn-commits.t

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@ system qw(git commit -m), "Modifications";
1919

2020
write_file("file", "Changed contents\nWorking copy\n");
2121

22-
my $got = qx{"$diff_bin" -c 1 2>&1};
22+
my $got = qx{"$^X" "$diff_bin" -c 1 2>&1};
2323
my $expected = <<ERR;
2424
fatal: Cannot find revision: 1
2525
ERR
2626
is($got, $expected, "Revision 1 not found");
2727

28-
$got = qx{"$diff_bin" -c 2 2>&1};
28+
$got = qx{"$^X" "$diff_bin" -c 2 2>&1};
2929
$expected = <<ERR;
3030
fatal: Cannot find revision: 2
3131
ERR
3232
is($got, $expected, "Revision 2 not found");
3333

34-
$got = qx{"$diff_bin" HEAD^ HEAD 2>&1};
34+
$got = qx{"$^X" "$diff_bin" HEAD^ HEAD 2>&1};
3535
$expected = <<ERR;
3636
fatal: Commit '[0-9a-f]{40}' must be in SVN repository
3737
ERR
3838
like($got, qr/$expected/, "Cannot resolve revision");
3939

40-
$got = qx{"$diff_bin" 2>&1};
40+
$got = qx{"$^X" "$diff_bin" 2>&1};
4141
$expected = <<ERR;
4242
fatal: Cannot find SVN base commit in branch
4343
ERR
4444
is($got, $expected, "Cannot resolve revision");
4545

46-
my $got = qx{"$diff_bin" -r 1 2>&1};
46+
my $got = qx{"$^X" "$diff_bin" -r 1 2>&1};
4747
my $expected = <<ERR;
4848
fatal: Cannot find revision: 1
4949
ERR

t/no-svn-remote.t

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
use FindBin;
44
use lib "$FindBin::Bin/lib";
55

6+
use File::chdir;
7+
68
use Test::More tests => 2;
79
use Test::Repo;
810

@@ -49,7 +51,11 @@ Test::Repo::test_diff($repo, name => "Diff with BASE");
4951
my $diff_bin = "$FindBin::Bin/../bin/git-svn-diff";
5052
my $dir = $repo->get_git_wc();
5153

52-
my $got = qx{cd "$dir"; "$diff_bin" --relative-repo 2>&1};
54+
my $got;
55+
{
56+
local $CWD = $dir;
57+
$got = qx{"$^X" "$diff_bin" --relative-repo 2>&1};
58+
}
5359
my $expected = <<ERR;
5460
svn info: command returned error: 1
5561
ERR

0 commit comments

Comments
 (0)