| File: | blib/lib/Git/ReleaseRepo/Command/status.pm |
| Coverage: | 91.3% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package Git::ReleaseRepo::Command::status; | ||||||
| 2 | # ABSTRACT: Show the status of a release repository | ||||||
| 3 | |||||||
| 4 | 2 2 2 | 1567 2 32 | use strict; | ||||
| 5 | 2 2 2 | 5 1 30 | use warnings; | ||||
| 6 | 2 2 2 | 5 2 60 | use List::MoreUtils qw( uniq ); | ||||
| 7 | 2 2 2 | 4 2 5 | use Moose; | ||||
| 8 | 2 2 2 | 7087 1 7 | use Git::ReleaseRepo -command; | ||||
| 9 | |||||||
| 10 | with 'Git::ReleaseRepo::WithVersionPrefix'; | ||||||
| 11 | |||||||
| 12 | sub description { | ||||||
| 13 | 0 | 1 | return 'Show the status of a release repository'; | ||||
| 14 | } | ||||||
| 15 | |||||||
| 16 | around opt_spec => sub { | ||||||
| 17 | my ( $orig, $self ) = @_; | ||||||
| 18 | return ( | ||||||
| 19 | $self->$orig(), | ||||||
| 20 | [ 'bugfix' => 'Check the status of the current release branch' ], | ||||||
| 21 | ); | ||||||
| 22 | }; | ||||||
| 23 | |||||||
| 24 | augment execute => sub { | ||||||
| 25 | my ( $self, $opt, $args ) = @_; | ||||||
| 26 | # "master" looks at master since latest release branch | ||||||
| 27 | # "bugfix" looks at release branch since latest release | ||||||
| 28 | my ( $since_version, %outdated, %diff ); | ||||||
| 29 | my $git = $self->git; | ||||||
| 30 | # Deploy branch | ||||||
| 31 | if ( my $track = $self->config->{track} ) { | ||||||
| 32 | my $current = $git->current_release; | ||||||
| 33 | print "On release $current"; | ||||||
| 34 | my $latest = $git->latest_version( $track ); | ||||||
| 35 | if ( $git->current_release ne $latest ) { | ||||||
| 36 | print " (can update to $latest)"; | ||||||
| 37 | } | ||||||
| 38 | print "\n"; | ||||||
| 39 | } | ||||||
| 40 | # Bugfix release | ||||||
| 41 | elsif ( $opt->bugfix ) { | ||||||
| 42 | my $rel_branch = $git->latest_release_branch; | ||||||
| 43 | $git->checkout( $rel_branch ); | ||||||
| 44 | $since_version = $git->latest_version( $rel_branch ); | ||||||
| 45 | %outdated = map { $_ => 1 } $git->outdated( 'refs/heads/' . $rel_branch ); | ||||||
| 46 | %diff = map { $_ => 1 } $git->outdated( 'refs/tags/' . $since_version ); | ||||||
| 47 | } | ||||||
| 48 | # Regular release | ||||||
| 49 | else { | ||||||
| 50 | $git->checkout; | ||||||
| 51 | $since_version = $git->latest_release_branch; | ||||||
| 52 | %outdated = map { $_ => 1 } $git->outdated( 'refs/heads/master' ); | ||||||
| 53 | %diff = $since_version ? map { $_ => 1 } $git->outdated( 'refs/tags/' . $since_version . '.0' ) | ||||||
| 54 | # If we haven't had a release yet, everything we have is different | ||||||
| 55 | : map { $_ => 1 } keys %{$git->submodule}; | ||||||
| 56 | } | ||||||
| 57 | |||||||
| 58 | my $header = "Changes since " . ( $since_version || "development started" ); | ||||||
| 59 | print $header . "\n"; | ||||||
| 60 | print "-" x length( $header ) . "\n"; | ||||||
| 61 | my @changed = sort( uniq( keys %outdated, keys %diff ) ); | ||||||
| 62 | #; use Data::Dumper; print Dumper \@changed; | ||||||
| 63 | for my $changed ( @changed ) { | ||||||
| 64 | print "$changed"; | ||||||
| 65 | if ( !$since_version || $diff{ $changed } ) { | ||||||
| 66 | print " changed"; | ||||||
| 67 | } | ||||||
| 68 | if ( $outdated{$changed} ) { | ||||||
| 69 | print " (can add)"; | ||||||
| 70 | } | ||||||
| 71 | print "\n"; | ||||||
| 72 | } | ||||||
| 73 | }; | ||||||
| 74 | |||||||
| 75 | 1; | ||||||