| 1 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | package Dist::Zilla::Plugin::Subversion::Check; | ||
| 4 | # ABSTRACT: check SVN working copy before release | ||
| 5 | |||
| 6 | 1 | ▶ | use Dist::Zilla 4 (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 0 | ▶ | use SVN::Client; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | |||
| 11 | with 'Dist::Zilla::Role::BeforeRelease'; | ||
| 12 | |||
| 13 | has 'svn' => ( | ||
| 14 | is => 'ro', | ||
| 15 | isa => 'SVN::Client', | ||
| 16 | lazy => 1, | ||
| 17 | default => sub { | ||
| 18 | my $self = shift; | ||
| 19 | SVN::Client->new(); | ||
| 20 | }, | ||
| 21 | ); | ||
| 22 | |||
| 23 | has check_up2date => ( is => 'rw', isa => 'Bool', default => 1 ); | ||
| 24 | has check_uncommited => ( is => 'rw', isa => 'Bool', default => 1 ); | ||
| 25 | has check_missing => ( is => 'rw', isa => 'Bool', default => 1 ); | ||
| 26 | has check_untracked => ( is => 'rw', isa => 'Bool', default => 1 ); | ||
| 27 | |||
| 28 | has '_wc_revision' => ( is => 'ro', isa => 'Int', lazy => 1, | ||
| 29 | default => sub { | ||
| 30 | my $self = shift; | ||
| 31 | my $rev; | ||
| 32 | $self->svn->info("", undef, 'WORKING', sub { $rev = $_[1]->rev }, 0); | ||
| 33 | return($rev); | ||
| 34 | } | ||
| 35 | ); | ||
| 36 | |||
| 37 | has '_repo_head_revision' => ( is => 'ro', isa => 'Int', lazy => 1, | ||
| 38 | default => sub { | ||
| 39 | my $self = shift; | ||
| 40 | my $rev; | ||
| 41 | $self->svn->info("", undef, 'HEAD', sub { $rev = $_[1]->rev }, 0); | ||
| 42 | return($rev); | ||
| 43 | } | ||
| 44 | ); | ||
| 45 | |||
| 46 | has '_svn_status' => ( is => 'ro', isa => 'HashRef[ArrayRef[Str]]', lazy_build => 1 ); | ||
| 47 | |||
| 48 | sub _build__svn_status { | ||
| 49 | my $self = shift; | ||
| 50 | my $ret = { 'untracked' => [], 'added' => [], 'missing' => [], 'deleted' => [], | ||
| 51 | 'modified' => [], 'merged' => [], 'conflicted' => [] }; | ||
| 52 | $self->svn->status('', 'HEAD', sub { | ||
| 53 | if($_[1]->text_status == 2) { push(@{$ret->{'untracked'}}, $_[0]); } | ||
| 54 | if($_[1]->text_status == 4) { push(@{$ret->{'added'}}, $_[0]); } | ||
| 55 | if($_[1]->text_status == 5) { push(@{$ret->{'missing'}}, $_[0]); } | ||
| 56 | if($_[1]->text_status == 6) { push(@{$ret->{'deleted'}}, $_[0]); } | ||
| 57 | if($_[1]->text_status == 8) { push(@{$ret->{'modified'}}, $_[0]); } | ||
| 58 | if($_[1]->text_status == 9) { push(@{$ret->{'merged'}}, $_[0]); } | ||
| 59 | if($_[1]->text_status == 10) { push(@{$ret->{'conflicted'}}, $_[0]); } | ||
| 60 | }, 1, 1, 1, 0); | ||
| 61 | |||
| 62 | return($ret); | ||
| 63 | } | ||
| 64 | |||
| 65 | foreach my $i ('untracked', 'added', 'missing', 'deleted', 'modified', 'merged', 'conflicted') { | ||
| 66 | has '_'.$i.'_files' => ( | ||
| 67 | is => 'ro', isa => 'ArrayRef[Str]', lazy => 1, | ||
| 68 | traits => [ 'Array' ], | ||
| 69 | default => sub { | ||
| 70 | my $self = shift; | ||
| 71 | return($self->_svn_status->{$i}); | ||
| 72 | }, | ||
| 73 | handles => { | ||
| 74 | '_'.$i.'_files_count' => 'count', | ||
| 75 | }, | ||
| 76 | ); | ||
| 77 | } | ||
| 78 | |||
| 79 | sub before_release { | ||
| 80 | my $self = shift; | ||
| 81 | |||
| 82 | $self->log('WC revision: '.$self->_wc_revision); | ||
| 83 | $self->log('Repository HEAD revision: '.$self->_repo_head_revision); | ||
| 84 | if( $self->check_up2date && $self->_wc_revision < $self->_repo_head_revision ) { | ||
| 85 | $self->log_fatal("Working copy not up-to-date!"); | ||
| 86 | } | ||
| 87 | |||
| 88 | foreach my $type ( keys %{$self->_svn_status} ) { | ||
| 89 | if( scalar @{$self->_svn_status->{$type}} ) { | ||
| 90 | $self->log($type." files: ".join(', ', @{$self->_svn_status->{$type}}) ); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | if( $self->check_missing && $self->_missing_files_count ) { | ||
| 95 | $self->log_fatal('Some files in working copy are missing!'); | ||
| 96 | } | ||
| 97 | |||
| 98 | |||
| 99 | if( $self->check_untracked && $self->_untracked_files_count ) { | ||
| 100 | $self->log_fatal('Some files in working copy are not under version control!'); | ||
| 101 | } | ||
| 102 | |||
| 103 | if( $self->check_uncommited && ( | ||
| 104 | $self->_added_files_count || | ||
| 105 | $self->_deleted_files_count || | ||
| 106 | $self->_modified_files_count || | ||
| 107 | $self->_merged_files_count || | ||
| 108 | $self->_conflicted_files_count ) | ||
| 109 | ) { | ||
| 110 | $self->log_fatal('Working copy has uncommited changes!'); | ||
| 111 | } | ||
| 112 | |||
| 113 | return; | ||
| 114 | } | ||
| 115 | |||
| 116 | 1; | ||
| 117 | |||
| 118 | __END__ | ||