From a8621c7bb2f913ab378825f9b65e562be0b35974 Mon Sep 17 00:00:00 2001 From: Abhishek Kadam Date: Sun, 21 May 2023 05:23:58 +0530 Subject: [PATCH] =?UTF-8?q?[create-next-app]:=20respecting=20the=20user's?= =?UTF-8?q?=20`init.defaultBranch`=20git=20con=E2=80=A6=20(#49960)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 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> --- packages/create-next-app/helpers/git.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/create-next-app/helpers/git.ts b/packages/create-next-app/helpers/git.ts index 965c8b6086..79eb9115a1 100644 --- a/packages/create-next-app/helpers/git.ts +++ b/packages/create-next-app/helpers/git.ts @@ -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"', {