@@ -3,13 +3,15 @@ import fs from "node:fs";
33import path from "node:path" ;
44import { promisify } from "node:util" ;
55import { type IpcMainInvokeEvent , ipcMain } from "electron" ;
6+ import { getChangedFilesForRepo } from "./git" ;
67
78const execAsync = promisify ( exec ) ;
89const fsPromises = fs . promises ;
910
1011interface FileEntry {
1112 path : string ;
1213 name : string ;
14+ changed ?: boolean ;
1315}
1416
1517// Cache for repository files to avoid rescanning
@@ -41,6 +43,7 @@ async function listFilesRecursive(
4143 dirPath : string ,
4244 ignoredFiles : Set < string > ,
4345 baseDir : string ,
46+ changedFiles : Set < string > ,
4447) : Promise < FileEntry [ ] > {
4548 const files : FileEntry [ ] = [ ] ;
4649
@@ -51,9 +54,9 @@ async function listFilesRecursive(
5154 const fullPath = path . join ( dirPath , entry . name ) ;
5255 const relativePath = path . relative ( baseDir , fullPath ) ;
5356
54- // Skip hidden files/directories , node_modules, and common build dirs
57+ // Skip .git directory , node_modules, and common build dirs
5558 if (
56- entry . name . startsWith ( "." ) ||
59+ entry . name === ".git" ||
5760 entry . name === "node_modules" ||
5861 entry . name === "dist" ||
5962 entry . name === "build" ||
@@ -72,12 +75,14 @@ async function listFilesRecursive(
7275 fullPath ,
7376 ignoredFiles ,
7477 baseDir ,
78+ changedFiles ,
7579 ) ;
7680 files . push ( ...subFiles ) ;
7781 } else if ( entry . isFile ( ) ) {
7882 files . push ( {
7983 path : relativePath ,
8084 name : entry . name ,
85+ changed : changedFiles . has ( relativePath ) ,
8186 } ) ;
8287 }
8388 }
@@ -112,8 +117,16 @@ export function registerFsIpc(): void {
112117 // Get git-ignored files
113118 const ignoredFiles = await getGitIgnoredFiles ( repoPath ) ;
114119
120+ // Get changed files from git
121+ const changedFiles = await getChangedFilesForRepo ( repoPath ) ;
122+
115123 // List all files
116- allFiles = await listFilesRecursive ( repoPath , ignoredFiles , repoPath ) ;
124+ allFiles = await listFilesRecursive (
125+ repoPath ,
126+ ignoredFiles ,
127+ repoPath ,
128+ changedFiles ,
129+ ) ;
117130
118131 // Update cache
119132 repoFileCache . set ( repoPath , {
@@ -131,17 +144,26 @@ export function registerFsIpc(): void {
131144 f . path . toLowerCase ( ) . includes ( lowerQuery ) ||
132145 f . name . toLowerCase ( ) . includes ( lowerQuery ) ,
133146 )
134- . slice ( 0 , 50 ) ; // Limit results
147+ . slice ( 0 , 50 ) ; // Limit search results
135148 }
136149
137- return allFiles . slice ( 0 , 100 ) ; // Limit initial results
150+ return allFiles ; // Return all files for full tree view
138151 } catch ( error ) {
139152 console . error ( "Error listing repo files:" , error ) ;
140153 return [ ] ;
141154 }
142155 } ,
143156 ) ;
144157
158+ ipcMain . handle (
159+ "clear-repo-file-cache" ,
160+ async ( _event : IpcMainInvokeEvent , repoPath : string ) : Promise < void > => {
161+ if ( repoPath ) {
162+ repoFileCache . delete ( repoPath ) ;
163+ }
164+ } ,
165+ ) ;
166+
145167 // Plan file operations
146168 ipcMain . handle (
147169 "ensure-posthog-folder" ,
0 commit comments