Skip to content

Commit

Permalink
fix(core): set default branch to main if no git (#28854)
Browse files Browse the repository at this point in the history
<!-- 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 #
  • Loading branch information
xiongemi authored Nov 12, 2024
1 parent 048f7c6 commit 2d77495
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/nx/src/command-line/init/implementation/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}
}
}
}
Expand Down

0 comments on commit 2d77495

Please sign in to comment.