mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-30 06:12:03 +00:00
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.
This commit is contained in:
@@ -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]`]);
|
||||
|
||||
Reference in New Issue
Block a user