Skip to content

Commit

Permalink
fix(core): add a workaround for potential bugs in git hasher (#3521)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin authored and FrozenPandaz committed Aug 18, 2020
1 parent 61fc721 commit 237d508
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions packages/workspace/src/core/hasher/git-hasher.ts
@@ -1,4 +1,6 @@
import { spawnSync } from 'child_process';
import { join } from 'path';
import { statSync } from 'fs';

function parseGitLsTree(output: string): Map<string, string> {
const changes: Map<string, string> = new Map<string, string>();
Expand Down Expand Up @@ -102,8 +104,39 @@ function gitStatus(
deletedFiles.push(filename);
}
});
const status = getGitHashForFiles(filesToHash, path);
return { deletedFiles, status };

const updated = checkForDeletedFiles(path, filesToHash, deletedFiles);
const status = getGitHashForFiles(updated.filesToHash, path);
return { deletedFiles: updated.deletedFiles, status };
}

/**
* This is only needed because of potential issues with interpreting "git status".
* We had a few issues where we didn't interpret renames correctly. Even though
* doing this somewhat slow, we will keep it for now.
*
* @vsavkin remove it in nx 10.2
*/
function checkForDeletedFiles(
path: string,
files: string[],
deletedFiles: string[]
) {
let filesToHash = [];

files.forEach((f) => {
try {
statSync(join(path, f)).isFile();
filesToHash.push(f);
} catch (err) {
console.warn(
`Warning: Fell back to using 'fs' to identify ${f} as deleted. Please open an issue at https://github.com/nrwl/nx so we can investigate.`
);
deletedFiles.push(f);
}
});

return { filesToHash, deletedFiles };
}

export function getFileHashes(path: string): Map<string, string> {
Expand Down

0 comments on commit 237d508

Please sign in to comment.