From 407cf633e0197bf843760f2fd9cf044f8cda0f4f Mon Sep 17 00:00:00 2001 From: Tony Nekola Date: Wed, 24 Dec 2025 23:42:05 +0200 Subject: [PATCH] fix: check directory before binary extension to handle edge cases Move directory check before binary file check to handle edge cases where a directory has a binary file extension (e.g., "images.png/"). Previously, such directories would be incorrectly treated as binary files instead of being expanded. --- libs/git-utils/src/diff.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) 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]`]);