Skip to content

Commit

Permalink
Print changes to be deployed or reverted.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Turner committed Jan 19, 2023
1 parent ef7767d commit 06daffc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
31 changes: 30 additions & 1 deletion lib/App/Sqitch/Engine.pm
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ sub deploy {
)
);

$sqitch->debug(__ "Will deploy the following changes:");
foreach my $will_deploy_position ($plan->position .. $to_index) {
$sqitch->debug($plan->change_at($will_deploy_position)->format_name_with_tags);
}

# Check that all dependencies will be satisfied.
$self->check_deploy_dependencies($plan, $to_index);

Expand All @@ -269,6 +274,15 @@ sub deploy {
$self->$meth( $plan, $to_index );
}

# Do a thing similar to Sqitch::Plan::Change::format_name_with_tags,
# but for an output from $self->deployed_changes or
# $self->deployed_changes_since.
sub _format_deployed_change_name_with_tags($) {
my ( $self, $change ) = @_;

return join ' ', $change->{name}, map { '@' . $_ } @{$change->{tags}};
}

sub revert {
my ( $self, $to ) = @_;

Expand Down Expand Up @@ -299,6 +313,8 @@ sub revert {
);
};

# NB this is an array of unblessed references, not of
# Sqitch::Plan::Change references.
@changes = $self->deployed_changes_since(
$self->_load_changes($change)
) or do {
Expand All @@ -308,14 +324,20 @@ sub revert {
));
return $self;
};
my @change_descriptions =
map { $self->_format_deployed_change_name_with_tags($_) } @changes;

if ($self->no_prompt) {
$sqitch->info(__x(
'Reverting changes to {change} from {destination}',
change => $change->format_name_with_tags,
destination => $self->destination,
));
$sqitch->info(__ 'Will revert the following changes:');
map { $sqitch->info($_) } @change_descriptions;
} else {
$sqitch->info(__ 'Would revert the following changes:');
map { $sqitch->info($_) } @change_descriptions;
hurl {
ident => 'revert:confirm',
message => __ 'Nothing reverted',
Expand All @@ -326,19 +348,26 @@ sub revert {
destination => $self->destination,
), $self->prompt_accept );
}

} else {
# NB this is an array of unblessed references, not of
# Sqitch::Plan::Change references.
@changes = $self->deployed_changes or do {
$sqitch->info(__ 'Nothing to revert (nothing deployed)');
return $self;
};
my @change_descriptions =
map { $self->_format_deployed_change_name_with_tags($_) } @changes;

if ($self->no_prompt) {
$sqitch->info(__x(
'Reverting all changes from {destination}',
destination => $self->destination,
));
$sqitch->info(__ 'Will revert the following changes:');
map { $sqitch->info($_) } @change_descriptions;
} else {
$sqitch->info(__ 'Would revert the following changes:');
map { $sqitch->info($_) } @change_descriptions;
hurl {
ident => 'revert',
message => __ 'Nothing reverted',
Expand Down
32 changes: 29 additions & 3 deletions t/engine.t
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1159,8 +1159,6 @@ is_deeply $engine->seen, [
], 'Should have deployed to change 2';
is_deeply +MockOutput->get_info, [
[__x 'Deploying changes to {destination}', destination => $engine->destination ],
# [__ 'ok'],
# [__ 'ok'],
], 'Should have emitted deploy announcement and successes';

# Make sure we can deploy everything by change.
Expand Down Expand Up @@ -2060,6 +2058,11 @@ is_deeply +MockOutput->get_info_literal, [
[' - roles ..', '........', ' '],
], 'It should have said it was reverting all changes and listed them';
is_deeply +MockOutput->get_info, [
[__ 'Would revert the following changes:'],
['roles'],
['users @alpha'],
['widgets @beta'],
['lolz'],
[__ 'ok'],
[__ 'ok'],
[__ 'ok'],
Expand Down Expand Up @@ -2092,6 +2095,11 @@ is_deeply +MockOutput->get_info_literal, [
[' - roles ..', '........', ' '],
], 'It should have said it was reverting all changes and listed them';
is_deeply +MockOutput->get_info, [
[__ 'Would revert the following changes:'],
['roles'],
['users @alpha'],
['widgets @beta'],
['lolz'],
[__ 'ok'],
[__ 'ok'],
[__ 'ok'],
Expand All @@ -2115,6 +2123,11 @@ is_deeply +MockOutput->get_ask_yes_no, [
), 1],
], 'Should have prompt to revert all changes';
is_deeply +MockOutput->get_info, [
[__ 'Would revert the following changes:'],
['roles'],
['users @alpha'],
['widgets @beta'],
['lolz'],
], 'It should have emitted nothing else';

# Revert all changes with no prompt.
Expand Down Expand Up @@ -2148,6 +2161,11 @@ is_deeply +MockOutput->get_info, [
'Reverting all changes from {destination}',
destination => $engine->destination,
)],
[__ 'Will revert the following changes:'],
['roles'],
['users @alpha'],
['widgets @beta'],
['lolz'],
[__ 'ok'],
[__ 'ok'],
[__ 'ok'],
Expand Down Expand Up @@ -2185,6 +2203,9 @@ is_deeply +MockOutput->get_info_literal, [
[' - widgets @beta ..', '', ' '],
], 'Output should show what it reverts to';
is_deeply +MockOutput->get_info, [
[__ 'Would revert the following changes:'],
['widgets @beta'],
['lolz'],
[__ 'ok'],
[__ 'ok'],
], 'And the revert successes should be emitted';
Expand All @@ -2211,7 +2232,10 @@ is_deeply +MockOutput->get_ask_yes_no, [
), 1],
], 'Should have prompt to revert to @alpha';
is_deeply +MockOutput->get_info, [
], 'It should have emitted nothing else';
[__ 'Would revert the following changes:'],
['widgets @beta'],
['lolz'],
], 'Should emit a detailed prompt.';

# Try to revert just the last change with no prompt
MockOutput->ask_yes_no_returns(1);
Expand Down Expand Up @@ -2241,6 +2265,8 @@ is_deeply +MockOutput->get_info, [
destination => $engine->destination,
change => $dbchanges[-1]->format_name_with_tags,
)],
[__ 'Will revert the following changes:'],
['lolz'],
[__ 'ok'],
], 'And the header and "ok" should be emitted';

Expand Down

0 comments on commit 06daffc

Please sign in to comment.