Skip to content

Commit

Permalink
fix(core): git hasher identifies deleted files
Browse files Browse the repository at this point in the history
Closes nrwl#4201
  • Loading branch information
bekos authored and vsavkin committed Mar 16, 2021
1 parent 6909926 commit 4f95d4e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/workspace/src/core/hasher/git-hasher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import { getFileHashes } from './git-hasher';

describe('git-hasher', () => {
let dir;
const warnSpy = jest.spyOn(console, 'warn');

beforeEach(() => {
dir = dirSync().name;
run(`git init`);
run(`git config user.email "[email protected]"`);
run(`git config user.name "test"`);

warnSpy.mockClear();
});

afterEach(() => {
expect(console.warn).not.toHaveBeenCalled();
removeSync(dir);
});

Expand Down
13 changes: 9 additions & 4 deletions packages/workspace/src/core/hasher/git-hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ function parseGitStatus(output: string): Map<string, string> {
for (let i = 0; i < chunks.length; i++) {
const chunk = chunks[i];
if (chunk.length) {
const change = chunk[0];
if (change === 'R') {
// The XY is the two-letter status code.
// See: https://git-scm.com/docs/git-status#_short_format
const X = chunk[0].trim();
const Y = chunk[1].trim();
const filename = chunk.substring(3);
if (X === 'R') {
changes.set(chunks[++i], 'D');
}
changes.set(chunk.substring(2).trim(), change);
// If both present, Y shows the status of the working tree
changes.set(filename, Y || X);
}
}
return changes;
Expand All @@ -49,7 +54,7 @@ function spawnProcess(command: string, args: string[], cwd: string): string {
`Failed to run ${command} ${args.join(' ')}.\n${r.stdout}\n${r.stderr}`
);
}
return r.stdout.toString().trim();
return r.stdout.toString().trimEnd();
}

function getGitHashForFiles(
Expand Down

0 comments on commit 4f95d4e

Please sign in to comment.