| 1 | package Git::LowLevel::Reference; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: class representing a reference in a git repository | ||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use MooseX::Privacy; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Git::LowLevel::Tree; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | has 'repository' => (is => 'ro', isa => 'Git::LowLevel', required => 1); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | has 'reference' => (is => 'ro', isa => 'Str', required=>1); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | has '_hash' => (is => 'rw', isa => 'Str', default => "empty", traits => [qw/Private/]); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 4 | has 'tree' => (is => 'rw', isa => 'Git::LowLevel::Tree'); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub exist | ||||||||||||||||||||||||||||
| 19 | 13 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
exist: called CC=3 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 13 | my $self =shift; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 13 | my $help = readpipe($self->repository->gitcmd() . " show-ref --dereference"); | |||||||||||||||||||||||||||
| 23 | 13 | my @lines = split /\n/,$help; | |||||||||||||||||||||||||||
| 24 | 13 | for my $line (@lines) | |||||||||||||||||||||||||||
| 25 | { | ||||||||||||||||||||||||||||
| 26 | 0 | $line =~/^([0-9a-fA-F]+)\s(.+)$/; | |||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ($2 eq $self->reference) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||
| 29 | 0 | $self->_hash($1); | |||||||||||||||||||||||||||
| 30 | 0 | return 1; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 13 | return 0; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub hash | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
hash: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | die("reference does not exist") unless $self->exist(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | return $self->_hash; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub getTree | ||||||||||||||||||||||||||||
| 47 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getTree: called CC=6 SCAR=23.5
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 49 | 7 | my $help; | |||||||||||||||||||||||||||
| 50 | 7 | ▶ | if ($self->exist) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | $help = readpipe($self->repository->gitcmd() . " cat-file -p " . $self->_hash); | |||||||||||||||||||||||||||
| 52 | 0 | my @lines = split /\n/,$help; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($lines[0]=~/^tree\s(.*)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||
| 55 | 0 | $help=$1; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 7 | ▶ | if (!defined($help) || length($help) == 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $help or length $help == 0
MC/DC0%0/2
not defined $help or length $help == 0
not defined $help
length $help == 0
Truth table33%1/3
not(A) or B
A= not defined $helpB= length $help == 0
| |||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||
| 60 | 7 | $help="empty"; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 7 | ▶ | if ($help eq "empty") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||
| 65 | 7 | $self->tree(Git::LowLevel::Tree->new(repository=> $self->repository, reference=> $self, hash => $help)); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | else | ||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||
| 69 | 0 | $self->tree(Git::LowLevel::Tree->new(repository=> $self->repository, reference=> $self, hash => $help, changed=>1)); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 7 | return $self->tree; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub find | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
find: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 77 | 0 | my $path = shift; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | return $self->getTree()->find($path); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | sub commit | ||||||||||||||||||||||||||||
| 83 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
commit: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 85 | 3 | my $comment = shift; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 3 | ▶ | die("no comment given") unless defined($comment); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 3 | $self->exist; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 3 | ▶ | return unless defined($self->tree); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 3 | $self->tree->save(); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 3 | my $cmd = "/bin/echo -e \'" . $comment. "\' | " . $self->repository->gitcmd() . " commit-tree " . $self->tree->hash; | |||||||||||||||||||||||||||
| 96 | 3 | ▶ | if (length($self->_hash) == 40) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||
| 98 | 0 | $cmd .= " -p " . $self->_hash; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 3 | my $help = readpipe($cmd); | |||||||||||||||||||||||||||
| 101 | 3 | chomp($help); | |||||||||||||||||||||||||||
| 102 | 3 | $self->_hash($help); | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 3 | $help = readpipe($self->repository->gitcmd() . " update-ref " . $self->reference . " " . $self->_hash); | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 4 | 1; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | __END__ | ||||||||||||||||||||||||||||