diff --git a/libs/git-utils/src/diff.ts b/libs/git-utils/src/diff.ts index 30db32da..450c6f51 100644 --- a/libs/git-utils/src/diff.ts +++ b/libs/git-utils/src/diff.ts @@ -57,20 +57,11 @@ export async function generateSyntheticDiffForNewFile( const fullPath = path.join(basePath, cleanPath); try { - // Check if it's a binary file - if (isBinaryFile(cleanPath)) { - return `diff --git a/${cleanPath} b/${cleanPath} -new file mode 100644 -index 0000000..0000000 -Binary file ${cleanPath} added -`; - } - // 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 so, recursively list all files and generate diffs for each + // Check if it's a directory first (before binary check) + // This handles edge cases like directories named "images.png/" if (stats.isDirectory()) { const filesInDir = await listAllFilesInDirectory(basePath, cleanPath); if (filesInDir.length === 0) { @@ -86,6 +77,15 @@ Binary file ${cleanPath} added return diffs.join(''); } + // Check if it's a binary file (after directory check to handle dirs with binary extensions) + if (isBinaryFile(cleanPath)) { + return `diff --git a/${cleanPath} b/${cleanPath} +new file mode 100644 +index 0000000..0000000 +Binary file ${cleanPath} added +`; + } + if (stats.size > MAX_SYNTHETIC_DIFF_SIZE) { const sizeKB = Math.round(stats.size / 1024); return createNewFileDiff(cleanPath, '100644', [`[File too large to display: ${sizeKB}KB]`]);