| 1 | # | ||||||||||
| 2 | # This file is part of Dist-Zilla-Plugin-Git | ||||||||||
| 3 | # | ||||||||||
| 4 | # This software is copyright (c) 2009 by Jerome Quelin. | ||||||||||
| 5 | # | ||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||
| 8 | # | ||||||||||
| 9 | 1 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | package Dist::Zilla::Plugin::Git::Check; | ||||||||||
| 14 | # ABSTRACT: Check your git repository before releasing | ||||||||||
| 15 | |||||||||||
| 16 | 1 | our $VERSION = '2.052'; | |||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | ▶ | use namespace::autoclean 0.09; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | ▶ | use Types::Standard qw(Bool Enum);; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 1 | with 'Dist::Zilla::Role::AfterBuild', | |||||||||
| 23 | 'Dist::Zilla::Role::BeforeRelease', | ||||||||||
| 24 | 'Dist::Zilla::Role::Git::Repo'; | ||||||||||
| 25 | 1 | with 'Dist::Zilla::Role::Git::DirtyFiles', | |||||||||
| 26 | 'Dist::Zilla::Role::GitConfig'; | ||||||||||
| 27 | |||||||||||
| 28 | 1 | has build_warnings => ( is=>'ro', isa => Bool, default => 0 ); | |||||||||
| 29 | |||||||||||
| 30 | 1 | has untracked_files => ( is=>'ro', isa => Enum([qw(die warn ignore)]), default => 'die' ); | |||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub _git_config_mapping { +{ | ||||||||
|
Subroutine
_git_config_mapping: not called CC=1 SCAR=6.9
| |||||||||||
| 33 | 0 | changelog => '%{changelog}s', | |||||||||
| 34 | } } | ||||||||||
| 35 | |||||||||||
| 36 | # -- public methods | ||||||||||
| 37 | |||||||||||
| 38 | around dump_config => sub | ||||||||||
| 39 | 5 | ▶ | { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||
| 40 | 5 | my $orig = shift; | |||||||||
| 41 | 5 | my $self = shift; | |||||||||
| 42 | |||||||||||
| 43 | 5 | my $config = $self->$orig; | |||||||||
| 44 | |||||||||||
| 45 | 5 | ▶ | $config->{+__PACKAGE__} = { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | # build_warnings does not affect the build outcome; do not need to track it | ||||||||||
| 47 | untracked_files => $self->untracked_files, | ||||||||||
| 48 | blessed($self) ne __PACKAGE__ ? ( version => $VERSION ) : (), | ||||||||||
| 49 | }; | ||||||||||
| 50 | |||||||||||
| 51 | 5 | return $config; | |||||||||
| 52 | 1 | }; | |||||||||
| 53 | |||||||||||
| 54 | 25 | ▶ | sub _perform_checks { | ||||||||
|
Subroutine
_perform_checks: called CC=11 SCAR=24.1
| |||||||||||
| 55 | 25 | my ($self, $log_method) = @_; | |||||||||
| 56 | |||||||||||
| 57 | 25 | my @issues; | |||||||||
| 58 | 25 | my $git = $self->git; | |||||||||
| 59 | 25 | my @output; | |||||||||
| 60 | |||||||||||
| 61 | # fetch current branch | ||||||||||
| 62 | 25 | ▶ | my ($branch) = | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | map /^\*\s+(.+)/ ? $1 : (), | ||||||||||
| 64 | $git->branch; | ||||||||||
| 65 | |||||||||||
| 66 | # check if some changes are staged for commit | ||||||||||
| 67 | 25 | @output = $git->diff( { cached=>1, 'name-status'=>1 } ); | |||||||||
| 68 | 25 | ▶ | if ( @output ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 5 | ▶ | push @issues, @output . " staged change" . (@output == 1 ? '' : 's'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | |||||||||||
| 71 | 5 | my $errmsg = | |||||||||
| 72 | "branch $branch has some changes staged for commit:\n" . | ||||||||||
| 73 | join "\n", map "\t$_", @output; | ||||||||||
| 74 | 5 | $self->$log_method($errmsg); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | # everything but files listed in allow_dirty should be in a | ||||||||||
| 78 | # clean state | ||||||||||
| 79 | 20 | @output = $self->list_dirty_files($git); | |||||||||
| 80 | 20 | ▶ | if ( @output ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 10 | ▶ | push @issues, @output . " uncommitted file" . (@output == 1 ? '' : 's'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | |||||||||||
| 83 | 10 | my $errmsg = | |||||||||
| 84 | "branch $branch has some uncommitted files:\n" . | ||||||||||
| 85 | join "\n", map "\t$_", @output; | ||||||||||
| 86 | 10 | $self->$log_method($errmsg); | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | # no files should be untracked | ||||||||||
| 90 | 10 | @output = $git->ls_files( { others=>1, 'exclude-standard'=>1 } ); | |||||||||
| 91 | 10 | ▶ | if ( @output ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 5 | ▶ | push @issues, @output . " untracked file" . (@output == 1 ? '' : 's'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | |||||||||||
| 94 | 5 | my $untracked = $self->untracked_files; | |||||||||
| 95 | 5 | ▶ | if ($untracked ne 'ignore') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | # If $log_method is log_fatal, switch to log unless | ||||||||||
| 97 | # untracked files are fatal. If $log_method is already log, | ||||||||||
| 98 | # this is a no-op. | ||||||||||
| 99 | 4 | ▶ | $log_method = 'log' unless $untracked eq 'die'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | |||||||||||
| 101 | 4 | my $errmsg = | |||||||||
| 102 | "branch $branch has some untracked files:\n" . | ||||||||||
| 103 | join "\n", map "\t$_", @output; | ||||||||||
| 104 | 4 | $self->$log_method($errmsg); | |||||||||
| 105 | } | ||||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 7 | ▶ | if (@issues) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | 2 | $self->log( "branch $branch has " . join(', ', @issues)); | |||||||||
| 110 | } else { | ||||||||||
| 111 | 5 | $self->log( "branch $branch is in a clean state" ); | |||||||||
| 112 | } | ||||||||||
| 113 | } # end _perform_checks | ||||||||||
| 114 | |||||||||||
| 115 | 5 | ▶ | sub after_build { | ||||||||
|
Subroutine
after_build: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||
| 116 | 5 | my $self = shift; | |||||||||
| 117 | |||||||||||
| 118 | 5 | ▶ | $self->_perform_checks('log') if $self->build_warnings; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | 25 | ▶ | sub before_release { | ||||||||
|
Subroutine
before_release: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 122 | 25 | my $self = shift; | |||||||||
| 123 | |||||||||||
| 124 | 25 | $self->_perform_checks('log_fatal'); | |||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 128 | 1 | 1; | |||||||||
| 129 | |||||||||||
| 130 | __END__ | ||||||||||