Skip to content

Commit

Permalink
fix(core): handle file renames properly for affected
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Mar 1, 2023
1 parent b7ef261 commit bec66b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 19 additions & 3 deletions e2e/nx-run/src/affected-graph.test.ts
Expand Up @@ -174,14 +174,12 @@ describe('Nx Affected and Graph Tests', () => {
let myapp2;
let mylib;

beforeEach(() => {
beforeAll(() => {
myapp = uniq('myapp');
myapp2 = uniq('myapp');
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

0 comments on commit bec66b3

Please sign in to comment.