diff --git a/extend/base/common/command/admin/VersionBase.php b/extend/base/common/command/admin/VersionBase.php index 3960a1e..4aa4c9a 100644 --- a/extend/base/common/command/admin/VersionBase.php +++ b/extend/base/common/command/admin/VersionBase.php @@ -213,43 +213,39 @@ class VersionBase extends Command // 获取所有tags,按时间倒序排列 $tags = explode("\n", trim(shell_exec('git tag --sort=-creatordate'))); - // 如果没有指定起始版本,则获取倒数第二个tag + + if (empty($tags)) { + $output->error('没有找到任何tag'); + + return; + } + + $toTag = $tags[0]; // 最新的tag if (empty($fromTag)) { if (count($tags) < 2) { $output->error('没有足够的tag来生成发布说明'); return; } - $fromTag = $tags[1]; // 倒数第二个tag - $toTag = $tags[0]; // 最新的tag - $output->info('未指定起始版本,使用倒数第二个tag: ' . $fromTag); - $output->info('到最新tag: ' . $toTag); } else { - // 如果指定了fromTag,找到比fromTag新的最近的tag - $toTag = null; - foreach ($tags as $tag) { - if (version_compare($tag, $fromTag, '>')) { - $toTag = $tag; - break; - } - } - - if ($toTag === null) { - $output->error('没有找到比 ' . $fromTag . ' 更新的tag'); + if (!in_array($fromTag, $tags)) { + $output->error('指定的起始版本 ' . $fromTag . ' 不存在'); + + return; + } + if (version_compare($fromTag, $toTag, '>=')) { + $output->error('指定的起始版本 ' . $fromTag . ' 不早于最新版本 ' . $toTag); return; } - $output->info('从指定版本开始生成发布说明: ' . $fromTag); - $output->info('到最新tag: ' . $toTag); } + $output->info('从版本 ' . $fromTag . ' 生成发布说明'); + $output->info('到最新tag: ' . $toTag); // 获取当前版本 - $currentVersion = static::VERSION; - if (!empty(static::PRODUCT_VERSION)) { - $currentVersion = static::PRODUCT_VERSION; - } + $currentVersion = static::PRODUCT_VERSION ?: static::VERSION; // 获取从指定tag到目标tag的所有提交,包含提交哈希和提交日期 $commits = shell_exec("git log {$fromTag}..{$toTag} --pretty=format:\"%h|%ad|%s\" --date=short"); @@ -324,7 +320,7 @@ class VersionBase extends Command $groupedCommits['其他'][] = $formatCallback($message, $commit); } } - + // 清空空分组 foreach (array_keys($groupedCommits) as $key) { if (empty($groupedCommits[$key])) {