Dist::Zilla::Plugin::Git::Check - check your git repository before releasing


Dist-Zilla-Plugin-Git documentation Contained in the Dist-Zilla-Plugin-Git distribution.

Index


Code Index:

NAME

Top

Dist::Zilla::Plugin::Git::Check - check your git repository before releasing

VERSION

Top

version 1.111590

SYNOPSIS

Top

In your dist.ini:

    [Git::Check]
    allow_dirty = dist.ini
    allow_dirty = README
    changelog = Changes      ; this is the default

DESCRIPTION

Top

This plugin checks that git is in a clean state before releasing. The following checks are performed before releasing:

* there should be no files in the index (staged copy)
* there should be no untracked files in the working copy
* the working copy should be clean. The files listed in allow_dirty can be modified locally, though.

If those conditions are not met, the plugin will die, and the release will thus be aborted. This lets you fix the problems before continuing.

The plugin accepts the following options:

* changelog - the name of your changelog file. defaults to Changes.
* allow_dirty - a file that is allowed to have local modifications. This option may appear multiple times. The default list is dist.ini and the changelog file given by changelog. You can use allow_dirty = to prohibit all local modifications.

AUTHOR

Top

Jerome Quelin

COPYRIGHT AND LICENSE

Top


Dist-Zilla-Plugin-Git documentation Contained in the Dist-Zilla-Plugin-Git distribution.

#
# This file is part of Dist-Zilla-Plugin-Git
#
# This software is copyright (c) 2009 by Jerome Quelin.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
use 5.008;
use strict;
use warnings;

package Dist::Zilla::Plugin::Git::Check;
BEGIN {
  $Dist::Zilla::Plugin::Git::Check::VERSION = '1.111590';
}
# ABSTRACT: check your git repository before releasing

use Git::Wrapper;
use Moose;

with 'Dist::Zilla::Role::BeforeRelease';
with 'Dist::Zilla::Role::Git::DirtyFiles';


# -- public methods

sub before_release {
    my $self = shift;
    my $git = Git::Wrapper->new('.');
    my @output;

    # fetch current branch
    my ($branch) =
        map { /^\*\s+(.+)/ ? $1 : () }
        $git->branch;

    # check if some changes are staged for commit
    @output = $git->diff( { cached=>1, 'name-status'=>1 } );
    if ( @output ) {
        my $errmsg =
            "branch $branch has some changes staged for commit:\n" .
            join "\n", map { "\t$_" } @output;
        $self->log_fatal($errmsg);
    }

    # everything but files listed in allow_dirty should be in a
    # clean state
    @output = $self->list_dirty_files($git);
    if ( @output ) {
        my $errmsg =
            "branch $branch has some uncommitted files:\n" .
            join "\n", map { "\t$_" } @output;
        $self->log_fatal($errmsg);
    }

    # no files should be untracked
    @output = $git->ls_files( { others=>1, 'exclude-standard'=>1 } );
    if ( @output ) {
        my $errmsg =
            "branch $branch has some untracked files:\n" .
            join "\n", map { "\t$_" } @output;
        $self->log_fatal($errmsg);
    }

    $self->log( "branch $branch is in a clean state" );
}


1;



__END__