Dist::Zilla::Plugin::Git::Init - initialize git repository on dzil new


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

Index


Code Index:

NAME

Top

Dist::Zilla::Plugin::Git::Init - initialize git repository on dzil new

VERSION

Top

version 1.111590

SYNOPSIS

Top

In your profile.ini:

    [Git::Init]
    commit_message = initial commit  ; this is the default
    remote = origin git@github.com:USERNAME/%{lc}N.git ; no default
    config = user.email USERID@cpan.org  ; there is no default

DESCRIPTION

Top

This plugin initializes a git repository when a new distribution is created with dzil new.

Plugin options

The plugin accepts the following options:

* commit_message - the commit message to use when checking in the newly-minted dist. Defaults to initial commit.
* config - a config setting to make in the repository. No config entries are made by default. A setting is specified as OPTION VALUE. This may be specified multiple times to add multiple entries.
* remote - a remote to add to the repository. No remotes are added by default. A remote is specified as NAME URL. This may be specified multiple times to add multiple remotes.

Formatting options

You can use the following codes in commit_message, config, or remote:

%n

A newline.

%N

The distribution name. You can also use %{lc}N or %{uc}N to get the name in lower case or upper case, respectively.

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.010;
use strict;
use warnings;

package Dist::Zilla::Plugin::Git::Init;
BEGIN {
  $Dist::Zilla::Plugin::Git::Init::VERSION = '1.111590';
}
# ABSTRACT: initialize git repository on dzil new

our %transform = (
  lc => sub { lc shift },
  uc => sub { uc shift },
  '' => sub { shift },
);

use Moose;
use Git::Wrapper;
use String::Formatter method_stringf => {
  -as => '_format_string',
  codes => {
    n => sub { "\n" },
    N => sub { $transform{$_[1] || ''}->( $_[0]->zilla->name ) },
  },
};

with 'Dist::Zilla::Role::AfterMint';

has commit_message => (
    is      => 'ro',
    isa     => 'Str',
    default => 'initial commit',
);

has remotes => (
  is   => 'ro',
  isa  => 'ArrayRef[Str]',
  default => sub { [] },
);

has config_entries => (
  is   => 'ro',
  isa  => 'ArrayRef[Str]',
  default => sub { [] },
);

sub mvp_multivalue_args { qw(config_entries remotes) }
sub mvp_aliases { return { config => 'config_entries', remote => 'remotes' } }

sub after_mint {
    my $self = shift;
    my ($opts) = @_;
    my $git = Git::Wrapper->new($opts->{mint_root});
    $self->log("Initializing a new git repository in " . $opts->{mint_root});
    $git->init;

    foreach my $configSpec (@{ $self->config_entries }) {
      my ($option, $value) = split ' ', _format_string($configSpec, $self), 2;
      $self->log_debug("Configuring $option $value");
      $git->config($option, $value);
    }

    $git->add($opts->{mint_root});
    $git->commit({message => _format_string($self->commit_message, $self)});
    foreach my $remoteSpec (@{ $self->remotes }) {
      my ($remote, $url) = split ' ', _format_string($remoteSpec, $self), 2;
      $self->log_debug("Adding remote $remote as $url");
      $git->remote(add => $remote, $url);
    }
}

1;



__END__