From ff3abffb1333163363e9150c1ad691c158faaf33 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Wed, 1 Mar 2023 18:59:36 -0500 Subject: [PATCH] fix(core): handle file renames properly for affected (#15340) (cherry picked from commit 7aac67c7833c82b129024204aa0f8c8b52beb62a) --- e2e/nx-run/src/affected-graph.test.ts | 19 ++++++++++++++++++- packages/nx/src/utils/command-line-utils.ts | 4 ++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/e2e/nx-run/src/affected-graph.test.ts b/e2e/nx-run/src/affected-graph.test.ts index 72bb99282201f..a1192fcb197be 100644 --- a/e2e/nx-run/src/affected-graph.test.ts +++ b/e2e/nx-run/src/affected-graph.test.ts @@ -5,7 +5,6 @@ import { newProject, readFile, readJson, - readProjectConfig, cleanupProject, runCLI, runCLIAsync, @@ -258,6 +257,24 @@ describe('Nx Affected and Graph Tests', () => { expect(runCLI('affected:apps')).toContain(myapp2); expect(runCLI('affected:libs')).not.toContain(mylib); }); + + it('should handle file renames', () => { + generateAll(); + + // Move file + updateFile( + `apps/${myapp2}/src/index.html`, + readFile(`apps/${myapp}/src/index.html`) + ); + removeFile(`apps/${myapp}/src/index.html`); + + const affectedProjects = runCLI( + 'print-affected --uncommitted --select projects' + ).split(', '); + + expect(affectedProjects).toContain(myapp); + expect(affectedProjects).toContain(myapp2); + }); }); describe('print-affected', () => { diff --git a/packages/nx/src/utils/command-line-utils.ts b/packages/nx/src/utils/command-line-utils.ts index 565f92353ed74..e4bec021010eb 100644 --- a/packages/nx/src/utils/command-line-utils.ts +++ b/packages/nx/src/utils/command-line-utils.ts @@ -353,7 +353,7 @@ export function parseFiles(options: NxArgs): { files: string[] } { } function getUncommittedFiles(): string[] { - return parseGitOutput(`git diff --name-only --relative HEAD .`); + return parseGitOutput(`git diff --name-only --no-renames --relative HEAD .`); } ``; @@ -378,7 +378,7 @@ function getFilesUsingBaseAndHead(base: string, head: string): string[] { .trim(); } return parseGitOutput( - `git diff --name-only --relative "${mergeBase}" "${head}"` + `git diff --name-only --no-renames --relative "${mergeBase}" "${head}"` ); }