diff --git a/CHANGELOG.md b/CHANGELOG.md index 36a0f3f..837eb4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the "simply-blame" extension will be documented in this file. +## [1.10.2] + ### Update + - Fix open file and file path with spaces + ## [1.10.1] ### Update - Fix editor manager try open unopend editor issue diff --git a/src/Git.ts b/src/Git.ts index f50873f..f07ed73 100644 --- a/src/Git.ts +++ b/src/Git.ts @@ -23,7 +23,7 @@ export const blameFile = async (fileName: string): Promise => { const location = fileName.replace(name, ''); try { - return await command(`cd ${location} && git blame --porcelain ${name}`) ?? ''; + return await command(`cd "${location}" && git blame --porcelain "${name}"`) ?? ''; } catch (e) { if ((e as Error).message.match(/no such path .* in HEAD/)) { vscode.window.showWarningMessage(`File: ${name} is not in HEAD`); diff --git a/src/test/suite/Git.test.ts b/src/test/suite/Git.test.ts index 3a078c0..ff9607f 100644 --- a/src/test/suite/Git.test.ts +++ b/src/test/suite/Git.test.ts @@ -100,18 +100,36 @@ Maybe this commit message is long and descriptive enough to prove a point. test('test blameFile slash succeeds', async () => { await blameFile('path/to/file/test.ts'); - sinon.assert.calledWithExactly(commandStub, `cd path/to/file/ && git blame --porcelain test.ts`); + sinon.assert.calledWithExactly(commandStub, `cd \"path/to/file/\" && git blame --porcelain \"test.ts\"`); }); test('test blameFile backslash succeeds', async () => { await blameFile('path\\to\\file\\test.ts'); - sinon.assert.calledWithExactly(commandStub, 'cd path\\to\\file\\ && git blame --porcelain test.ts'); + sinon.assert.calledWithExactly(commandStub, 'cd \"path\\to\\file\\\" && git blame --porcelain \"test.ts\"'); }); test('test blameFile filename with dash succeeds', async () => { await blameFile('path/to/file/test-this.txt'); - sinon.assert.calledWithExactly(commandStub, `cd path/to/file/ && git blame --porcelain test-this.txt`); + sinon.assert.calledWithExactly(commandStub, `cd \"path/to/file/\" && git blame --porcelain \"test-this.txt\"`); + }); + + test('test blameFile filename with space succeeds', async () => { + await blameFile('path/to/file/test this.txt'); + + sinon.assert.calledWithExactly(commandStub, `cd \"path/to/file/\" && git blame --porcelain \"test this.txt\"`); + }); + + test('test blameFile path with space succeeds', async () => { + await blameFile('path/to my files/test.txt'); + + sinon.assert.calledWithExactly(commandStub, `cd \"path/to my files/\" && git blame --porcelain \"test.txt\"`); + }); + + test('test blameFile path and filename with space succeeds', async () => { + await blameFile('path/to my files/test this.txt'); + + sinon.assert.calledWithExactly(commandStub, `cd \"path/to my files/\" && git blame --porcelain \"test this.txt\"`); }); });