Skip to content

Commit

Permalink
fix(core): handle file renames properly for affected (#15340)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7aac67c)
  • Loading branch information
FrozenPandaz committed Mar 10, 2023
1 parent fc2ea3c commit ff3abff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 18 additions & 1 deletion e2e/nx-run/src/affected-graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
newProject,
readFile,
readJson,
readProjectConfig,
cleanupProject,
runCLI,
runCLIAsync,
Expand Down Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/utils/command-line-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 .`);
}

``;
Expand All @@ -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}"`
);
}

Expand Down

0 comments on commit ff3abff

Please sign in to comment.