mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-06 10:02:49 +08:00
feat(update): 新增 --keep-repo 参数,dry-run 模式下保留上游克隆目录便于对比
This commit is contained in:
@@ -30,6 +30,7 @@ class AdminUpdateServiceBase
|
||||
public $optionalConflict = null; // null=未指定(走交互), skip|overwrite|ask
|
||||
public $forceConflict = null; // null=未指定(走交互), overwrite|skip|ask
|
||||
public $showScope = null; // null=未指定(默认all), all|conflict
|
||||
public $keepRepo = false; // dry-run模式下保留上游克隆目录
|
||||
public $skippedConflictFiles = []; // [file_path => ['type' => 'add|delete|update', 'category' => 'optional|force']]
|
||||
|
||||
/**
|
||||
@@ -351,7 +352,14 @@ class AdminUpdateServiceBase
|
||||
|
||||
if (empty($need_process_files)) {
|
||||
$output->writeln('没有需要更新的文件');
|
||||
$this->cleanWorkpaceDir();
|
||||
|
||||
// 即使没有需要处理的文件,如果有跳过的冲突文件且keepRepo,保留目录并输出摘要
|
||||
if ($this->dryRun && $this->keepRepo && !empty($this->skippedConflictFiles)) {
|
||||
$this->outputSkippedFilesSummary($this->skippedConflictFiles, $output);
|
||||
$this->outputKeepRepoPaths($current_version_dir, $last_version_dir, $now_dir, $output);
|
||||
} else {
|
||||
$this->cleanWorkpaceDir();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -470,6 +478,11 @@ class AdminUpdateServiceBase
|
||||
$output->writeln("风险评估: 强制冲突 {$force_conflict_count}个(高风险) | 可选冲突 {$optional_conflict_count}个(中风险) | 无冲突变更 {$no_conflict_count}个(低风险)");
|
||||
}
|
||||
|
||||
// 跳过文件汇总输出(独立于 --show 参数和 need_process_files)
|
||||
if ($this->dryRun && !empty($this->skippedConflictFiles)) {
|
||||
$this->outputSkippedFilesSummary($this->skippedConflictFiles, $output);
|
||||
}
|
||||
|
||||
// 非 dry-run 模式:仅在显式传了 --show 时输出变更摘要
|
||||
if (!$this->dryRun && $this->showScope !== null && !empty($need_process_files)) {
|
||||
$showScope = $this->showScope ?: 'all';
|
||||
@@ -530,7 +543,11 @@ class AdminUpdateServiceBase
|
||||
}
|
||||
}
|
||||
|
||||
$this->cleanWorkpaceDir();
|
||||
if ($this->dryRun && $this->keepRepo) {
|
||||
$this->outputKeepRepoPaths($current_version_dir, $last_version_dir, $now_dir, $output);
|
||||
} else {
|
||||
$this->cleanWorkpaceDir();
|
||||
}
|
||||
}
|
||||
|
||||
protected function showPostUpdateGuidance(array $need_process_files, Output $output): void
|
||||
@@ -641,6 +658,28 @@ class AdminUpdateServiceBase
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function outputSkippedFilesSummary(array $skippedFiles, Output $output): void
|
||||
{
|
||||
$output->writeln('');
|
||||
$output->writeln('跳过的冲突文件(' . count($skippedFiles) . '个):');
|
||||
foreach ($skippedFiles as $file_path => $info) {
|
||||
$category = $info['category'];
|
||||
$output->writeln(' ' . $file_path . ' [' . $category . ']');
|
||||
$output->writeln(' 对比: diff runtime/update/current/' . $file_path . ' runtime/update/repo/' . $file_path);
|
||||
$output->writeln(' 开发者版本: ' . $file_path);
|
||||
}
|
||||
}
|
||||
|
||||
protected function outputKeepRepoPaths(string $currentDir, string $repoDir, string $nowDir, Output $output): void
|
||||
{
|
||||
$output->writeln('');
|
||||
$output->writeln('已保留更新目录(预览模式 --keep-repo):');
|
||||
$output->writeln(' 当前版本原始代码: ' . $currentDir);
|
||||
$output->writeln(' 上游最新代码: ' . $repoDir);
|
||||
$output->writeln(' 开发者代码: ' . $nowDir);
|
||||
$output->writeln(' 目录将在下次更新时自动清理,或手动删除 runtime/update/');
|
||||
}
|
||||
|
||||
protected function cleanWorkpaceDir()
|
||||
{
|
||||
$dir = App::getRuntimePath() . '/update/';
|
||||
|
||||
@@ -28,6 +28,7 @@ class UpdateBase extends Command
|
||||
->addOption('optional-conflict', null, Option::VALUE_OPTIONAL, '可选文件冲突处理策略: skip|overwrite|ask')
|
||||
->addOption('force-conflict', null, Option::VALUE_OPTIONAL, '强制文件冲突处理策略: overwrite|skip|ask')
|
||||
->addOption('show', null, Option::VALUE_OPTIONAL, '变更输出范围: all|conflict')
|
||||
->addOption('keep-repo', null, Option::VALUE_NONE, '预览模式下保留上游克隆目录,便于手动对比跳过的文件')
|
||||
->setDescription('更新系统代码');
|
||||
}
|
||||
|
||||
@@ -49,6 +50,7 @@ class UpdateBase extends Command
|
||||
$update_service->optionalConflict = $input->getOption('optional-conflict') ?: null;
|
||||
$update_service->forceConflict = $input->getOption('force-conflict') ?: null;
|
||||
$update_service->showScope = $input->getOption('show') ?: null;
|
||||
$update_service->keepRepo = (bool)$input->getOption('keep-repo');
|
||||
|
||||
$update_service->update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user