MCPcopy Create free account
hub / github.com/REditorSupport/vscode-R / createGitignore

Function createGitignore

src/rGitignore.ts:11–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9import { catchAsError, getCurrentWorkspaceFolder } from './util';
10
11export async function createGitignore(): Promise<void> {
12 // .gitignore template from "https://github.com/github/gitignore/blob/main/R.gitignore"
13 const ignoreFileTemplate = extensionContext.asAbsolutePath('R/template/R.gitignore');
14 const ignoreFileContent = readFileSync(ignoreFileTemplate);
15
16 const currentWorkspaceFolder = getCurrentWorkspaceFolder()?.uri.fsPath;
17 if (currentWorkspaceFolder === undefined) {
18 void window.showWarningMessage('Please open a workspace folder to create .gitignore');
19 return;
20 }
21 const ignorePath = join(currentWorkspaceFolder, '.gitignore');
22 if (existsSync(ignorePath)) {
23 const overwrite = await window.showWarningMessage(
24 '".gitignore" file already exists. Do you want to overwrite?',
25 'Yes', 'No'
26 );
27 if (overwrite === 'No') {
28 return;
29 }
30 }
31 writeFile(ignorePath, ignoreFileContent, (err) => {
32 try {
33 if (err) {
34 void window.showErrorMessage(err.name);
35 }
36 } catch (e) {
37 void window.showErrorMessage(catchAsError(e).message);
38 }
39 });
40}

Callers

nothing calls this directly

Calls 2

catchAsErrorFunction · 0.90

Tested by

no test coverage detected