fix(core): git hasher should handle unstaged files with spaces
This commit is contained in:
parent
e9393805c1
commit
cb15498d83
@ -78,7 +78,28 @@ describe('git-hasher', () => {
|
|||||||
run(`echo AAA > "a b".txt`);
|
run(`echo AAA > "a b".txt`);
|
||||||
run(`git add .`);
|
run(`git add .`);
|
||||||
run(`git commit -am init`);
|
run(`git commit -am init`);
|
||||||
expect([...getFileHashes(dir).keys()]).toEqual([`${dir}/a b.txt`]);
|
run(`touch "x y z.txt"`); // unstaged
|
||||||
|
expect([...getFileHashes(dir).keys()]).toEqual([
|
||||||
|
`${dir}/a b.txt`,
|
||||||
|
`${dir}/x y z.txt`,
|
||||||
|
]);
|
||||||
|
run(`git add .`);
|
||||||
|
expect([...getFileHashes(dir).keys()]).toEqual([
|
||||||
|
`${dir}/a b.txt`,
|
||||||
|
`${dir}/x y z.txt`,
|
||||||
|
]);
|
||||||
|
run(`mv "a b.txt" "a b moved.txt"`);
|
||||||
|
expect([...getFileHashes(dir).keys()]).toEqual([
|
||||||
|
`${dir}/x y z.txt`,
|
||||||
|
`${dir}/a b moved.txt`,
|
||||||
|
]);
|
||||||
|
run(`git add .`);
|
||||||
|
expect([...getFileHashes(dir).keys()]).toEqual([
|
||||||
|
`${dir}/a b moved.txt`,
|
||||||
|
`${dir}/x y z.txt`,
|
||||||
|
]);
|
||||||
|
run(`rm "x y z.txt"`);
|
||||||
|
expect([...getFileHashes(dir).keys()]).toEqual([`${dir}/a b moved.txt`]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle renames and modifications', () => {
|
it('should handle renames and modifications', () => {
|
||||||
|
|||||||
@ -36,6 +36,7 @@ function parseGitStatus(output: string): Map<string, string> {
|
|||||||
.match(/(?:[^\s"]+|"[^"]*")+/g)
|
.match(/(?:[^\s"]+|"[^"]*")+/g)
|
||||||
.map((r) => (r.startsWith('"') ? r.substring(1, r.length - 1) : r))
|
.map((r) => (r.startsWith('"') ? r.substring(1, r.length - 1) : r))
|
||||||
.filter((r) => !!r);
|
.filter((r) => !!r);
|
||||||
|
|
||||||
if (changeType && filenames && filenames.length > 0) {
|
if (changeType && filenames && filenames.length > 0) {
|
||||||
// the before filename we mark as deleted, so we remove it from the map
|
// the before filename we mark as deleted, so we remove it from the map
|
||||||
// changeType can be A/D/R/RM etc
|
// changeType can be A/D/R/RM etc
|
||||||
@ -43,8 +44,12 @@ function parseGitStatus(output: string): Map<string, string> {
|
|||||||
// the before part gets marked as deleted
|
// the before part gets marked as deleted
|
||||||
if (changeType[0] === 'R') {
|
if (changeType[0] === 'R') {
|
||||||
changes.set(filenames[0], 'D');
|
changes.set(filenames[0], 'D');
|
||||||
}
|
|
||||||
changes.set(filenames[filenames.length - 1], changeType);
|
changes.set(filenames[filenames.length - 1], changeType);
|
||||||
|
} else if (changeType === '??') {
|
||||||
|
changes.set(filenames.join(' '), changeType);
|
||||||
|
} else {
|
||||||
|
changes.set(filenames[filenames.length - 1], changeType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return changes;
|
return changes;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user