Skip to content

Commit e8266e2

Browse files
xiongemiFrozenPandaz
authored andcommitted
fix(core): set default branch to main if no git (#28854)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # (cherry picked from commit 2d77495)
1 parent b87865d commit e8266e2

File tree

1 file changed

+10
-1
lines changed
  • packages/nx/src/command-line/init/implementation

1 file changed

+10
-1
lines changed

packages/nx/src/command-line/init/implementation/utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { existsSync, readFileSync, writeFileSync } from 'fs';
1919
import { printSuccessMessage } from '../../../nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud';
2020
import { repoUsesGithub } from '../../../nx-cloud/utilities/url-shorten';
2121
import { connectWorkspaceToCloud } from '../../connect/connect-to-nx-cloud';
22+
import { deduceDefaultBase as gitInitDefaultBase } from '../../../utils/default-base';
2223

2324
export function createNxJsonFile(
2425
repoRoot: string,
@@ -93,7 +94,15 @@ function deduceDefaultBase() {
9394
});
9495
return 'next';
9596
} catch {
96-
return 'master';
97+
try {
98+
execSync(`git rev-parse --verify master`, {
99+
stdio: ['ignore', 'ignore', 'ignore'],
100+
windowsHide: false,
101+
});
102+
return 'master';
103+
} catch {
104+
return gitInitDefaultBase();
105+
}
97106
}
98107
}
99108
}

0 commit comments

Comments
 (0)