Qgoda/Repository/Fetcher/Git.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 46 CC 3 SCAR 16.7
CC
3
Cov
0%
fetch
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 5.3
1 #! /bin/false
2  
3 # Copyright (C) 2016-2018 Guido Flohr <guido.flohr@cantanea.com>,
4 # all rights reserved.
5  
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10  
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15  
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18  
19 package Qgoda::Repository::Fetcher::Git;
20 $Qgoda::Repository::Fetcher::Git::VERSION = 'v0.9.2';
21 use strict;
22  
23 use Locale::TextDomain qw(qgoda);
24 use Git;
25 use File::Path qw(rmtree);
26  
27 use Qgoda;
28  
29 use base qw(Qgoda::Repository::Fetcher);
30  
31 sub fetch {
32 my ($self, $uri, $destination) = @_;
33  
34 my $logger = Qgoda->new->logger;
35  
36 $logger->debug(__x("cloning repository '{repository}'",
37 repository => $uri));
38  
39 # This will die in case of an error.
40 Git::command('clone', '--depth', '1', $uri, $destination);
41  
42 my $gitdir = File::Spec->catfile($destination, '.git');
43 $logger->debug(__x("deleting '{directory}'",
44 directory => $gitdir));
45  
46 rmtree $gitdir, { error => \my $err };
47 if (@$err) {
48 for my $diag (@$err) {
49 my ($file, $message) = %$diag;
50 if ($file eq '') {
51 $logger->error($message);
52 } else {
53 $logger->error(__x("error deleting '{file}': {error}",
54 file => $file, error => $!));
55 }
56 }
57 $logger->fatal(__"giving up after previous errors");
58 }
59  
60 return $destination;
61 }
62  
63 1;