fix: preserve changes when diff fails

This commit is contained in:
2026-08-23 16:12:20 +08:00
parent 7e024093b1
commit f9e21195c1
3 changed files with 50 additions and 5 deletions

View File

@@ -325,10 +325,17 @@ export class ConversationChangeTracker {
diff?: string;
truncated?: boolean;
}> {
const [working, staged] = await Promise.all([
this.git.run(projectPath, ['diff', '--no-ext-diff', '--no-color', '--relative', '--', relativePath]),
this.git.run(projectPath, ['diff', '--cached', '--no-ext-diff', '--no-color', '--relative', '--', relativePath]),
]);
let working: GitCommandResult;
let staged: GitCommandResult;
try {
[working, staged] = await Promise.all([
this.git.run(projectPath, ['diff', '--no-ext-diff', '--no-color', '--relative', '--', relativePath]),
this.git.run(projectPath, ['diff', '--cached', '--no-ext-diff', '--no-color', '--relative', '--', relativePath]),
]);
} catch {
return {};
}
if (working.code !== 0 || staged.code !== 0) return {};
const bounded = boundedText(`${staged.stdout}${working.stdout}`, MAX_DIFF_BYTES);
return {
...(bounded.text ? { diff: bounded.text } : {}),