MCPcopy Index your code
hub / github.com/coderoad/coderoad-vscode / init

Function init

src/services/git/index.ts:73–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

71}
72
73async function init(): Promise<Error | void> {
74 const { version: gitVersion, error: gitError } = await getVersion('git')
75 if (gitError) {
76 throw new Error(`Error: Git config error: ${gitError.message}`)
77 }
78 if (!gitVersion) {
79 throw new Error('Error: No git version found')
80 }
81 const hasInitialBranch = await compareVersions(gitVersion, '>=2.28.0')
82 let stderr
83 if (hasInitialBranch) {
84 // --initial-branch is introduced in git v2.28 when git changed the default master -> main
85 const initResult = await exec({ command: 'git init --initial-branch=master' })
86 stderr = initResult.stderr
87 } else {
88 // pre git v2.28, master is default branch
89 const initResult = await exec({ command: 'git init' })
90 stderr = initResult.stderr
91 }
92 // note: prevents stderr warning concerning default init branch
93 if (stderr) {
94 throw new Error(`Error initializing Git: ${stderr}`)
95 }
96}
97
98export async function initIfNotExists(): Promise<never | void> {
99 const hasGitInit = exists('.git')

Callers 1

initIfNotExistsFunction · 0.85

Calls 3

getVersionFunction · 0.90
compareVersionsFunction · 0.90
execFunction · 0.90

Tested by

no test coverage detected