File tree Expand file tree Collapse file tree 1 file changed +26
-5
lines changed
Expand file tree Collapse file tree 1 file changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -343,11 +343,32 @@ async function runDirenvAllow(worktreePath: string): Promise<void> {
343343 const envrcPath = join ( worktreePath , '.envrc' )
344344 if ( existsSync ( envrcPath ) ) {
345345 console . log ( 'Running direnv allow...' )
346- try {
347- await runCommand ( 'direnv' , [ 'allow' ] , worktreePath )
348- } catch ( error ) {
349- console . warn ( 'Failed to run direnv allow:' , error )
350- }
346+ return new Promise ( ( resolve ) => {
347+ // Use bash -c with explicit cd to ensure direnv sees the correct directory context
348+ // Just using cwd option doesn't work reliably with direnv
349+ const proc = spawn ( 'bash' , [ '-c' , `cd '${ worktreePath } ' && direnv allow` ] , {
350+ stdio : 'inherit' ,
351+ shell : false ,
352+ } )
353+
354+ proc . on ( 'close' , ( code ) => {
355+ if ( code === 0 ) {
356+ console . log ( 'direnv allow completed successfully' )
357+ } else {
358+ console . warn ( `direnv allow exited with code ${ code } ` )
359+ }
360+ resolve ( )
361+ } )
362+
363+ proc . on ( 'error' , ( error ) => {
364+ if ( ( error as NodeJS . ErrnoException ) . code === 'ENOENT' ) {
365+ console . warn ( 'bash not found, skipping direnv allow' )
366+ } else {
367+ console . warn ( 'Failed to run direnv allow:' , error . message )
368+ }
369+ resolve ( )
370+ } )
371+ } )
351372 } else {
352373 console . log ( 'No .envrc found, skipping direnv allow' )
353374 }
You can’t perform that action at this time.
0 commit comments