Unverified Commit a8621c7b authored by Abhishek Kadam's avatar Abhishek Kadam Committed by GitHub

[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: 's avatarSteven <229881+styfle@users.noreply.github.com>
parent 77a3172b
......@@ -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"', {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment