[create-next-app]: respecting the user's init.defaultBranch
git con… (#49960)
### What? This commit makes sure `create-next-app` doesn't ignore user's git configuration (`init.defaultBranch`). ### Why? Hard coding configurations of a user is annoying (for the user). Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
This commit is contained in:
parent
77a3172b8e
commit
a8621c7bb2
1 changed files with 11 additions and 1 deletions
|
@ -19,6 +19,14 @@ function isInMercurialRepository(): boolean {
|
|||
return false
|
||||
}
|
||||
|
||||
function isDefaultBranchSet(): boolean {
|
||||
try {
|
||||
execSync('git config init.defaultBranch', { stdio: 'ignore' })
|
||||
return true
|
||||
} catch (_) {}
|
||||
return false
|
||||
}
|
||||
|
||||
export function tryGitInit(root: string): boolean {
|
||||
let didInit = false
|
||||
try {
|
||||
|
@ -30,7 +38,9 @@ export function tryGitInit(root: string): boolean {
|
|||
execSync('git init', { stdio: 'ignore' })
|
||||
didInit = true
|
||||
|
||||
execSync('git checkout -b main', { stdio: 'ignore' })
|
||||
if (!isDefaultBranchSet()) {
|
||||
execSync('git checkout -b main', { stdio: 'ignore' })
|
||||
}
|
||||
|
||||
execSync('git add -A', { stdio: 'ignore' })
|
||||
execSync('git commit -m "Initial commit from Create Next App"', {
|
||||
|
|
Loading…
Reference in a new issue