()
| 9 | import { catchAsError, getCurrentWorkspaceFolder } from './util'; |
| 10 | |
| 11 | export 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 | } |
nothing calls this directly
no test coverage detected