App-Sqitch

 view release on metacpan or  search on metacpan

lib/App/Sqitch/Command/rebase.pm  view on Meta::CPAN

has onto_change => (
    is  => 'ro',
    isa => Str,
);

has upto_change => (
    is  => 'ro',
    isa => Str,
);

has modified => (
    is      => 'ro',
    isa     => Bool,
    default => 0,
);

sub options {
    return qw(
        onto-change|onto=s
        upto-change|upto=s
        modified|m
    );
}

sub configure {
    my ( $class, $config, $opt ) = @_;
    return { map { $_ => $opt->{$_} } grep { exists $opt->{$_} } qw(
        onto_change
        upto_change
        modified
    ) };
}

sub execute {
    my $self = shift;
    my ($targets, $changes) = $self->parse_args(
        target => $self->target,
        args   => \@_,
    );

    # Warn on multiple targets.
    my $target = shift @{ $targets };
    $self->warn(__x(
        'Too many targets specified; connecting to {target}',
        target => $target->name,
    )) if @{ $targets };

    # Warn on too many changes.
    my $engine = $target->engine;
    my $onto = $self->modified
        ? $engine->planned_deployed_common_ancestor_id
        : $self->onto_change // shift @{ $changes };
    my $upto = $self->upto_change // shift @{ $changes };
    $self->warn(__x(
        'Too many changes specified; rebasing onto "{onto}" up to "{upto}"',
        onto => $onto,
        upto => $upto,
    )) if @{ $changes };

    # Now get to work.
    $engine->with_verify( $self->verify );
    $engine->log_only( $self->log_only );
    $engine->lock_timeout( $self->lock_timeout );

    # Revert.
    $engine->set_variables( $self->_collect_revert_vars($target) );
    die unless defined $self->no_prompt;
    die unless defined $self->prompt_accept;
    try {
        $engine->revert( $onto, ! ($self->no_prompt), $self->prompt_accept );
    } catch {
        # Rethrow unknown errors or errors with exitval > 1.
        die $_ if ! eval { $_->isa('App::Sqitch::X') }
            || $_->exitval > 1
            || $_->ident eq 'revert:confirm';
        # Emit notice of non-fatal errors (e.g., nothing to revert).
        $self->info($_->message)
    };

    # Deploy.
    $engine->set_variables( $self->_collect_deploy_vars($target) );
    $engine->deploy( $upto, $self->mode );
    return $self;
}

1;

__END__

=head1 Name

App::Sqitch::Command::rebase - Revert and redeploy Sqitch changes

=head1 Synopsis

  my $cmd = App::Sqitch::Command::rebase->new(%params);
  $cmd->execute;

=head1 Description

If you want to know how to use the C<rebase> command, you probably want to be
reading C<sqitch-rebase>. But if you really want to know how the C<rebase> command
works, read on.

=head1 Interface

=head2 Class Methods

=head3 C<options>

  my @opts = App::Sqitch::Command::rebase->options;

Returns a list of L<Getopt::Long> option specifications for the command-line
options for the C<rebase> command.

=head2 Attributes

=head3 C<onto_change>

Change onto which to rebase the target.



( run in 0.458 second using v1.01-cache-2.11-cpan-5a3173703d6 )