#!perl

use strict;
use warnings;

use autodie;

use Git;


use Pod::Usage;
use Getopt::Long;

sub say (@) { print @_, "\n" }

my %opt;
GetOptions( \%opt, 
    'help' => sub { pod2usage(1) },
    'man'  => sub { pod2usage( verbose => 2 ) },
) or pod2usage( "for a list of all valid options, do 'git cpan-update --help'" );


my $repo = Git->repository;

my $last_import = $repo->command_oneline('rev-parse', '--verify', 'cpan/master');

$repo->command_noisy('cpan-import', @ARGV);

my $updated = $repo->command_oneline('rev-parse', '-q', '--verify', 'cpan/master');

$repo->command_noisy('rebase', 'cpan/master') 
    unless $last_import eq $updated;

__END__

=pod

=head1 NAME

git-cpan-update - Import the latest version of a module and rebase the current
branch

=head1 SYNOPSIS

    % git cpan-update

=head1 DESCRIPTION

This command runs C<git cpan-import>, and then if C<cpan/master> was updated
runs C<git rebase cpan/master>, bringing your patches up to date with the
upstream.

=head1 VERSION

This document describes git-cpan-update version 0.3.1

=head1 BUGS AND LIMITATIONS

Please report any bugs or feature requests to
C<bug-git-cpan-patch@rt.cpan.org>, or through the web 
interface at L<http://rt.cpan.org>.
  
=head1 AUTHORS

Yuval Kogman C<< <nothingmuch@woobling.org> >>

Yanick Champoux C<< <yanick@cpan.org> >>

=head1 LICENCE

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.

=head1 SEE ALSO

L<Git::CPAN::Patch>, L<git-cpan-import>

=cut
