Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input_record_separator option to Git::Repository::Command::new #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/Git/Repository/Command.pm
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,13 @@ sub final_output {
my ($self, @cb) = @_;

# get output / errput
my $input_record_separator =
exists $self->options->{input_record_separator}
? $self->options->{input_record_separator}
: "\n";
my ( @output, @errput );
$self->loop_on(
input_record_separator => "\n",
input_record_separator => $input_record_separator,
stdout => sub { chomp( my $o = shift ); push @output, $o; },
stderr => sub { chomp( my $e = shift ); push @errput, $e; },
);
Expand Down Expand Up @@ -333,6 +337,20 @@ Boolean option to control the output of warnings.
If true, methods such as C<final_output()> will not warn when Git outputs
messages on C<STDERR>.

=item C<input_record_separator>

A string which the C<$/> special variable is set to during the command
execution.

This is mostly useful when passing the C<-z> option to a Git command so that it
output lines separated by the NUL character and you want to get it line by line,
like this:

my @files = $git->run(
qw/ls-tree -r --name-only -z HEAD/,
{ input_record_separator => "\0" },
);

=back

If the L<Git::Repository> object has its own option hash, it will be used
Expand Down
7 changes: 7 additions & 0 deletions t/20-simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,10 @@ ok( $r = eval { Git::Repository->new( work_tree => $dir ) },
$tree = $r->run( mktree => { input => '' } );
is( $tree, '4b825dc642cb6eb9a060e54bf8d69288fbee4904', 'mktree empty tree' );

# use ls-tree with input_record_separator option
BEGIN { $tests += 1 }
my @files = $r->run(
qw/ls-tree --name-only -z HEAD/,
{ input_record_separator => "\0" },
);
ok( @files > 1, 'option input_record_separator in run() worked');