Skip to content

Commit 0bc0ed8

Browse files
Fix direnv allow prompt in init-worktree script.
Improve handling of direnv .envrc file authorization to ensure proper setup during worktree initialization. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent bb2ca2d commit 0bc0ed8

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

scripts/init-worktree.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)