fix(cli): honor --dry-run when updating and removing core files
This commit is contained in:
@@ -284,6 +284,13 @@ final class Installer
|
|||||||
}
|
}
|
||||||
|
|
||||||
$absolute = $this->root . '/' . $relative;
|
$absolute = $this->root . '/' . $relative;
|
||||||
|
|
||||||
|
if ($options['dryRun'] ?? false) {
|
||||||
|
$actions[$relative] = 'planned';
|
||||||
|
$installed[$relative] = 'sha256:' . hash('sha256', $provider->read($relative));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$action = $this->sync->write($absolute, $provider->read($relative), $expected[$relative] ?? null, $options);
|
$action = $this->sync->write($absolute, $provider->read($relative), $expected[$relative] ?? null, $options);
|
||||||
$actions[$relative] = $action;
|
$actions[$relative] = $action;
|
||||||
|
|
||||||
@@ -300,6 +307,10 @@ final class Installer
|
|||||||
if (isset($installed[$relative]) || isset($protected[$relative]) || in_array($relative, $files, true)) {
|
if (isset($installed[$relative]) || isset($protected[$relative]) || in_array($relative, $files, true)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ($options['dryRun'] ?? false) {
|
||||||
|
$actions[$relative] = 'remove-planned';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$action = $this->sync->remove($this->root . '/' . $relative, $hash, $options);
|
$action = $this->sync->remove($this->root . '/' . $relative, $hash, $options);
|
||||||
if ($action === FileSync::ABORTED) {
|
if ($action === FileSync::ABORTED) {
|
||||||
$aborted[] = $relative;
|
$aborted[] = $relative;
|
||||||
|
|||||||
@@ -194,6 +194,48 @@ Harness::it('--dry-run no escribe archivos ni lock', function () {
|
|||||||
rrmdir($tool);
|
rrmdir($tool);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Harness::it('update core --dry-run no escribe archivos', function () {
|
||||||
|
$proj = tmpdir('proj');
|
||||||
|
$tool = g7_toolbox();
|
||||||
|
$core = g7_core('1.0.0', 'router-v1');
|
||||||
|
$core2 = g7_core('2.0.0', 'router-v2');
|
||||||
|
|
||||||
|
(new InstallCommand(new Console()))->run([$proj, '--toolbox=' . $tool, '--core-dir=' . $core, '--yes']);
|
||||||
|
|
||||||
|
$routerBefore = (string) file_get_contents($proj . '/src/Libs/Router.php');
|
||||||
|
(new UpdateCommand(new Console()))->run(['core', '--root=' . $proj, '--toolbox=' . $tool, '--core-dir=' . $core2, '--yes', '--dry-run']);
|
||||||
|
|
||||||
|
ok(str_contains($routerBefore, 'router-v1'), 'estado inicial correcto');
|
||||||
|
ok(str_contains((string) file_get_contents($proj . '/src/Libs/Router.php'), 'router-v1'), 'dry-run no escribe el fichero');
|
||||||
|
eq('1.0.0', Lock::load($proj)->core()['version'], 'dry-run no actualiza la version en el lock');
|
||||||
|
|
||||||
|
rrmdir($proj);
|
||||||
|
rrmdir($tool);
|
||||||
|
rrmdir($core);
|
||||||
|
rrmdir($core2);
|
||||||
|
});
|
||||||
|
|
||||||
|
Harness::it('update core --dry-run aborta por drift sin escribir', function () {
|
||||||
|
$proj = tmpdir('proj');
|
||||||
|
$tool = g7_toolbox();
|
||||||
|
$core = g7_core('1.0.0', 'router-v1');
|
||||||
|
$core2 = g7_core('2.0.0', 'router-v2');
|
||||||
|
|
||||||
|
(new InstallCommand(new Console()))->run([$proj, '--toolbox=' . $tool, '--core-dir=' . $core, '--yes']);
|
||||||
|
write_file($proj . '/config.php', "<?php\n// customizado\n");
|
||||||
|
|
||||||
|
(new UpdateCommand(new Console()))->run(['core', '--root=' . $proj, '--toolbox=' . $tool, '--core-dir=' . $core2, '--yes', '--dry-run']);
|
||||||
|
|
||||||
|
ok(!is_file($proj . '/config.php.bak'), 'dry-run no crea backups');
|
||||||
|
ok(str_contains((string) file_get_contents($proj . '/config.php'), 'customizado'), 'dry-run conserva la edicion local');
|
||||||
|
ok(str_contains((string) file_get_contents($proj . '/src/Libs/Router.php'), 'router-v1'), 'dry-run no toca ficheros sin drift');
|
||||||
|
|
||||||
|
rrmdir($proj);
|
||||||
|
rrmdir($tool);
|
||||||
|
rrmdir($core);
|
||||||
|
rrmdir($core2);
|
||||||
|
});
|
||||||
|
|
||||||
Harness::it('core sin tags: versión desconocida y commit pineado', function () {
|
Harness::it('core sin tags: versión desconocida y commit pineado', function () {
|
||||||
$proj = tmpdir('proj');
|
$proj = tmpdir('proj');
|
||||||
$tool = g7_toolbox();
|
$tool = g7_toolbox();
|
||||||
|
|||||||
Reference in New Issue
Block a user