mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-31 06:42:03 +00:00
fix: expand untracked directories to show individual file diffs
Previously, when git status reported an untracked directory (e.g., "?? apps/"), the code would try to read the directory as a file, which failed and showed "[Unable to read file content]". Now, when encountering a directory: - Strip trailing slash from path (git reports dirs as "dirname/") - Check if path is a directory using stats.isDirectory() - Recursively list all files inside using listAllFilesInDirectory - Generate synthetic diffs for each file found This ensures users see the actual file contents in the diff view instead of an error placeholder.
This commit is contained in:
@@ -118,7 +118,7 @@ describe('diff.ts', () => {
|
||||
expect(diff).toContain('[Unable to read file content]');
|
||||
});
|
||||
|
||||
it('should handle directory path gracefully', async () => {
|
||||
it('should handle empty directory path gracefully', async () => {
|
||||
const dirName = 'some-directory';
|
||||
const dirPath = path.join(tempDir, dirName);
|
||||
await fs.mkdir(dirPath);
|
||||
@@ -127,7 +127,38 @@ describe('diff.ts', () => {
|
||||
|
||||
expect(diff).toContain(`diff --git a/${dirName} b/${dirName}`);
|
||||
expect(diff).toContain('new file mode 040000');
|
||||
expect(diff).toContain('[Directory]');
|
||||
expect(diff).toContain('[Empty directory]');
|
||||
});
|
||||
|
||||
it('should expand directory with files and generate diffs for each file', async () => {
|
||||
const dirName = 'new-feature';
|
||||
const dirPath = path.join(tempDir, dirName);
|
||||
await fs.mkdir(dirPath);
|
||||
await fs.writeFile(path.join(dirPath, 'index.ts'), 'export const foo = 1;\n');
|
||||
await fs.writeFile(path.join(dirPath, 'utils.ts'), 'export const bar = 2;\n');
|
||||
|
||||
const diff = await generateSyntheticDiffForNewFile(tempDir, dirName);
|
||||
|
||||
// Should contain diffs for both files in the directory
|
||||
expect(diff).toContain(`diff --git a/${dirName}/index.ts b/${dirName}/index.ts`);
|
||||
expect(diff).toContain(`diff --git a/${dirName}/utils.ts b/${dirName}/utils.ts`);
|
||||
expect(diff).toContain('+export const foo = 1;');
|
||||
expect(diff).toContain('+export const bar = 2;');
|
||||
// Should NOT contain a diff for the directory itself
|
||||
expect(diff).not.toContain('[Empty directory]');
|
||||
});
|
||||
|
||||
it('should handle directory path with trailing slash', async () => {
|
||||
const dirName = 'trailing-slash-dir';
|
||||
const dirPath = path.join(tempDir, dirName);
|
||||
await fs.mkdir(dirPath);
|
||||
await fs.writeFile(path.join(dirPath, 'file.txt'), 'content\n');
|
||||
|
||||
// git status reports untracked directories with trailing slash
|
||||
const diff = await generateSyntheticDiffForNewFile(tempDir, `${dirName}/`);
|
||||
|
||||
expect(diff).toContain(`diff --git a/${dirName}/file.txt b/${dirName}/file.txt`);
|
||||
expect(diff).toContain('+content');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user