bump-version 提交前校验,存在其他暂存改动时中止
- --commit 在改动任何版本文件前先检查已暂存文件,发现版本文件外的暂存改动则中止并提示,避免误提交无关内容 - 同步 AGC 更新技术方案文档说明
This commit is contained in:
@@ -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 <file> 取消暂存,或先提交这些改动。',
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const current = readLocalVersion();
|
||||
|
||||
// 若版本文件已带着一次未提交的提升(例如先默认跑过一次),再 --commit 时不再重复递增,直接提交现有改动。
|
||||
|
||||
@@ -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`)**
|
||||
|
||||
|
||||
Reference in New Issue
Block a user