Skip to content

Commit 3fdf0bc

Browse files
committed
ref microsoft#44776 Get previous commits as part of commit info
1 parent d562ebb commit 3fdf0bc

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

extensions/git/src/git.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ export class Git {
481481
export interface Commit {
482482
hash: string;
483483
message: string;
484+
previousHashes: string[];
484485
}
485486

486487
export class GitStatusParser {
@@ -1287,14 +1288,14 @@ export class Repository {
12871288
}
12881289

12891290
async getCommit(ref: string): Promise<Commit> {
1290-
const result = await this.run(['show', '-s', '--format=%H\n%B', ref]);
1291-
const match = /^([0-9a-f]{40})\n([^]*)$/m.exec(result.stdout.trim());
1291+
const result = await this.run(['show', '-s', '--format=%H\n%P\n%B', ref]);
1292+
const match = /^([0-9a-f]{40})\n(.*)\n([^]*)$/m.exec(result.stdout.trim());
12921293

12931294
if (!match) {
12941295
return Promise.reject<Commit>('bad commit format');
12951296
}
12961297

1297-
return { hash: match[1], message: match[2] };
1298+
return { hash: match[1], message: match[3], previousHashes: [match[2]] };
12981299
}
12991300

13001301
async updateSubmodules(paths: string[]): Promise<void> {

extensions/git/src/test/git.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,18 @@ suite('git', () => {
181181
test('get commit', async () => {
182182
const spawnOption = {};
183183
const gitOutput = `52c293a05038d865604c2284aa8698bd087915a1
184+
8e5a374372b8393906c7e380dbb09349c5385554
184185
This is a commit message.`;
185186
const git = sinon.createStubInstance(Git);
186187
git.exec = sinon.stub()
187-
.withArgs('REPOSITORY_ROOT', ['show', '-s', '--format=%H\n%B', 'REF'], spawnOption)
188+
.withArgs('REPOSITORY_ROOT', ['show', '-s', '--format=%H\n%P\n%B', 'REF_SINGLE_PARENT'], spawnOption)
188189
.returns(Promise.resolve({stdout: gitOutput}));
189190
const repository = new Repository(git, 'REPOSITORY_ROOT');
190191

191-
assert.deepEqual(await repository.getCommit('REF'), {
192+
assert.deepEqual(await repository.getCommit('REF_SINGLE_PARENT'), {
192193
hash: '52c293a05038d865604c2284aa8698bd087915a1',
193-
message: 'This is a commit message.'
194+
message: 'This is a commit message.',
195+
previousHashes: ['8e5a374372b8393906c7e380dbb09349c5385554']
194196
});
195197
});
196198
});

0 commit comments

Comments
 (0)