Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): handle file renames properly for affected #15340

Merged
merged 1 commit into from Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions e2e/nx-run/src/affected-graph.test.ts
Expand Up @@ -180,8 +180,6 @@ describe('Nx Affected and Graph Tests', () => {
mylib = uniq('mylib');
const nxJson: NxJsonConfiguration = readJson('nx.json');

delete nxJson.implicitDependencies;

updateFile('nx.json', JSON.stringify(nxJson));
runCommand(`git init`);
runCommand(`git config user.email "test@test.com"`);
Expand Down Expand Up @@ -266,6 +264,24 @@ describe('Nx Affected and Graph Tests', () => {
implicitDependencies: [],
}));
});

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
Expand Up @@ -222,7 +222,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 @@ -249,7 +249,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