File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 11import * as TT from 'typings/tutorial'
22import { exec , exists } from '../node'
3+ import { version , compareVersions } from '../dependencies'
34import logger from '../logger'
45
56export const gitOrigin = 'coderoad'
@@ -70,8 +71,22 @@ export async function clear(): Promise<Error | void> {
7071}
7172
7273async function init ( ) : Promise < Error | void > {
74+ const gitVersion = await version ( 'git' )
75+ if ( ! gitVersion ) {
76+ throw new Error ( 'Error: No git version found' )
77+ }
78+ const hasInitialBranch = await compareVersions ( gitVersion , '>=2.28.0' )
79+ let stderr
80+ if ( hasInitialBranch ) {
81+ // --initial-branch is introduced in git v2.28 when git changed the default master -> main
82+ const initResult = await exec ( { command : 'git init --initial-branch=master' } )
83+ stderr = initResult . stderr
84+ } else {
85+ // pre git v2.28, master is default branch
86+ const initResult = await exec ( { command : 'git init' } )
87+ stderr = initResult . stderr
88+ }
7389 // note: prevents stderr warning concerning default init branch
74- const { stderr } = await exec ( { command : 'git init --initial-branch=master' } )
7590 if ( stderr ) {
7691 throw new Error ( `Error initializing Git: ${ stderr } ` )
7792 }
You can’t perform that action at this time.
0 commit comments