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
vercel#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
2 people authored and hydRAnger committed Jun 12, 2023
1 parent 7a9c122 commit f1a70f6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/create-next-app/helpers/git.ts
Original file line number Diff line number Diff line change
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 f1a70f6

Please sign in to comment.