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 ed5f3a6

Browse files
vsavkinFrozenPandaz
authored andcommittedSep 11, 2020
fix(core): git hasher should handle unstaged files with spaces
1 parent 46454aa commit ed5f3a6

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed
 

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,28 @@ describe('git-hasher', () => {
7878
run(`echo AAA > "a b".txt`);
7979
run(`git add .`);
8080
run(`git commit -am init`);
81-
expect([...getFileHashes(dir).keys()]).toEqual([`${dir}/a b.txt`]);
81+
run(`touch "x y z.txt"`); // unstaged
82+
expect([...getFileHashes(dir).keys()]).toEqual([
83+
`${dir}/a b.txt`,
84+
`${dir}/x y z.txt`,
85+
]);
86+
run(`git add .`);
87+
expect([...getFileHashes(dir).keys()]).toEqual([
88+
`${dir}/a b.txt`,
89+
`${dir}/x y z.txt`,
90+
]);
91+
run(`mv "a b.txt" "a b moved.txt"`);
92+
expect([...getFileHashes(dir).keys()]).toEqual([
93+
`${dir}/x y z.txt`,
94+
`${dir}/a b moved.txt`,
95+
]);
96+
run(`git add .`);
97+
expect([...getFileHashes(dir).keys()]).toEqual([
98+
`${dir}/a b moved.txt`,
99+
`${dir}/x y z.txt`,
100+
]);
101+
run(`rm "x y z.txt"`);
102+
expect([...getFileHashes(dir).keys()]).toEqual([`${dir}/a b moved.txt`]);
82103
});
83104

84105
it('should handle renames and modifications', () => {

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,20 @@ function parseGitStatus(output: string): Map<string, string> {
3636
.match(/(?:[^\s"]+|"[^"]*")+/g)
3737
.map((r) => (r.startsWith('"') ? r.substring(1, r.length - 1) : r))
3838
.filter((r) => !!r);
39+
3940
if (changeType && filenames && filenames.length > 0) {
4041
// the before filename we mark as deleted, so we remove it from the map
4142
// changeType can be A/D/R/RM etc
4243
// if it R and RM, we need to split the output into before and after
4344
// the before part gets marked as deleted
4445
if (changeType[0] === 'R') {
4546
changes.set(filenames[0], 'D');
47+
changes.set(filenames[filenames.length - 1], changeType);
48+
} else if (changeType === '??') {
49+
changes.set(filenames.join(' '), changeType);
50+
} else {
51+
changes.set(filenames[filenames.length - 1], changeType);
4652
}
47-
changes.set(filenames[filenames.length - 1], changeType);
4853
}
4954
});
5055
return changes;

0 commit comments

Comments
 (0)
Please sign in to comment.