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 be42a10

Browse files
JakubKoralewskiFrozenPandaz
authored andcommittedAug 18, 2020
fix(core): git hasher should handle file that are both renamed and modified
1 parent 5f637f8 commit be42a10

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
 

‎packages/workspace/src/core/hasher/git-hasher.spec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ describe('git-hasher', () => {
8181
expect([...getFileHashes(dir).keys()]).toEqual([`${dir}/a b.txt`]);
8282
});
8383

84+
it('should handle renames and modifications', () => {
85+
run(`echo AAA > "a".txt`);
86+
run(`git add .`);
87+
run(`git commit -am init`);
88+
run(`mv a.txt moda.txt`);
89+
run(`git add .`);
90+
run(`echo modified >> moda.txt`);
91+
expect([...getFileHashes(dir).keys()]).toEqual([`${dir}/moda.txt`]);
92+
});
93+
8494
function run(command: string) {
8595
return execSync(command, { cwd: dir, stdio: ['pipe', 'pipe', 'pipe'] });
8696
}

‎packages/workspace/src/core/hasher/git-hasher.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ function parseGitStatus(output: string): Map<string, string> {
3636
.filter((r) => !!r);
3737
if (changeType && filenames && filenames.length > 0) {
3838
// the before filename we mark as deleted, so we remove it from the map
39-
if (changeType === 'R') {
39+
// changeType can be A/D/R/RM etc
40+
// if it R and RM, we need to split the output into before and after
41+
// the before part gets marked as deleted
42+
if (changeType[0] === 'R') {
4043
changes.set(filenames[0], 'D');
4144
}
4245
changes.set(filenames[filenames.length - 1], changeType);

0 commit comments

Comments
 (0)
Please sign in to comment.