From b0ee13ec72a97005aa38b2ab42ab78a542d128c9 Mon Sep 17 00:00:00 2001 From: Emily Xiong Date: Mon, 11 Nov 2024 14:21:15 -0500 Subject: [PATCH] fix(core): set default branch to main if no git --- .../nx/src/command-line/init/implementation/utils.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/nx/src/command-line/init/implementation/utils.ts b/packages/nx/src/command-line/init/implementation/utils.ts index 59ae88b52bcf0..50bcfabe42232 100644 --- a/packages/nx/src/command-line/init/implementation/utils.ts +++ b/packages/nx/src/command-line/init/implementation/utils.ts @@ -19,6 +19,7 @@ import { existsSync, readFileSync, writeFileSync } from 'fs'; import { printSuccessMessage } from '../../../nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud'; import { repoUsesGithub } from '../../../nx-cloud/utilities/url-shorten'; import { connectWorkspaceToCloud } from '../../connect/connect-to-nx-cloud'; +import { deduceDefaultBase as gitInitDefaultBase } from '../../../utils/default-base'; export function createNxJsonFile( repoRoot: string, @@ -93,7 +94,15 @@ function deduceDefaultBase() { }); return 'next'; } catch { - return 'master'; + try { + execSync(`git rev-parse --verify master`, { + stdio: ['ignore', 'ignore', 'ignore'], + windowsHide: false, + }); + return 'master'; + } catch { + return gitInitDefaultBase(); + } } } }