fix(merge): in-place 合并脏树守卫忽略未跟踪文件(--untracked-files=no)
之前 mergeInPrimaryCheckout 用 git status --porcelain 判脏,未跟踪文件(GEMINI.md/.claude/ 本地杂物)也算进去 → 误判拒绝合并(jiu/dudu 等带未跟踪文件的项目「通过并合并」必失败)。 改为 --untracked-files=no 只看已跟踪改动;未跟踪文件不挡合并(真要被覆盖时 git merge 自报错走 catch)。 测试加:仅未跟踪文件 → 仍 in-place 合并成功。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -140,6 +140,22 @@ test('mergeBranch:main 被主检出占用但工作区有未提交改动 →
|
||||
assert.equal(gitSync(repo, ['rev-parse', 'main']).trim(), mainBefore, 'main 无损');
|
||||
});
|
||||
|
||||
test('mergeBranch:main 被主检出占用、仅有未跟踪文件 → 不算脏,仍 in-place 合并成功', async (t) => {
|
||||
const repo = setup(t);
|
||||
gitSync(repo, ['checkout', '-b', 'maestro/tsk_ut']);
|
||||
commitFile(repo, 'a.txt', 'A\n', 'maestro(tsk_ut): add a');
|
||||
gitSync(repo, ['checkout', 'main']);
|
||||
// 主检出有未跟踪文件(项目常见本地杂物,如 GEMINI.md/.claude/…)——不应挡合并
|
||||
writeFileSync(join(repo, 'LOCAL_NOTES.md'), 'untracked junk\n');
|
||||
const mainBefore = gitSync(repo, ['rev-parse', 'main']).trim();
|
||||
|
||||
const r = await mergeBranch(repo, 'maestro/tsk_ut', 'main', 'tsk_ut');
|
||||
assert.equal(r.ok, true, r.error);
|
||||
assert.notEqual(gitSync(repo, ['rev-parse', 'main']).trim(), mainBefore, 'main 应前进');
|
||||
assert.equal(gitSync(repo, ['show', 'main:a.txt']), 'A\n');
|
||||
assert.ok(existsSync(join(repo, 'LOCAL_NOTES.md')), '未跟踪文件应原样保留');
|
||||
});
|
||||
|
||||
test('mergeBranch:重复合并(分支已在 main 里)→ ok,不新建提交', async (t) => {
|
||||
const repo = setup(t);
|
||||
gitSync(repo, ['checkout', '-b', 'maestro/tsk_re']);
|
||||
|
||||
Reference in New Issue
Block a user