Skip to content

Commit 71cebe8

Browse files
committed
Fixing an issue where package-deps-hash didn't correctly handle staged renames.
1 parent 4ff66b7 commit 71cebe8

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

‎libraries/package-deps-hash/src/getPackageDeps.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,24 @@ export function parseGitStatus(output: string, packagePath: string): Map<string,
6363
.trim()
6464
.split('\n')
6565
.forEach(line => {
66-
const [changeType, filename]: string[] = line.trim().split(' ');
6766
/*
68-
* changeType == 'D' or 'M' or 'A'
69-
* filename == path to the file
67+
* changeType is in the format of "XY" where "X" is the status of the file in the index and "Y" is the status of
68+
* the file in the working tree. Some example statuses:
69+
* - 'D' == deletion
70+
* - 'M' == modification
71+
* - 'A' == addition
72+
* - '??' == untracked
73+
* - 'R' == rename
74+
* - 'RM' == rename with modifications
75+
* filenames == path to the file, or files in the case of files that have been renamed
7076
*/
71-
if (changeType && filename) {
72-
changes.set(filename, changeType as GitStatusChangeType);
77+
const [changeType, ...filenames]: string[] = line.trim().split(' ').filter((linePart) => !!linePart);
78+
79+
if (changeType && filenames && filenames.length > 0) {
80+
// We always care about the last filename in the filenames array. In the case of non-rename changes,
81+
// the filenames array only contains one item. In the case of rename changes, the last item in the
82+
// array is the path to the file in the working tree, which is the only one that we care about.
83+
changes.set(filenames[filenames.length - 1], changeType as GitStatusChangeType);
7384
}
7485
});
7586

0 commit comments

Comments
 (0)