Skip to content

Commit

Permalink
Merge branch 'mo/perl-bidi-pipe-envfix' into maint
Browse files Browse the repository at this point in the history
* mo/perl-bidi-pipe-envfix:
  perl: command_bidi_pipe() method should set-up git environmens
  • Loading branch information
Junio C Hamano committed Mar 21, 2011
2 parents a8e04dd + 48d9e6a commit eec8a51
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
25 changes: 20 additions & 5 deletions perl/Git.pm
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ increase notwithstanding).

use Carp qw(carp croak); # but croak is bad - throw instead
use Error qw(:try);
use Cwd qw(abs_path);
use Cwd qw(abs_path cwd);
use IPC::Open2 qw(open2);
use Fcntl qw(SEEK_SET SEEK_CUR);
}
Expand Down Expand Up @@ -396,7 +396,16 @@ See C<command_close_bidi_pipe()> for details.

sub command_bidi_pipe {
my ($pid, $in, $out);
my ($self) = _maybe_self(@_);
local %ENV = %ENV;
my $cwd_save = undef;
if ($self) {
shift;
$cwd_save = cwd();
_setup_git_cmd_env($self);
}
$pid = open2($in, $out, 'git', @_);
chdir($cwd_save) if $cwd_save;
return ($pid, $in, $out, join(' ', @_));
}

Expand Down Expand Up @@ -843,7 +852,7 @@ sub _open_hash_and_insert_object_if_needed {

($self->{hash_object_pid}, $self->{hash_object_in},
$self->{hash_object_out}, $self->{hash_object_ctx}) =
command_bidi_pipe(qw(hash-object -w --stdin-paths --no-filters));
$self->command_bidi_pipe(qw(hash-object -w --stdin-paths --no-filters));
}

sub _close_hash_and_insert_object {
Expand Down Expand Up @@ -932,7 +941,7 @@ sub _open_cat_blob_if_needed {

($self->{cat_blob_pid}, $self->{cat_blob_in},
$self->{cat_blob_out}, $self->{cat_blob_ctx}) =
command_bidi_pipe(qw(cat-file --batch));
$self->command_bidi_pipe(qw(cat-file --batch));
}

sub _close_cat_blob {
Expand Down Expand Up @@ -1279,15 +1288,21 @@ sub _command_common_pipe {
# for the given repository and execute the git command.
sub _cmd_exec {
my ($self, @args) = @_;
_setup_git_cmd_env($self);
_execv_git_cmd(@args);
die qq[exec "@args" failed: $!];
}

# set up the appropriate state for git command
sub _setup_git_cmd_env {
my $self = shift;
if ($self) {
$self->repo_path() and $ENV{'GIT_DIR'} = $self->repo_path();
$self->repo_path() and $self->wc_path()
and $ENV{'GIT_WORK_TREE'} = $self->wc_path();
$self->wc_path() and chdir($self->wc_path());
$self->wc_subdir() and chdir($self->wc_subdir());
}
_execv_git_cmd(@args);
die qq[exec "@args" failed: $!];
}

# Execute the given Git command ($_[0]) with arguments ($_[1..])
Expand Down
10 changes: 10 additions & 0 deletions t/t9700/test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ BEGIN
my $dir_commit = $r2->command_oneline('log', '-n1', '--pretty=format:%H', '.');
isnt($last_commit, $dir_commit, 'log . does not show last commit');

# commands outside working tree
chdir($abs_repo_dir . '/..');
my $r3 = Git->repository(Directory => $abs_repo_dir);
my $tmpfile3 = "$abs_repo_dir/file3.tmp";
open TEMPFILE3, "+>$tmpfile3" or die "Can't open $tmpfile3: $!";
is($r3->cat_blob($file1hash, \*TEMPFILE3), 15, "cat_blob(outside): size");
close TEMPFILE3;
unlink $tmpfile3;
chdir($abs_repo_dir);

printf "1..%d\n", Test::More->builder->current_test;

my $is_passing = eval { Test::More->is_passing };
Expand Down

0 comments on commit eec8a51

Please sign in to comment.