(
projectDir: string,
commitMsg: string,
)
| 10 | * @param commitMsg Message for initial commit. |
| 11 | */ |
| 12 | export async function initGitDir( |
| 13 | projectDir: string, |
| 14 | commitMsg: string, |
| 15 | ): Promise<void> { |
| 16 | if (!projectDir || !fs.existsSync(projectDir)) { |
| 17 | outputChannel.appendLine( |
| 18 | `Error: Project directory does not exist: ${projectDir}`, |
| 19 | ); |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | if (!commitMsg || commitMsg.trim().length === 0) { |
| 24 | commitMsg = "Initial commit"; |
| 25 | } |
| 26 | |
| 27 | try { |
| 28 | // .gitignore content - ignore build artifacts |
| 29 | const gitignore = "/build\n/dist\n"; |
| 30 | await fs.promises.writeFile( |
| 31 | path.join(projectDir, ".gitignore"), |
| 32 | gitignore, |
| 33 | ); |
| 34 | |
| 35 | // Initialize git repository |
| 36 | let initCmd = `git init && git config core.safecrlf false`; |
| 37 | initCmd += ` && git add -A && git commit -q -m "${commitMsg}"`; |
| 38 | const report = `Initializing ${projectDir} as Git repository`; |
| 39 | await executeProcess({ |
| 40 | name: "Initializing Git", |
| 41 | report: report, |
| 42 | command: initCmd, |
| 43 | args: [], |
| 44 | shell: true, |
| 45 | cwd: projectDir, |
| 46 | }); |
| 47 | } catch (err) { |
| 48 | const errorMessage = |
| 49 | err instanceof Error ? err.message : String(err); |
| 50 | outputChannel.appendLine( |
| 51 | `Error: Initializing project dir as Git repository: ${errorMessage}`, |
| 52 | ); |
| 53 | } |
| 54 | } |
| 55 | } |
nothing calls this directly
no test coverage detected