|
1 | 1 | import { spawnSync } from 'child_process';
|
| 2 | +import { join } from 'path'; |
| 3 | +import { statSync } from 'fs'; |
2 | 4 |
|
3 | 5 | function parseGitLsTree(output: string): Map<string, string> {
|
4 | 6 | const changes: Map<string, string> = new Map<string, string>();
|
@@ -102,8 +104,39 @@ function gitStatus(
|
102 | 104 | deletedFiles.push(filename);
|
103 | 105 | }
|
104 | 106 | });
|
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 }; |
107 | 140 | }
|
108 | 141 |
|
109 | 142 | export function getFileHashes(path: string): Map<string, string> {
|
|
0 commit comments