diff --git a/apps/ai-game-creator-shell/scripts/bump-version.mjs b/apps/ai-game-creator-shell/scripts/bump-version.mjs index 3911ce972..9e4a9eb9a 100644 --- a/apps/ai-game-creator-shell/scripts/bump-version.mjs +++ b/apps/ai-game-creator-shell/scripts/bump-version.mjs @@ -44,7 +44,39 @@ function hasUncommittedVersionChanges() { ); } +function otherStagedFiles() { + const result = spawnSync( + 'git', + ['diff', '--cached', '--name-only'], + { cwd: repoRoot, encoding: 'utf8' }, + ); + if (result.status !== 0) { + throw new Error('无法读取已暂存文件列表'); + } + const versionSet = new Set(versionFiles); + return result.stdout + .split('\n') + .map((file) => file.trim()) + .filter(Boolean) + .filter((file) => !versionSet.has(file)); +} + const { target, commit } = parseArgs(process.argv); + +// 提交前先确认没有其他已暂存改动,避免把无关改动一并提交;若存在则在改动任何文件前中止。 +if (commit) { + const others = otherStagedFiles(); + if (others.length > 0) { + console.error( + `[bump-version] 检测到其他已暂存改动,为避免误提交,请先单独处理后再运行 --commit:\n ${others.join('\n ')}`, + ); + console.error( + '提示:用 git restore --staged 取消暂存,或先提交这些改动。', + ); + process.exit(1); + } +} + const current = readLocalVersion(); // 若版本文件已带着一次未提交的提升(例如先默认跑过一次),再 --commit 时不再重复递增,直接提交现有改动。 diff --git a/docs/technical/【技术方案】AGC客户端更新检查与下载-2026-08-31.md b/docs/technical/【技术方案】AGC客户端更新检查与下载-2026-08-31.md index 4d6fa256a..10a9367e4 100644 --- a/docs/technical/【技术方案】AGC客户端更新检查与下载-2026-08-31.md +++ b/docs/technical/【技术方案】AGC客户端更新检查与下载-2026-08-31.md @@ -59,7 +59,8 @@ npm run ai-game-creator-shell:bump-version -- --version 0.1.25 --commit ``` 若先用默认方式写入版本(未提交),再补 `--commit`,命令会识别到工作区已提升、直接提交现有改动, -**不会重复递增**。提交标题固定为“提升 AGC 版本至 x.y.z”。 +**不会重复递增**。提交前若检测到**除版本文件外的其他已暂存改动**,会中止并提示先处理,避免误提交无关内容。 +提交标题固定为“提升 AGC 版本至 x.y.z”。 **发布只读仓库版本(`npm run ai-game-creator-shell:build` 与 `release:upload`)**