From 1ab5cab7cdd6e6dea6101f6df25eebc94457ba89 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Wed, 31 Jul 2024 13:24:16 -0500 Subject: [PATCH] fix(misc): hide git not a repository error (#27237) ## Current Behavior There's an error that leaks through during `create-nx-workspace`. ## Expected Behavior The error is ok and it is hidden during `create-nx-workspace`. ## Related Issue(s) Fixes # (cherry picked from commit 2160cd974dec435777e3bd7bb231dbe7bcff0d45) --- packages/nx/src/utils/git-utils.spec.ts | 12 ++++++------ packages/nx/src/utils/git-utils.ts | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/nx/src/utils/git-utils.spec.ts b/packages/nx/src/utils/git-utils.spec.ts index af51f95e2813b..67bc43ad2b2fd 100644 --- a/packages/nx/src/utils/git-utils.spec.ts +++ b/packages/nx/src/utils/git-utils.spec.ts @@ -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', () => { @@ -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', () => { @@ -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', () => { @@ -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', () => { @@ -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', () => { @@ -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' }); }); }); diff --git a/packages/nx/src/utils/git-utils.ts b/packages/nx/src/utils/git-utils.ts index 6e76c56a428b6..9b2a2cc3e6196 100644 --- a/packages/nx/src/utils/git-utils.ts +++ b/packages/nx/src/utils/git-utils.ts @@ -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';