Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 237d508

Browse files
vsavkinFrozenPandaz
authored andcommittedAug 18, 2020
fix(core): add a workaround for potential bugs in git hasher (#3521)
1 parent 61fc721 commit 237d508

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed
 

Diff for: ‎packages/workspace/src/core/hasher/git-hasher.ts

+35-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { spawnSync } from 'child_process';
2+
import { join } from 'path';
3+
import { statSync } from 'fs';
24

35
function parseGitLsTree(output: string): Map<string, string> {
46
const changes: Map<string, string> = new Map<string, string>();
@@ -102,8 +104,39 @@ function gitStatus(
102104
deletedFiles.push(filename);
103105
}
104106
});
105-
const status = getGitHashForFiles(filesToHash, path);
106-
return { deletedFiles, status };
107+
108+
const updated = checkForDeletedFiles(path, filesToHash, deletedFiles);
109+
const status = getGitHashForFiles(updated.filesToHash, path);
110+
return { deletedFiles: updated.deletedFiles, status };
111+
}
112+
113+
/**
114+
* This is only needed because of potential issues with interpreting "git status".
115+
* We had a few issues where we didn't interpret renames correctly. Even though
116+
* doing this somewhat slow, we will keep it for now.
117+
*
118+
* @vsavkin remove it in nx 10.2
119+
*/
120+
function checkForDeletedFiles(
121+
path: string,
122+
files: string[],
123+
deletedFiles: string[]
124+
) {
125+
let filesToHash = [];
126+
127+
files.forEach((f) => {
128+
try {
129+
statSync(join(path, f)).isFile();
130+
filesToHash.push(f);
131+
} catch (err) {
132+
console.warn(
133+
`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.`
134+
);
135+
deletedFiles.push(f);
136+
}
137+
});
138+
139+
return { filesToHash, deletedFiles };
107140
}
108141

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

0 commit comments

Comments
 (0)
Please sign in to comment.