Git-Release
view release on metacpan or search on metacpan
lib/Git/Release.pm view on Meta::CPAN
sub list_local_branches {
return $_[0]->branch->local_branches;
}
sub get_current_branch_name {
return $_[0]->branch->current_name;
}
sub get_current_branch {
return $_[0]->branch->current;
}
# return branches with ready prefix.
sub get_ready_branches {
my $self = shift;
my $prefix = $self->config->ready_prefix;
my @branches = $self->list_all_branches;
my @ready_branches = grep /$prefix/, @branches;
return map { $self->_new_branch( ref => $_ ) } @ready_branches;
}
sub get_release_branches {
my $self = shift;
my $prefix = $self->config->release_prefix;
my @branches = $self->list_all_branches;
my @release_branches = sort grep /$prefix/, @branches;
return map { $self->_new_branch( ref => $_ ) } @release_branches; # release branch not found.
}
sub install_hooks {
my $self = shift;
my $repo_path = $self->repo->repo_path;
my $checkout_hook = File::Spec->join( $repo_path , 'hooks' , 'post-checkout' );
print "$checkout_hook\n";
open my $fh , ">" , $checkout_hook;
print $fh <<"END";
#!/usr/bin/env perl
use Git::Release;
my \$m = Git::Release->new; # release manager
\$m->branch->current->print_doc;
END
close $fh;
chmod 0755, $checkout_hook;
}
sub tracking_list {
my ($self) = @_;
my @args = qw(for-each-ref);
push @args, '--format';
push @args ,'%(refname:short):%(upstream)';
push @args, 'refs/heads';
my @lines = $self->repo->command(@args);
my %tracking = map { split ':', $_ , 2 } @lines;
return %tracking;
}
sub update_remote_refs {
my $self = shift;
$self->repo->command_oneline(qw(remote update --prune));
}
sub _new_branch {
my ( $self, %args ) = @_;
my $branch = Git::Release::Branch->new(
%args, manager => $self );
return $branch;
}
sub checkout_release_branch {
my $self = shift;
my @rbs = $self->get_release_branches;
my ($rb) = grep { $_->is_local } @rbs;
unless ($rb) {
($rb) = grep { $_->is_remote } @rbs;
}
unless ($rb) {
die 'Release branch not found.';
}
$rb->checkout;
return $rb;
}
=head2 find_branch
Find a specific branch from the branch list (remote and local).
=cut
sub find_branch {
my ( $self, $name ) = @_;
my @branches = $self->list_all_branches;
for my $ref ( @branches ) {
my $branch = $self->_new_branch( ref => $ref );
return $branch if $branch->name eq $name;
}
}
sub find_develop_branch {
my $self = shift;
my $dev_branch_name = $self->config->develop_branch;
return $self->find_branch( $dev_branch_name );
}
# checkout or create develop branch
sub checkout_develop_branch {
my $self = shift;
my $name = $self->config->develop_branch;
my $branch = $self->branch->find_branches( $name );
# if branch found, we should check it out
$branch = $self->_new_branch( ref => $name )->create( from => 'master' ) unless $branch;
$branch->checkout;
return $branch;
}
( run in 0.581 second using v1.01-cache-2.11-cpan-59e3e3084b8 )