@@ -176,34 +176,57 @@ class GitService {
176176
177177 /**
178178 * Get the diff in the git repository.
179+ * Handles submodules correctly by using simple-git with safe configuration.
179180 * @returns The diff object is being returned.
180181 */
181182 async getGitDiff ( repo : Repository , _cachedInput = true , nameOnly ?: boolean ) {
182- // let diff = await repo.diff(cached);
183- const git = simpleGit ( repo . rootUri . fsPath ) ;
183+ // Configure simple-git for proper submodule handling
184+ const git = simpleGit ( repo . rootUri . fsPath , {
185+ binary : "git" ,
186+ maxConcurrentProcesses : 6 ,
187+ } ) ;
188+
184189 let diff : string | null = "" ;
185190
186191 // Get exclusion patterns from settings
187192 const excludePatterns = WorkspaceService . getInstance ( ) . getExcludeFilesFromDiff ( ) ;
188193
189- if ( ! nameOnly ) {
190- diff = await git . diff ( [ "--cached" ] ) . catch ( ( error ) => {
191- this . showErrorMessage ( "git repository not found" ) ;
192- console . error ( error ) ;
194+ try {
195+ // Check if we're in a valid git repository (handles submodules)
196+ const isRepo = await git . checkIsRepo ( ) ;
197+ if ( ! isRepo ) {
198+ this . showErrorMessage ( "Not a git repository" ) ;
193199 return null ;
194- } ) ;
200+ }
195201
196- // Apply file filtering if diff was successful
197- if ( diff && excludePatterns . length > 0 ) {
198- diff = this . filterDiffByExclusions ( diff , excludePatterns ) ;
202+ if ( ! nameOnly ) {
203+ diff = await git . diff ( [ "--cached" ] ) ;
204+
205+ // Apply file filtering if diff was successful
206+ if ( diff && excludePatterns . length > 0 ) {
207+ diff = this . filterDiffByExclusions ( diff , excludePatterns ) ;
208+ }
209+ } else {
210+ diff = await git . diff ( [ "--cached" , "--name-status" ] ) ;
199211 }
200- } else {
201- diff = await git . diff ( [ "--cached" , "--name-status" ] ) . catch ( ( error ) => {
202- this . showErrorMessage ( "git repository not found" ) ;
203- console . error ( error ) ;
204- return null ;
205- } ) ;
212+ } catch ( error ) {
213+ // Handle specific git errors
214+ if ( error && typeof error === "object" && "message" in error ) {
215+ const errorMessage = ( error as Error ) . message ;
216+ if ( errorMessage . includes ( "not a git repository" ) ) {
217+ this . showErrorMessage ( "Not a git repository" ) ;
218+ } else if ( errorMessage . includes ( "submodule" ) ) {
219+ this . showErrorMessage ( "Submodule error - ensure submodules are initialized" ) ;
220+ } else {
221+ this . showErrorMessage ( "Git operation failed" ) ;
222+ }
223+ } else {
224+ this . showErrorMessage ( "Git operation failed" ) ;
225+ }
226+ console . error ( "Git diff error:" , error ) ;
227+ return null ;
206228 }
229+
207230 return diff ;
208231 }
209232
0 commit comments