fix(git): handle untracked files in collectDiffs for commit message generation

Amp-Thread-ID: https://ampcode.com/threads/T-019c0a87-5323-7098-bea3-a1fc7cd43c18
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
MrLYC
2026-01-30 00:26:18 +08:00
co-authored by Amp
parent 0bd4dc12e4
commit 07597a3d14
+9 -2
View File
@@ -424,8 +424,15 @@ export async function getDiff(directory, { path, staged = false, contextLines =
noIndexArgs.push(`-U${Math.max(0, contextLines)}`);
}
noIndexArgs.push('--no-index', '--', '/dev/null', path);
const noIndexDiff = await git.raw(noIndexArgs);
return noIndexDiff;
try {
const noIndexDiff = await git.raw(noIndexArgs);
return noIndexDiff;
} catch (noIndexError) {
if (noIndexError.message && noIndexError.message.includes('diff --git')) {
return noIndexError.message;
}
throw noIndexError;
}
}
} catch (error) {
console.error('Failed to get Git diff:', error);