mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 20:43:36 +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);
|
const fullPath = path.join(basePath, cleanPath);
|
||||||
|
|
||||||
try {
|
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
|
// Get file stats to check size and type
|
||||||
const stats = await secureFs.stat(fullPath);
|
const stats = await secureFs.stat(fullPath);
|
||||||
|
|
||||||
// Check if it's a directory (can happen with untracked directories from git status)
|
// Check if it's a directory first (before binary check)
|
||||||
// If so, recursively list all files and generate diffs for each
|
// This handles edge cases like directories named "images.png/"
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
const filesInDir = await listAllFilesInDirectory(basePath, cleanPath);
|
const filesInDir = await listAllFilesInDirectory(basePath, cleanPath);
|
||||||
if (filesInDir.length === 0) {
|
if (filesInDir.length === 0) {
|
||||||
@@ -86,6 +77,15 @@ Binary file ${cleanPath} added
|
|||||||
return diffs.join('');
|
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) {
|
if (stats.size > MAX_SYNTHETIC_DIFF_SIZE) {
|
||||||
const sizeKB = Math.round(stats.size / 1024);
|
const sizeKB = Math.round(stats.size / 1024);
|
||||||
return createNewFileDiff(cleanPath, '100644', [`[File too large to display: ${sizeKB}KB]`]);
|
return createNewFileDiff(cleanPath, '100644', [`[File too large to display: ${sizeKB}KB]`]);
|
||||||
|
|||||||
Reference in New Issue
Block a user