File Coverage

blib/lib/App/Sqitch/Command/rebase.pm
Criterion Covered Total %
statement 59 59 100.0
branch 10 12 83.3
condition 12 12 100.0
subroutine 14 14 100.0
pod 1 1 100.0
total 96 98 97.9


line stmt bran cond sub pod time code
1             package App::Sqitch::Command::rebase;
2              
3 2     2   2027 use 5.010;
  2         8  
4 2     2   12 use strict;
  2         6  
  2         41  
5 2     2   10 use warnings;
  2         4  
  2         48  
6 2     2   10 use utf8;
  2         4  
  2         10  
7 2     2   56 use Moo;
  2         4  
  2         14  
8 2     2   784 use Types::Standard qw(Str Bool);
  2         9  
  2         24  
9 2     2   1894 use Locale::TextDomain qw(App-Sqitch);
  2         4  
  2         29  
10 2     2   409 use App::Sqitch::X qw(hurl);
  2         10  
  2         23  
11 2     2   616 use List::Util qw(first);
  2         5  
  2         134  
12 2     2   13 use Try::Tiny;
  2         5  
  2         124  
13 2     2   21 use namespace::autoclean;
  2         4  
  2         13  
14              
15             extends 'App::Sqitch::Command';
16             with 'App::Sqitch::Role::RevertDeployCommand';
17              
18             our $VERSION = 'v1.4.0'; # VERSION
19              
20             has onto_change => (
21             is => 'ro',
22             isa => Str,
23             );
24              
25             has upto_change => (
26             is => 'ro',
27             isa => Str,
28             );
29              
30             has modified => (
31             is => 'ro',
32             isa => Bool,
33             default => 0,
34             );
35              
36             sub options {
37             return qw(
38             onto-change|onto=s
39             upto-change|upto=s
40             modified|m
41             );
42             }
43              
44             sub configure {
45             my ( $class, $config, $opt ) = @_;
46             return { map { $_ => $opt->{$_} } grep { exists $opt->{$_} } qw(
47             onto_change
48             upto_change
49             modified
50             ) };
51             }
52              
53             sub execute {
54 14     14 1 33174 my $self = shift;
55 14         82 my ($targets, $changes) = $self->parse_args(
56             target => $self->target,
57             args => \@_,
58             );
59              
60             # Warn on multiple targets.
61 12         559 my $target = shift @{ $targets };
  12         25  
62             $self->warn(__x(
63             'Too many targets specified; connecting to {target}',
64             target => $target->name,
65 12 100       23 )) if @{ $targets };
  12         55  
66              
67             # Warn on too many changes.
68 12         467 my $engine = $target->engine;
69             my $onto = $self->modified
70             ? $engine->planned_deployed_common_ancestor_id
71 12 100 100     2065 : $self->onto_change // shift @{ $changes };
  5         17  
72 12   100     50 my $upto = $self->upto_change // shift @{ $changes };
  6         14  
73             $self->warn(__x(
74             'Too many changes specified; rebasing onto "{onto}" up to "{upto}"',
75             onto => $onto,
76             upto => $upto,
77 12 100       19 )) if @{ $changes };
  12         36  
78              
79             # Now get to work.
80 12         403 $engine->with_verify( $self->verify );
81 12         503 $engine->log_only( $self->log_only );
82 12         455 $engine->lock_timeout( $self->lock_timeout );
83              
84             # Revert.
85 12         573 $engine->set_variables( $self->_collect_revert_vars($target) );
86 12 50       261 die unless defined $self->no_prompt;
87 12 50       38 die unless defined $self->prompt_accept;
88             try {
89 12     12   641 $engine->revert( $onto, ! ($self->no_prompt), $self->prompt_accept );
90             } catch {
91             # Rethrow unknown errors or errors with exitval > 1.
92 4 100 100 4   1548 die $_ if ! eval { $_->isa('App::Sqitch::X') }
  4   100     71  
93             || $_->exitval > 1
94             || $_->ident eq 'revert:confirm';
95             # Emit notice of non-fatal errors (e.g., nothing to revert).
96 1         32 $self->info($_->message)
97 12         96 };
98              
99             # Deploy.
100 9         266 $engine->set_variables( $self->_collect_deploy_vars($target) );
101 9         231 $engine->deploy( $upto, $self->mode );
102 9         131 return $self;
103             }
104              
105             1;
106              
107             __END__
108              
109             =head1 Name
110              
111             App::Sqitch::Command::rebase - Revert and redeploy Sqitch changes
112              
113             =head1 Synopsis
114              
115             my $cmd = App::Sqitch::Command::rebase->new(%params);
116             $cmd->execute;
117              
118             =head1 Description
119              
120             If you want to know how to use the C<rebase> command, you probably want to be
121             reading C<sqitch-rebase>. But if you really want to know how the C<rebase> command
122             works, read on.
123              
124             =head1 Interface
125              
126             =head2 Class Methods
127              
128             =head3 C<options>
129              
130             my @opts = App::Sqitch::Command::rebase->options;
131              
132             Returns a list of L<Getopt::Long> option specifications for the command-line
133             options for the C<rebase> command.
134              
135             =head2 Attributes
136              
137             =head3 C<onto_change>
138              
139             Change onto which to rebase the target.
140              
141             =head3 C<upto_change>
142              
143             Change up to which to rebase the target.
144              
145             =head3 C<modified>
146              
147             Boolean to revert to the change prior to earliest change with a revised
148             deploy script.
149              
150             =head2 Instance Methods
151              
152             =head3 C<execute>
153              
154             $rebase->execute;
155              
156             Executes the rebase command.
157              
158             =head1 See Also
159              
160             =over
161              
162             =item L<sqitch-rebase>
163              
164             Documentation for the C<rebase> command to the Sqitch command-line client.
165              
166             =item L<sqitch>
167              
168             The Sqitch command-line client.
169              
170             =back
171              
172             =head1 Author
173              
174             David E. Wheeler <david@justatheory.com>
175              
176             =head1 License
177              
178             Copyright (c) 2012-2023 iovation Inc., David E. Wheeler
179              
180             Permission is hereby granted, free of charge, to any person obtaining a copy
181             of this software and associated documentation files (the "Software"), to deal
182             in the Software without restriction, including without limitation the rights
183             to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
184             copies of the Software, and to permit persons to whom the Software is
185             furnished to do so, subject to the following conditions:
186              
187             The above copyright notice and this permission notice shall be included in all
188             copies or substantial portions of the Software.
189              
190             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
191             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
192             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
193             AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
194             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
195             OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
196             SOFTWARE.
197              
198             =cut