| 1 | package Git::LowLevel; | ||||||||||
| 2 | # ABSTRACT: LowLevel Blob/Tree/Commit operations on a GIT Repository | ||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use MooseX::Privacy; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use Git::LowLevel::Reference; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | |||||||||||
| 10 | |||||||||||
| 11 | 4 | has 'git_dir' => (is => 'ro', isa => 'Str', required => 1); | |||||||||
| 12 | |||||||||||
| 13 | 4 | has 'gitcmd' => (is => 'rw', isa=>'Str', default=>'git'); | |||||||||
| 14 | |||||||||||
| 15 | 4 | has 'bare' => (is => 'rw', default=>0, traits => [qw/Private/]); | |||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | private_method _isGit => sub { | ||||||||||
| 21 | 9 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.4
| |||||||||||
| 22 | |||||||||||
| 23 | 9 | ▶ | return 0 unless -d $self->git_dir(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | |||||||||||
| 25 | 9 | ▶ | if (-d $self->git_dir . "/.git") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | { | ||||||||||
| 27 | 8 | $self->bare(0); | |||||||||
| 28 | 8 | return 1; | |||||||||
| 29 | } | ||||||||||
| 30 | 1 | my $help=readpipe("cd " . $self->git_dir . "; " . $self->gitcmd() . ' rev-parse --git-dir 1>/dev/null 2> /dev/null;echo $?'); | |||||||||
| 31 | 1 | chomp($help); | |||||||||
| 32 | |||||||||||
| 33 | 1 | ▶ | if ($help == 0) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | { | ||||||||||
| 35 | 0 | $self->bare(1); | |||||||||
| 36 | 0 | return 1; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 1 | return 0; | |||||||||
| 40 | 4 | }; | |||||||||
| 41 | |||||||||||
| 42 | sub BUILD { | ||||||||||
| 43 | 9 | ▶ | my $self = shift; | ||||||||
|
Subroutine
BUILD: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||
| 44 | |||||||||||
| 45 | 9 | ▶ | die("directory does not exist (".$self->git_dir . " )") unless -d $self->git_dir(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 9 | ▶ | die("directory is not a git repository (" .$self->git_dir . " )") unless $self->_isGit(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | #update gitcmd attribute | ||||||||||
| 49 | 8 | $self->gitcmd($self->gitcmd . ' --git-dir='.$self->git_dir()); | |||||||||
| 50 | 8 | ▶ | if ($self->bare()==0) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | { | ||||||||||
| 52 | 8 | $self->gitcmd($self->gitcmd . "/.git"); | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | }; | ||||||||||
| 56 | |||||||||||
| 57 | |||||||||||
| 58 | sub getReference | ||||||||||
| 59 | { | ||||||||||
| 60 | 7 | ▶ | my $self = shift; | ||||||||
|
Subroutine
getReference: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 61 | 7 | my $ref = shift; | |||||||||
| 62 | |||||||||||
| 63 | 7 | return Git::LowLevel::Reference->new(repository=>$self, reference=>$ref); | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | |||||||||||
| 67 | |||||||||||
| 68 | 4 | 1; | |||||||||
| 69 | |||||||||||
| 70 | __END__ | ||||||||||
| 71 | |||||||||||
| 72 | =pod | ||||||||||
| 73 | |||||||||||
| 74 | =encoding UTF-8 | ||||||||||
| 75 | |||||||||||
| 76 | =head1 NAME | ||||||||||
| 77 | |||||||||||
| 78 | Git::LowLevel - LowLevel Blob/Tree/Commit operations on a GIT Repository | ||||||||||
| 79 | |||||||||||
| 80 | =head1 VERSION | ||||||||||
| 81 | |||||||||||
| 82 | version 0.2 | ||||||||||
| 83 | |||||||||||
| 84 | =head1 DESCRIPTION | ||||||||||
| 85 | |||||||||||
| 86 | Git::LowLevel is a Perl Module for using gits low level functions to create and read | ||||||||||
| 87 | blobs, trees, commits and references. | ||||||||||
| 88 | |||||||||||
| 89 | Git::LowLevel is not intended to be used for script based committing or something | ||||||||||
| 90 | like that. | ||||||||||
| 91 | |||||||||||
| 92 | It main indent is to create/read references and their trees while you have checked out | ||||||||||
| 93 | abother branch. | ||||||||||
| 94 | |||||||||||
| 95 | =head2 EXAMPLE1 | ||||||||||
| 96 | |||||||||||
| 97 | use Git::LowLevel; | ||||||||||
| 98 | |||||||||||
| 99 | my $repository = Git::LowLevel->new(git_dir => "/tmp/repo"); | ||||||||||
| 100 | my $ref = $repository->getReference("refs/heads/master"); | ||||||||||
| 101 | my $tree = $ref->getTree(); | ||||||||||
| 102 | |||||||||||
| 103 | die ("reference does not exist") unless $ref->exist(); | ||||||||||
| 104 | die ("no files in tree") unless !$tree->empty(); | ||||||||||
| 105 | |||||||||||
| 106 | my $blob = $tree->find("/doc/doxygen.conf"); | ||||||||||
| 107 | die("no blob found") unless defined($blob) && ref($blob) eq "Git::LowLevel::Blob"; | ||||||||||
| 108 | |||||||||||
| 109 | print $blob->content; | ||||||||||
| 110 | |||||||||||
| 111 | =head2 EXAMPLE2 | ||||||||||
| 112 | |||||||||||
| 113 | use Git::LowLevel; | ||||||||||
| 114 | |||||||||||
| 115 | my $repository = Git::LowLevel->new(git_dir => "/tmp/repo"); | ||||||||||
| 116 | my $ref = $repository->getReference("refs/heads/master"); | ||||||||||
| 117 | my $tree = $ref->getTree(); | ||||||||||
| 118 | |||||||||||
| 119 | my $newblob = $tree->newBlob(); | ||||||||||
| 120 | $newblob->path("hello"); | ||||||||||
| 121 | $newblob->_content("Hello World"); | ||||||||||
| 122 | $tree->add($newblob); | ||||||||||
| 123 | $ref->commit("added hello"); | ||||||||||
| 124 | |||||||||||
| 125 | =head1 ATTRIBUTES | ||||||||||
| 126 | |||||||||||
| 127 | =head2 git_dir | ||||||||||
| 128 | |||||||||||
| 129 | directory of the git repository | ||||||||||
| 130 | |||||||||||
| 131 | =head2 gitcmd | ||||||||||
| 132 | |||||||||||
| 133 | path to the git command, default is to search in your path | ||||||||||
| 134 | |||||||||||
| 135 | =head2 bare | ||||||||||
| 136 | |||||||||||
| 137 | B<private attribute> | ||||||||||
| 138 | |||||||||||
| 139 | holds the value if this repository is a bare one or not | ||||||||||
| 140 | |||||||||||
| 141 | =head1 METHODS | ||||||||||
| 142 | |||||||||||
| 143 | =head2 _isGit | ||||||||||
| 144 | |||||||||||
| 145 | B<private method> | ||||||||||
| 146 | |||||||||||
| 147 | checks if git_dir is a git repository | ||||||||||
| 148 | |||||||||||
| 149 | =head2 BUILD | ||||||||||
| 150 | |||||||||||
| 151 | B<private method> | ||||||||||
| 152 | |||||||||||
| 153 | called after new for internal setup | ||||||||||
| 154 | |||||||||||
| 155 | =head2 getReference | ||||||||||
| 156 | |||||||||||
| 157 | returns a reference object from the given reference path | ||||||||||
| 158 | |||||||||||
| 159 | @param none | ||||||||||
| 160 | |||||||||||
| 161 | @return L<Git::LowLevel::Reference> object | ||||||||||
| 162 | |||||||||||
| 163 | =head1 AUTHOR | ||||||||||
| 164 | |||||||||||
| 165 | Dominik Meyer <dmeyer@federationhq.de> | ||||||||||
| 166 | |||||||||||
| 167 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 168 | |||||||||||
| 169 | This software is Copyright (c) 2018 by Dominik Meyer. | ||||||||||
| 170 | |||||||||||
| 171 | This is free software, licensed under: | ||||||||||
| 172 | |||||||||||
| 173 | The GNU General Public License, Version 2, June 1991 | ||||||||||
| 174 | |||||||||||
| 175 | =cut | ||||||||||