Git::More - An extension of App::gh::Git with some goodies for hook developers.
version 0.017
use Git::More; my $git = Git::More->repository(); my $config = $git->get_config('section'); my $branch = $git->get_current_branch(); my $commits = $git->get_refs_commits(); my $message = $git->get_commit_msg('HEAD');
This is an extension of the App::gh::Git class. It's meant to implement a few extra methods commonly needed by Git hook developers.
App::gh::Git
In particular, it's used by the standard hooks implemented by the Git::Hooks framework.
Git::Hooks
This method groks the configuration options for the repository. It returns every option found by invoking git config --list.
git config --list
The options are returned as a hash-ref pointing to a two-level hash. For example, if the config options are these:
section1.a=1 section1.b=2 section1.b=3 section2.x.a=A section2.x.b=B section2.x.b=C
Then, it'll return this hash:
{ 'section1' => { 'a' => [1], 'b' => [2, 3], }, 'section2' => { 'x.a' => ['A'], 'x.b' => ['B', 'C'], }, }
The first level keys are the part of the option names before the first dot. The second level keys are everything after the first dot in the option names. You won't get more levels than two. In the example above, you can see that the option "section2.x.a" is split in two: "section2" in the first level and "x.a" in the second.
The values are always array-refs, even it there is only one value to a specific option. For some options, it makes sense to have a list of values attached to them. But even if you expect a single value to an option you may have it defined in the global scope and redefined in the local scope. In this case, it will appear as a two-element array, the last one being the local value.
So, if you want to treat an option as single-valued, you should fetch it like this:
$h->{section1}{a}[-1] $h->{section2}{'x.a'}[-1]
This method returns the repository's current branch name, as indicated by the git branch command. Note that its a ref shortname, i.e., it's usually subintended to reside under the 'refs/heads/' ref scope.
git branch
This method returns a list of hashes representing every commit reachable from NEWCOMMIT but not from OLDCOMMIT. It obtains this information by invoking git rev-list OLDCOMIT..NEWCOMMIT.
git rev-list OLDCOMIT..NEWCOMMIT
Each commit is represented by a hash with the following structure (the codes are explained in the git help rev-list document):
git help rev-list
{ commit => %H: commit hash tree => %T: tree hash parent => %P: parent hashes (space separated) author_name => %aN: author name author_email => %aE: author email author_date => %ai: author date in ISO8601 format commmitter_name => %cN: committer name committer_email => %cE: committer email committer_date => %ci: committer date in ISO8601 format body => %B: raw body (aka commit message) }
This method returns the commit message (aka body) of the commit identified by COMMIT_ID. The result is a string.
This method returns a reference to a hash mapping every affected files between OLDCOMMIT and NEWCOMMIT to their affecting status. The list is grokked with the command git diff --cached --name-status.
git diff --cached --name-status
The optional FILTER parameter must be a valid value for the --diff-filter option of the git diff command. You can use it to AM, for instance, to request only files that have been Added or Modified.
--diff-filter
git diff
AM
Gustavo L. de M. Chaves <gnustavo@cpan.org>
This software is copyright (c) 2012 by CPqD <www.cpqd.com.br>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Git::Hooks, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Git::Hooks
CPAN shell
perl -MCPAN -e shell install Git::Hooks
For more information on module installation, please visit the detailed CPAN module installation guide.