Skip to content

Commit

Permalink
ref microsoft#44776 Get previous commits as part of commit info
Browse files Browse the repository at this point in the history
  • Loading branch information
ryu1kn committed Apr 10, 2018
1 parent d562ebb commit 3fdf0bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions extensions/git/src/git.ts
Expand Up @@ -481,6 +481,7 @@ export class Git {
export interface Commit {
hash: string;
message: string;
previousHashes: string[];
}

export class GitStatusParser {
Expand Down Expand Up @@ -1287,14 +1288,14 @@ export class Repository {
}

async getCommit(ref: string): Promise<Commit> {
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<Commit>('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<void> {
Expand Down
8 changes: 5 additions & 3 deletions extensions/git/src/test/git.test.ts
Expand Up @@ -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']
});
});
});
Expand Down

0 comments on commit 3fdf0bc

Please sign in to comment.