| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Shipwright::Script::Defaultbranch; | 
| 2 | 1 |  |  | 1 |  | 893 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 29 |  | 
| 3 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 27 |  | 
| 4 | 1 |  |  | 1 |  | 4 | use Shipwright::Util; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 71 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 1 |  |  | 1 |  | 5 | use base qw/App::CLI::Command Shipwright::Base Shipwright::Script/; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 131 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 1 |  |  | 1 |  | 5 | use Shipwright; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 8 |  | 
| 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__ |