@@ -99,7 +99,7 @@ increase notwithstanding).
99
99
100
100
use Carp qw( carp croak) ; # but croak is bad - throw instead
101
101
use Error qw( :try) ;
102
- use Cwd qw( abs_path) ;
102
+ use Cwd qw( abs_path cwd ) ;
103
103
use IPC::Open2 qw( open2) ;
104
104
use Fcntl qw( SEEK_SET SEEK_CUR) ;
105
105
}
@@ -396,7 +396,16 @@ See C<command_close_bidi_pipe()> for details.
396
396
397
397
sub command_bidi_pipe {
398
398
my ($pid , $in , $out );
399
+ my ($self ) = _maybe_self(@_ );
400
+ local %ENV = %ENV ;
401
+ my $cwd_save = undef ;
402
+ if ($self ) {
403
+ shift ;
404
+ $cwd_save = cwd();
405
+ _setup_git_cmd_env($self );
406
+ }
399
407
$pid = open2($in , $out , ' git' , @_ );
408
+ chdir ($cwd_save ) if $cwd_save ;
400
409
return ($pid , $in , $out , join (' ' , @_ ));
401
410
}
402
411
@@ -843,7 +852,7 @@ sub _open_hash_and_insert_object_if_needed {
843
852
844
853
($self -> {hash_object_pid }, $self -> {hash_object_in },
845
854
$self -> {hash_object_out }, $self -> {hash_object_ctx }) =
846
- command_bidi_pipe(qw( hash-object -w --stdin-paths --no-filters) );
855
+ $self -> command_bidi_pipe(qw( hash-object -w --stdin-paths --no-filters) );
847
856
}
848
857
849
858
sub _close_hash_and_insert_object {
@@ -932,7 +941,7 @@ sub _open_cat_blob_if_needed {
932
941
933
942
($self -> {cat_blob_pid }, $self -> {cat_blob_in },
934
943
$self -> {cat_blob_out }, $self -> {cat_blob_ctx }) =
935
- command_bidi_pipe(qw( cat-file --batch) );
944
+ $self -> command_bidi_pipe(qw( cat-file --batch) );
936
945
}
937
946
938
947
sub _close_cat_blob {
@@ -1279,15 +1288,21 @@ sub _command_common_pipe {
1279
1288
# for the given repository and execute the git command.
1280
1289
sub _cmd_exec {
1281
1290
my ($self , @args ) = @_ ;
1291
+ _setup_git_cmd_env($self );
1292
+ _execv_git_cmd(@args );
1293
+ die qq[ exec "@args " failed: $! ] ;
1294
+ }
1295
+
1296
+ # set up the appropriate state for git command
1297
+ sub _setup_git_cmd_env {
1298
+ my $self = shift ;
1282
1299
if ($self ) {
1283
1300
$self -> repo_path() and $ENV {' GIT_DIR' } = $self -> repo_path();
1284
1301
$self -> repo_path() and $self -> wc_path()
1285
1302
and $ENV {' GIT_WORK_TREE' } = $self -> wc_path();
1286
1303
$self -> wc_path() and chdir ($self -> wc_path());
1287
1304
$self -> wc_subdir() and chdir ($self -> wc_subdir());
1288
1305
}
1289
- _execv_git_cmd(@args );
1290
- die qq[ exec "@args " failed: $! ] ;
1291
1306
}
1292
1307
1293
1308
# Execute the given Git command ($_[0]) with arguments ($_[1..])
0 commit comments