Git::Wrapper::Plus::Branches - Extract branches from Git
version 0.004011
This module aims to do what you want when you think you want to parse the output of
git branch
Except it works the right way, and uses
git for-each-ref
So
use Git::Wrapper::Plus::Branches; my $branches = Git::Wrapper::Plus::Branches->new( git => $git_wrapper ); # Show details of every local branch for my $branch ( $branches->branches ) { printf "%s %s", $branch->name, $branch->sha1; } # Show details of all branches starting with master for my $branch ( $branches->get_branch("master*") ) { printf "%s %s", $branch->name, $branch->sha1; } # Show details of current branch for my $branch ( $branches->current_branch ) { printf "%s %s", $branch->name, $branch->sha1; }
branches
Returns a ::Branch object for each local branch.
::Branch
for my $branch ( $b->branches ) { $branch # isa Git::Wrapper::Plus::Branch }
Get branch info about master
my ($branch,) = $branches->get_branch('master');
Note: This can easily return multiple values.
For instance, branches is implemented as
my ( @branches ) = $branches->get_branch('**');
Mostly, because the underlying mechanism is implemented in terms of fnmatch(3)
fnmatch(3)
If the branch does not exist, or no branches match the expression, get_branch will return an empty list.
get_branch
So in the top example, $branch is undef if master does not exist.
$branch
undef
master
current_branch
Returns a ::Branch object if currently on a branch, undef otherwise.
branch
my $b = $branches->current_branch; if ( defined $b ) { printf "Currently on: %s", $b->name; } else { print "Detached HEAD"; }
git
REQUIRED: A Git::Wrapper Compatible object.
Git::Wrapper
refs
OPTIONAL: A Git::Wrapper::Plus::Refs Compatible object ( mostly for plumbing )
Git::Wrapper::Plus::Refs
Kent Fredric <kentnl@cpan.org>
This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.
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::Wrapper::Plus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Git::Wrapper::Plus
CPAN shell
perl -MCPAN -e shell install Git::Wrapper::Plus
For more information on module installation, please visit the detailed CPAN module installation guide.