File Coverage

blib/lib/Banal/Dist/Util/Git.pm
Criterion Covered Total %
statement 20 37 54.0
branch 0 14 0.0
condition 0 9 0.0
subroutine 7 8 87.5
pod 0 1 0.0
total 27 69 39.1


line stmt bran cond sub pod time code
1 1     1   222011 use 5.014; # because we use the 'state' and 'non-destructive substitution' feature (s///r)
  1         16  
2 1     1   7 use strict;
  1         2  
  1         53  
3 1     1   13 use warnings;
  1         10  
  1         174  
4              
5             package Banal::Dist::Util::Git;
6             # vim: set ts=2 sts=2 sw=2 tw=115 et :
7             # ABSTRACT: General purpose utility collection for
8             # KEYWORDS: author utility
9              
10             our $VERSION = '0.005';
11             # AUTHORITY
12              
13 1     1   826 use Path::Tiny;
  1         12342  
  1         99  
14              
15 1         6 use Exporter::Shiny qw(
16             detect_settings_from_git
17 1     1   433 );
  1         4066  
18              
19 1     1   517 use namespace::autoclean;
  1         18088  
  1         15  
20              
21              
22             # Detect settings (like remote 'server') from the local git repository
23             sub detect_settings_from_git {
24 0     0 0   my %args = @_;
25 0   0       my $dir = $args{dir} || Path::Tiny->cwd;
26 0           my %detected;
27              
28             REMOTE: {
29 0           eval {
  0            
30 0           my $git = Git::Wrapper->new( $dir );
31 0           my @lines = $git->remote( {v=>1} );
32 0   0       /^(\S+)\s+(\S+)\s+\(fetch\)$/i and $detected{remotes}{$1}=$2 foreach (@lines);
33             };
34              
35 0 0 0       last REMOTE unless ( exists $detected{remotes} ) && ( exists $detected{remotes}{origin} );
36 0 0         last REMOTE unless $detected{remotes}{origin} =~ qr{^ (https?|git):/(?.*)?/
37             (? .* ) / (:? (? .*) /)? (? .*) \.git$}xi;
38 1     1   701 my ($domain, $folder) = ( $+{domain}, $+{folder} );
  1         385  
  1         238  
  0            
39              
40 0 0         if ( $domain =~ /^((?github)\.com) | ((?bitbucket)\.org)$/xi) {
    0          
    0          
41 0           my $server = $detected{server} = $+{server};
42 0           $detected{"server_amr_opt_${server}"}= "user:${folder}"; # for [AutoMetaResources]
43             } elsif ( $domain =~ /^git\.moose\.perl\.org$/xi ) {
44 0           $detected{server} = 'gitmo';
45             } elsif ( $domain =~ /^git\.shadowcat\.co\.uk$/xi ) {
46 0 0         $detected{server} = $folder if $folder =~ /^catagits|p5sagit|dbsrgits$/;
47             }
48             }
49 0 0         wantarray ? (%detected) : \%detected;
50             }
51              
52              
53             1;
54              
55             __END__