From 03a92547197e375ac5e76e7b9976e3d3291137c0 Mon Sep 17 00:00:00 2001 From: Sergey Panteleev Date: Wed, 28 Jun 2023 14:56:15 +0300 Subject: [PATCH] extended debug for git interaction --- lib/App/cpm/Worker/Installer.pm | 14 ++++++++++---- lib/App/cpm/Worker/Installer/Menlo.pm | 7 +++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/App/cpm/Worker/Installer.pm b/lib/App/cpm/Worker/Installer.pm index dcf0be86..466d0287 100644 --- a/lib/App/cpm/Worker/Installer.pm +++ b/lib/App/cpm/Worker/Installer.pm @@ -126,16 +126,22 @@ sub _fetch_git { DIR => $self->menlo->{base}, ); $self->menlo->mask_output( diag_progress => "Cloning $uri" ); - $self->menlo->run_command([ 'git', 'clone', $uri, $dir ]); - - unless (-e "$dir/.git") { + my ($ok, $res) = $self->menlo->run_command([ 'git', 'clone', $uri, $dir ]); + if (!$ok || !-e "$dir/.git") { $self->menlo->diag_fail("Failed cloning git repository $uri", 1); + if ($res->{stdout}) { + $self->menlo->diag_fail($_, 1) foreach map { " $_" } split /\r?\n/, $res->{stdout}; + } return; } my $guard = pushd $dir; if ($ref) { - unless ($self->menlo->run_command([ 'git', 'checkout', $ref ])) { + ($ok, $res) = $self->menlo->run_command([ 'git', 'checkout', $ref ]); + unless ($ok) { $self->menlo->diag_fail("Failed to checkout '$ref' in git repository $uri\n"); + if ($res->{stdout}) { + $self->menlo->diag_fail($_, 1) foreach map { " $_" } split /\r?\n/, $res->{stdout}; + } return; } } diff --git a/lib/App/cpm/Worker/Installer/Menlo.pm b/lib/App/cpm/Worker/Installer/Menlo.pm index eb39a131..aa8a33a2 100644 --- a/lib/App/cpm/Worker/Installer/Menlo.pm +++ b/lib/App/cpm/Worker/Installer/Menlo.pm @@ -55,7 +55,6 @@ sub log { sub run_command { my ($self, $cmd) = @_; $self->run_timeout($cmd, 0); - } sub run_timeout { @@ -66,7 +65,7 @@ sub run_timeout { my $runner = Command::Runner->new( command => $cmd, - keep => 0, + keep => 1, redirect => 1, timeout => $timeout, stdout => sub { $self->log(@_) }, @@ -76,8 +75,8 @@ sub run_timeout { $self->diag_fail("Timed out (> ${timeout}s)."); return; } - my $result = $res->{result}; - ref $cmd eq 'CODE' ? $result : $result == 0; + my $result = ref $cmd eq 'CODE' ? $res->{result} : $res->{result} == 0; + return wantarray ? ($result, $res) : $result; } 1;