Devel/Git.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Database/Vfeed.pm ↑ Summary Devel/Mercurial.pm »
1 #
2 # $Id$
3 #
4 # devel::git Brik
5 #
6 package Metabrik::Devel::Git;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik::Shell::Command Metabrik::System::Package);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
17 license => 'http://opensource.org/licenses/BSD-3-Clause',
18 attributes => {
19 datadir => [ qw(datadir) ],
20 capture_mode => [ qw(0|1) ],
21 use_sudo => [ qw(0|1) ],
22 use_pager => [ qw(0|1) ],
23 },
24 attributes_default => {
25 capture_mode => 0,
26 use_sudo => 0,
27 use_pager => 1,
28 },
29 commands => {
30 install => [ ], # Inherited
31 clone => [ qw(repository directory|OPTIONAL) ],
32 update => [ qw(repository directory|OPTIONAL) ],
33 update_or_clone => [ qw(repository directory|OPTIONAL) ],
34 },
35 require_binaries => {
36 git => [ ],
37 },
38 need_packages => {
39 ubuntu => [ qw(git) ],
40 debian => [ qw(git) ],
41 kali => [ qw(git) ],
42 },
43 };
44 }
45  
46 sub clone {
47 my $self = shift;
48 my ($repository, $directory) = @_;
49  
50 $self->brik_help_run_undef_arg('clone', $repository) or return;
51  
52 if (! defined($directory)) {
53 my $datadir = $self->datadir;
54  
55 $directory ||= $datadir;
56 my ($name) = $repository =~ m{^.*/(.*)$};
57 $directory .= '/'.$name;
58 }
59  
60 my $cmd = "git clone $repository $directory";
61  
62 $self->execute($cmd) or return;
63  
64 return $directory;
65 }
66  
67 sub update {
68 my $self = shift;
69 my ($repository, $directory) = @_;
70  
71 $self->brik_help_run_undef_arg('update', $repository) or return;
72  
73 if (! defined($directory)) {
74 my $datadir = $self->datadir;
75  
76 $directory ||= $datadir;
77 my ($name) = $repository =~ m{^.*/(.*)$};
78 $directory .= '/'.$name;
79 }
80  
81 my $cmd = "git pull -u $repository $directory";
82  
83 $self->execute($cmd) or return;
84  
85 return $directory;
86 }
87  
88 sub update_or_clone {
89 my $self = shift;
90 my ($repository, $directory) = @_;
91  
92 $self->brik_help_run_undef_arg('update_or_clone', $repository) or return;
93  
94 if (defined($directory) && -d $directory) {
95 return $self->update($repository, $directory);
96 }
97  
98 return $self->clone($repository, $directory);
99 }
100  
101 1;
102  
103 __END__
« Database/Vfeed.pm ↑ Summary Devel/Mercurial.pm »