@@ -307,38 +307,51 @@ export const getProjectFileContext = async (
307307 * - lastCommitMessages: Recent commit messages, formatted as a newline-separated string
308308 */
309309async function getGitChanges ( ) {
310- try {
311- const { stdout : status } = await execAsync ( 'git status' , {
312- cwd : projectRoot ,
310+ const status = execAsync ( 'git status' , { cwd : projectRoot } )
311+ . then ( ( { stdout } ) => stdout )
312+ . catch ( ( error ) => {
313+ logger . error ( { error } , 'Failed to get git status' )
314+ return ''
313315 } )
314- const { stdout : diff } = await execAsync ( 'git diff' , { cwd : projectRoot } )
315- const { stdout : diffCached } = await execAsync ( 'git diff --cached' , {
316- cwd : projectRoot ,
316+
317+ const diff = execAsync ( 'git diff' , { cwd : projectRoot } )
318+ . then ( ( { stdout } ) => stdout )
319+ . catch ( ( error ) => {
320+ logger . error ( { error } , 'Failed to get git diff' )
321+ return ''
317322 } )
318- const { stdout : shortLogOutput } = await execAsync (
319- 'git shortlog HEAD~10..HEAD' ,
320- {
321- cwd : projectRoot ,
322- }
323- )
324- const shortLogLines = shortLogOutput . trim ( ) . split ( '\n' )
325- const lastCommitMessages = shortLogLines
326- . slice ( 1 )
327- . reverse ( )
328- . map ( ( line ) => line . trim ( ) )
329- . join ( '\n' )
330-
331- return { status, diff, diffCached, lastCommitMessages }
332- } catch ( error ) {
333- logger . error (
334- {
335- errorMessage : error instanceof Error ? error . message : String ( error ) ,
336- errorStack : error instanceof Error ? error . stack : undefined ,
337- projectRoot,
338- } ,
339- 'Failed to get git changes'
323+
324+ const diffCached = execAsync ( 'git diff --cached' , {
325+ cwd : projectRoot ,
326+ } )
327+ . then ( ( { stdout } ) => stdout )
328+ . catch ( ( error ) => {
329+ logger . error ( { error } , 'Failed to get git diff --cached' )
330+ return ''
331+ } )
332+
333+ const lastCommitMessages = execAsync ( 'git shortlog HEAD~10..HEAD' , {
334+ cwd : projectRoot ,
335+ } )
336+ . then ( ( { stdout } ) =>
337+ stdout
338+ . trim ( )
339+ . split ( '\n' )
340+ . slice ( 1 )
341+ . reverse ( )
342+ . map ( ( line ) => line . trim ( ) )
343+ . join ( '\n' )
340344 )
341- return { status : '' , diff : '' , diffCached : '' , lastCommitMessages : '' }
345+ . catch ( ( error ) => {
346+ logger . error ( { error } , 'Failed to get lastCommitMessages' )
347+ return ''
348+ } )
349+
350+ return {
351+ status : await status ,
352+ diff : await diff ,
353+ diffCached : await diffCached ,
354+ lastCommitMessages : await lastCommitMessages ,
342355 }
343356}
344357
0 commit comments