Skip to content

Commit

Permalink
fix(core): git hasher should handle file that are both renamed and mo…
Browse files Browse the repository at this point in the history
…dified
  • Loading branch information
JakubKoralewski authored and vsavkin committed Aug 13, 2020
1 parent 10911e2 commit f25e70f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/workspace/src/core/hasher/git-hasher.spec.ts
Expand Up @@ -81,6 +81,16 @@ describe('git-hasher', () => {
expect([...getFileHashes(dir).keys()]).toEqual([`${dir}/a b.txt`]);
});

it('should handle renames and modifications', () => {
run(`echo AAA > "a".txt`);
run(`git add .`);
run(`git commit -am init`);
run(`mv a.txt moda.txt`);
run(`git add .`);
run(`echo modified >> moda.txt`);
expect([...getFileHashes(dir).keys()]).toEqual([`${dir}/moda.txt`]);
});

function run(command: string) {
return execSync(command, { cwd: dir, stdio: ['pipe', 'pipe', 'pipe'] });
}
Expand Down
5 changes: 4 additions & 1 deletion packages/workspace/src/core/hasher/git-hasher.ts
Expand Up @@ -36,7 +36,10 @@ function parseGitStatus(output: string): Map<string, string> {
.filter((r) => !!r);
if (changeType && filenames && filenames.length > 0) {
// the before filename we mark as deleted, so we remove it from the map
if (changeType === 'R') {
// changeType can be A/D/R/RM etc
// if it R and RM, we need to split the output into before and after
// the before part gets marked as deleted
if (changeType[0] === 'R') {
changes.set(filenames[0], 'D');
}
changes.set(filenames[filenames.length - 1], changeType);
Expand Down

0 comments on commit f25e70f

Please sign in to comment.