Skip to content

Commit f111580

Browse files
committed
fix(core): handle file renames properly for affected (#15340)
(cherry picked from commit 7aac67c)
1 parent bf9844e commit f111580

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

e2e/nx-run/src/affected-graph.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ describe('Nx Affected and Graph Tests', () => {
180180
mylib = uniq('mylib');
181181
const nxJson: NxJsonConfiguration = readJson('nx.json');
182182

183-
delete nxJson.implicitDependencies;
184-
185183
updateFile('nx.json', JSON.stringify(nxJson));
186184
runCommand(`git init`);
187185
runCommand(`git config user.email "test@test.com"`);
@@ -266,6 +264,24 @@ describe('Nx Affected and Graph Tests', () => {
266264
implicitDependencies: [],
267265
}));
268266
});
267+
268+
it('should handle file renames', () => {
269+
generateAll();
270+
271+
// Move file
272+
updateFile(
273+
`apps/${myapp2}/src/index.html`,
274+
readFile(`apps/${myapp}/src/index.html`)
275+
);
276+
removeFile(`apps/${myapp}/src/index.html`);
277+
278+
const affectedProjects = runCLI(
279+
'print-affected --uncommitted --select projects'
280+
).split(', ');
281+
282+
expect(affectedProjects).toContain(myapp);
283+
expect(affectedProjects).toContain(myapp2);
284+
});
269285
});
270286

271287
describe('print-affected', () => {

packages/nx/src/utils/command-line-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export function parseFiles(options: NxArgs): { files: string[] } {
222222
}
223223

224224
function getUncommittedFiles(): string[] {
225-
return parseGitOutput(`git diff --name-only --relative HEAD .`);
225+
return parseGitOutput(`git diff --name-only --no-renames --relative HEAD .`);
226226
}
227227

228228
``;
@@ -249,7 +249,7 @@ function getFilesUsingBaseAndHead(base: string, head: string): string[] {
249249
.trim();
250250
}
251251
return parseGitOutput(
252-
`git diff --name-only --relative "${mergeBase}" "${head}"`
252+
`git diff --name-only --no-renames --relative "${mergeBase}" "${head}"`
253253
);
254254
}
255255

0 commit comments

Comments
 (0)