Skip to content

Commit

Permalink
fix(misc): hide git not a repository error (#27237)
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 -->

There's an error that leaks through during `create-nx-workspace`.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

The error is ok and it is hidden during `create-nx-workspace`.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #

(cherry picked from commit 2160cd9)
  • Loading branch information
FrozenPandaz committed Aug 1, 2024
1 parent 2770ec5 commit 1ab5cab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions packages/nx/src/utils/git-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('git utils tests', () => {
const result = getGithubSlugOrNull();

expect(result).toBe('origin-user/repo-name');
expect(execSync).toHaveBeenCalledWith('git remote -v');
expect(execSync).toHaveBeenCalledWith('git remote -v', { stdio: 'pipe' });
});

it('should return "github" if there are no remotes', () => {
Expand All @@ -30,7 +30,7 @@ describe('git utils tests', () => {
const result = getGithubSlugOrNull();

expect(result).toBe('github');
expect(execSync).toHaveBeenCalledWith('git remote -v');
expect(execSync).toHaveBeenCalledWith('git remote -v', { stdio: 'pipe' });
});

it('should return "github" if execSync throws an error', () => {
Expand All @@ -41,7 +41,7 @@ describe('git utils tests', () => {
const result = getGithubSlugOrNull();

expect(result).toBe('github');
expect(execSync).toHaveBeenCalledWith('git remote -v');
expect(execSync).toHaveBeenCalledWith('git remote -v', { stdio: 'pipe' });
});

it('should return the first github remote slug if no origin is present', () => {
Expand All @@ -53,7 +53,7 @@ describe('git utils tests', () => {
const result = getGithubSlugOrNull();

expect(result).toBe('upstream-user/repo-name');
expect(execSync).toHaveBeenCalledWith('git remote -v');
expect(execSync).toHaveBeenCalledWith('git remote -v', { stdio: 'pipe' });
});

it('should return null if remote is set up but not github', () => {
Expand All @@ -65,7 +65,7 @@ describe('git utils tests', () => {
const result = getGithubSlugOrNull();

expect(result).toBeNull();
expect(execSync).toHaveBeenCalledWith('git remote -v');
expect(execSync).toHaveBeenCalledWith('git remote -v', { stdio: 'pipe' });
});

it('should return the first github remote slug for HTTPS URLs', () => {
Expand All @@ -77,7 +77,7 @@ describe('git utils tests', () => {
const result = getGithubSlugOrNull();

expect(result).toBe('origin-user/repo-name');
expect(execSync).toHaveBeenCalledWith('git remote -v');
expect(execSync).toHaveBeenCalledWith('git remote -v', { stdio: 'pipe' });
});
});

Expand Down
4 changes: 3 additions & 1 deletion packages/nx/src/utils/git-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { logger } from '../devkit-exports';

export function getGithubSlugOrNull(): string | null {
try {
const gitRemote = execSync('git remote -v').toString();
const gitRemote = execSync('git remote -v', {
stdio: 'pipe',
}).toString();
// If there are no remotes, we default to github
if (!gitRemote || gitRemote.length === 0) {
return 'github';
Expand Down

0 comments on commit 1ab5cab

Please sign in to comment.