File Coverage

blib/lib/Shipwright/Script/Defaultbranch.pm
Criterion Covered Total %
statement 15 33 45.4
branch 0 6 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 20 46 43.4


line stmt bran cond sub pod time code
1             package Shipwright::Script::Defaultbranch;
2 1     1   873 use strict;
  1         2  
  1         28  
3 1     1   4 use warnings;
  1         1  
  1         19  
4 1     1   4 use Shipwright::Util;
  1         1  
  1         103  
5              
6 1     1   6 use base qw/App::CLI::Command Shipwright::Base Shipwright::Script/;
  1         1  
  1         126  
7              
8 1     1   8 use Shipwright;
  1         1  
  1         6  
9              
10             sub run {
11 0     0 0   my $self = shift;
12 0           my $name = shift;
13 0           my $default = shift;
14              
15 0 0         confess_or_die "need name arg\n" unless $name;
16 0 0         confess_or_die "need default arg\n" unless $default;
17              
18 0           my $shipwright = Shipwright->new( repository => $self->repository, );
19              
20 0           my $branches = $shipwright->backend->branches;
21              
22 0 0         if ( grep { $default eq $_ } @{ $branches->{$name} } ) {
  0            
  0            
23              
24             # move $default to head
25 0           @{ $branches->{$name} } =
  0            
26 0           ( $default, grep { $_ ne $default } @{ $branches->{$name} } );
  0            
27 0           $shipwright->backend->branches($branches);
28 0           $self->log->fatal(
29             "successfully set default branch for $name, now it's $default");
30             }
31             else {
32 0           confess_or_die "$name doesn't have branches $default.
33 0           Available branches are " . join( ', ', @{ $branches->{$name} } ) . "\n";
34             }
35             }
36              
37             1;
38              
39             __END__