Enhance move-env-to-worktree script to respect gitignore for non-.env files and always include .env files (excluding .env.example). This improves file handling during environment setup in worktrees.

This commit is contained in:
dal 2025-07-25 19:38:21 -06:00
parent f8f33365ea
commit 4672f0fcaa
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
1 changed files with 11 additions and 6 deletions

View File

@ -95,17 +95,22 @@ async function findEnvFiles(dir: string, baseDir: string = dir): Promise<string[
const fullPath = join(currentDir, entry.name);
const relativePath = relative(baseDir, fullPath);
// Check if this path is ignored
if (isIgnored(fullPath, gitignoreStack)) {
continue;
}
if (entry.isDirectory()) {
// Always skip .git directory
if (entry.name === '.git') continue;
// Check if directory is ignored
if (isIgnored(fullPath, gitignoreStack)) {
continue;
}
await walkDir(fullPath, gitignoreStack);
} else if (entry.name.startsWith('.env')) {
} else if (entry.name.startsWith('.env') && !entry.name.endsWith('.example')) {
// Always include .env files (but not .env.example), regardless of gitignore rules
envFiles.push(relativePath);
} else {
// For non-.env files, check if they're ignored
if (isIgnored(fullPath, gitignoreStack)) {
continue;
}
}
}
} catch (error) {