Skip to content

Commit 7c52312

Browse files
authored
Merge pull request #118 from JamiLu/fix-fileopen
Fix open files with spaces File path and filename were not escaped with quote signs which then led failing to open files with spaces. The sames issue could have aroused for filenames with spacial characters as well. This fix the escaping of the path name and the filename fixes this issue and files are opened correctly. The filename with spaces would be interpreted as separated files if the filename was not escaped which is not wanted behavior
2 parents 884307f + 5153a89 commit 7c52312

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to the "simply-blame" extension will be documented in this file.
44

5+
## [1.10.2]
6+
### Update
7+
- Fix open file and file path with spaces
8+
59
## [1.10.1]
610
### Update
711
- Fix editor manager try open unopend editor issue

src/Git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const blameFile = async (fileName: string): Promise<string> => {
2323
const location = fileName.replace(name, '');
2424

2525
try {
26-
return await command(`cd ${location} && git blame --porcelain ${name}`) ?? '';
26+
return await command(`cd "${location}" && git blame --porcelain "${name}"`) ?? '';
2727
} catch (e) {
2828
if ((e as Error).message.match(/no such path .* in HEAD/)) {
2929
vscode.window.showWarningMessage(`File: ${name} is not in HEAD`);

src/test/suite/Git.test.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,36 @@ Maybe this commit message is long and descriptive enough to prove a point.
100100
test('test blameFile slash succeeds', async () => {
101101
await blameFile('path/to/file/test.ts');
102102

103-
sinon.assert.calledWithExactly(commandStub, `cd path/to/file/ && git blame --porcelain test.ts`);
103+
sinon.assert.calledWithExactly(commandStub, `cd \"path/to/file/\" && git blame --porcelain \"test.ts\"`);
104104
});
105105

106106
test('test blameFile backslash succeeds', async () => {
107107
await blameFile('path\\to\\file\\test.ts');
108108

109-
sinon.assert.calledWithExactly(commandStub, 'cd path\\to\\file\\ && git blame --porcelain test.ts');
109+
sinon.assert.calledWithExactly(commandStub, 'cd \"path\\to\\file\\\" && git blame --porcelain \"test.ts\"');
110110
});
111111

112112
test('test blameFile filename with dash succeeds', async () => {
113113
await blameFile('path/to/file/test-this.txt');
114114

115-
sinon.assert.calledWithExactly(commandStub, `cd path/to/file/ && git blame --porcelain test-this.txt`);
115+
sinon.assert.calledWithExactly(commandStub, `cd \"path/to/file/\" && git blame --porcelain \"test-this.txt\"`);
116+
});
117+
118+
test('test blameFile filename with space succeeds', async () => {
119+
await blameFile('path/to/file/test this.txt');
120+
121+
sinon.assert.calledWithExactly(commandStub, `cd \"path/to/file/\" && git blame --porcelain \"test this.txt\"`);
122+
});
123+
124+
test('test blameFile path with space succeeds', async () => {
125+
await blameFile('path/to my files/test.txt');
126+
127+
sinon.assert.calledWithExactly(commandStub, `cd \"path/to my files/\" && git blame --porcelain \"test.txt\"`);
128+
});
129+
130+
test('test blameFile path and filename with space succeeds', async () => {
131+
await blameFile('path/to my files/test this.txt');
132+
133+
sinon.assert.calledWithExactly(commandStub, `cd \"path/to my files/\" && git blame --porcelain \"test this.txt\"`);
116134
});
117135
});

0 commit comments

Comments
 (0)