Skip to content

Commit

Permalink
[create-next-app]: respecting the user's init.defaultBranch git con… (
Browse files Browse the repository at this point in the history
#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>
  • Loading branch information
lycuid and styfle committed May 20, 2023
1 parent 77a3172 commit a8621c7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/create-next-app/helpers/git.ts
Expand Up @@ -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 {
Expand All @@ -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"', {
Expand Down

0 comments on commit a8621c7

Please sign in to comment.