Skip to content

Commit e1cddd0

Browse files
committed
only add .local to gitignore if there are .local files
1 parent f9ad53e commit e1cddd0

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/project/project-gitignore.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { join } from "path/mod.ts";
9-
import { exists } from "fs/mod.ts";
9+
import { exists, walkSync } from "fs/mod.ts";
1010

1111
import { which } from "../core/path.ts";
1212
import { execProcess } from "../core/process.ts";
@@ -15,7 +15,7 @@ import { kQuartoScratch } from "./project-scratch.ts";
1515
import { lines } from "../core/text.ts";
1616
import { isEnvDir } from "../core/jupyter/capabilities.ts";
1717

18-
export const kQuartoIgnore = [`/${kQuartoScratch}/`, `/_*.local`];
18+
export const kQuartoIgnore = [`/${kQuartoScratch}/`];
1919

2020
export async function ensureGitignore(
2121
dir: string,
@@ -32,6 +32,17 @@ export async function ensureGitignore(
3232
requiredEntries.push(requiredEntry);
3333
}
3434
}
35+
// see if we need to gitignore any .local files
36+
const kLocalEntry = `/_*.local`;
37+
if (!gitignore.includes(kLocalEntry)) {
38+
for (const walk of walkSync(dir, { maxDepth: 1 })) {
39+
if (walk.name.match(/^_.*?\.local$/)) {
40+
requiredEntries.push(kLocalEntry);
41+
break;
42+
}
43+
}
44+
}
45+
3546
if (requiredEntries.length > 0) {
3647
writeGitignore(dir, gitignore.concat(requiredEntries));
3748
return true;

0 commit comments

Comments
 (0)