diff --git a/libs/git-utils/src/diff.ts b/libs/git-utils/src/diff.ts index 96609cfa..a5388f39 100644 --- a/libs/git-utils/src/diff.ts +++ b/libs/git-utils/src/diff.ts @@ -44,8 +44,21 @@ Binary file ${relativePath} added `; } - // Get file stats to check size + // Get file stats to check size and type const stats = await secureFs.stat(fullPath); + + // Check if it's a directory (can happen with untracked directories from git status) + if (stats.isDirectory()) { + return `diff --git a/${relativePath} b/${relativePath} +new file mode 040000 +index 0000000..0000000 +--- /dev/null ++++ b/${relativePath} +@@ -0,0 +1 @@ ++[Directory] +`; + } + if (stats.size > MAX_SYNTHETIC_DIFF_SIZE) { const sizeKB = Math.round(stats.size / 1024); return `diff --git a/${relativePath} b/${relativePath} diff --git a/libs/git-utils/tests/diff.test.ts b/libs/git-utils/tests/diff.test.ts index 6212df1a..953d2763 100644 --- a/libs/git-utils/tests/diff.test.ts +++ b/libs/git-utils/tests/diff.test.ts @@ -117,6 +117,18 @@ describe('diff.ts', () => { expect(diff).toContain(`diff --git a/${fileName} b/${fileName}`); expect(diff).toContain('[Unable to read file content]'); }); + + it('should handle directory path gracefully', async () => { + const dirName = 'some-directory'; + const dirPath = path.join(tempDir, dirName); + await fs.mkdir(dirPath); + + const diff = await generateSyntheticDiffForNewFile(tempDir, dirName); + + expect(diff).toContain(`diff --git a/${dirName} b/${dirName}`); + expect(diff).toContain('new file mode 040000'); + expect(diff).toContain('[Directory]'); + }); }); describe('appendUntrackedFileDiffs', () => {