diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index dc4829808b4ed1cba1c5a0e36e4f3c7e10ae9140..b2c111a46fe893a7e87503c3211982c01c9454ff 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -481,6 +481,7 @@ export class Git { export interface Commit { hash: string; message: string; + previousHashes: string[]; } export class GitStatusParser { @@ -1287,14 +1288,14 @@ export class Repository { } async getCommit(ref: string): Promise { - const result = await this.run(['show', '-s', '--format=%H\n%B', ref]); - const match = /^([0-9a-f]{40})\n([^]*)$/m.exec(result.stdout.trim()); + const result = await this.run(['show', '-s', '--format=%H\n%P\n%B', ref]); + const match = /^([0-9a-f]{40})\n(.*)\n([^]*)$/m.exec(result.stdout.trim()); if (!match) { return Promise.reject('bad commit format'); } - return { hash: match[1], message: match[2] }; + return { hash: match[1], message: match[3], previousHashes: [match[2]] }; } async updateSubmodules(paths: string[]): Promise { diff --git a/extensions/git/src/test/git.test.ts b/extensions/git/src/test/git.test.ts index 39c9f0a7e9fc17012d509ef2daf149998597d9b7..af4a24c349bf00feb7e7217f6e717fdbbbc5b3fa 100644 --- a/extensions/git/src/test/git.test.ts +++ b/extensions/git/src/test/git.test.ts @@ -181,16 +181,18 @@ suite('git', () => { test('get commit', async () => { const spawnOption = {}; const gitOutput = `52c293a05038d865604c2284aa8698bd087915a1 +8e5a374372b8393906c7e380dbb09349c5385554 This is a commit message.`; const git = sinon.createStubInstance(Git); git.exec = sinon.stub() - .withArgs('REPOSITORY_ROOT', ['show', '-s', '--format=%H\n%B', 'REF'], spawnOption) + .withArgs('REPOSITORY_ROOT', ['show', '-s', '--format=%H\n%P\n%B', 'REF_SINGLE_PARENT'], spawnOption) .returns(Promise.resolve({stdout: gitOutput})); const repository = new Repository(git, 'REPOSITORY_ROOT'); - assert.deepEqual(await repository.getCommit('REF'), { + assert.deepEqual(await repository.getCommit('REF_SINGLE_PARENT'), { hash: '52c293a05038d865604c2284aa8698bd087915a1', - message: 'This is a commit message.' + message: 'This is a commit message.', + previousHashes: ['8e5a374372b8393906c7e380dbb09349c5385554'] }); }); });