[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:
Abhishek Kadam 2023-05-21 05:23:58 +05:30 committed by GitHub
parent 77a3172b8e
commit a8621c7bb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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"', {