Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 5fd4faa

Browse files
committed
workaround for issue 182 (git add -p or git add -i with a subdirectory)
inspired by pull request 218 using code from @PhilipDavis
1 parent dd8b3ba commit 5fd4faa

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

git-add--interactive.perl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,48 @@ sub run_cmd_pipe {
177177
die "$^O does not support: @invalid\n" if @invalid;
178178
my @args = map { m/ /o ? "\"$_\"": $_ } @_;
179179
return qx{@args};
180+
} elsif (($^O eq 'MSWin32' || $^O eq 'msys') && (scalar @_ > 200)) {
181+
182+
# workaround for https://github.com/msysgit/git/issues/182
183+
# mostly the work of @PhilipDavis, circa 2014-08-07
184+
185+
my @myArgs = @_;
186+
my $cmd = "@myArgs";
187+
my $path = "$ENV{APPDATA}";
188+
$path =~ s/\\/\//g;
189+
190+
use File::Temp qw(tempfile);
191+
# for troubleshooting, you might find it useful to eliminate the UNLINK setting:
192+
my ($fhargs, $filename) = tempfile("$path/git-args-XXXXXX", UNLINK => 1);
193+
194+
if (grep $_ eq "--", @myArgs) {
195+
196+
$cmd = "";
197+
while ($myArgs[0] ne '--') {
198+
$cmd = $cmd . shift(@myArgs) . " ";
199+
}
200+
201+
$cmd = $cmd . "-- ";
202+
shift(@myArgs);
203+
204+
foreach (@myArgs) {
205+
# if files have whitespace in the name, quotes around $_ are mandatory:
206+
print $fhargs "\"$_\" \n";
207+
}
208+
209+
$fhargs->flush;
210+
211+
# 2015 may 26: @kkheller using cat to xargs instead of "< $filename"
212+
$cmd = "cat $filename | xargs -s 20000 " . $cmd;
213+
}
214+
215+
print "$filename\n";
216+
print "$cmd \n\n";
217+
218+
my $fh = undef;
219+
open($fh, '-|', $cmd) or die;
220+
return <$fh>;
221+
180222
} else {
181223
my $fh = undef;
182224
open($fh, '-|', @_) or die;

0 commit comments

Comments
 (0)