提交 3fdf0bcc 编写于 作者: R Ryuichi Inagaki

ref #44776 Get previous commits as part of commit info

上级 d562ebbf
......@@ -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<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> {
......
......@@ -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']
});
});
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册