提交 0fec2516 编写于 作者: T Tomas Vik

refactor: migrate getLastCommitSha to use the Git Extension

上级 dbe1de75
......@@ -87,6 +87,10 @@ export class WrappedRepository {
return this.getRemoteByName(pipelineGitRemoteName || this.remoteName);
}
get lastCommitSha(): string | undefined {
return this.rawRepository.state.HEAD?.commit;
}
get instanceUrl(): string {
const remoteUrls = this.rawRepository.state.remotes
.map(r => r.fetchUrl)
......
......@@ -59,17 +59,6 @@ describe('git_service', () => {
gitService = new GitService(getDefaultOptions());
});
describe('fetchLastCommitId', () => {
it('returns the last commit sha', async () => {
await git.commit('Test commit', [], { '--allow-empty': null });
const lastCommitSha = await git.revparse(['HEAD']);
const result = await gitService.fetchLastCommitId();
expect(result).toEqual(lastCommitSha);
});
});
describe('fetchTrackingBranchName', () => {
beforeEach(async () => {
await git.checkout(['-b', 'new-branch']);
......@@ -138,10 +127,6 @@ describe('git_service', () => {
gitService = new GitService(options);
});
it('fetchLastCommitId returns null', async () => {
expect(gitService.fetchLastCommitId()).rejects.toBeInstanceOf(Error);
});
it('fetchTrackingBranchName returns null', async () => {
expect(gitService.fetchTrackingBranchName()).rejects.toBeInstanceOf(Error);
});
......
......@@ -27,10 +27,6 @@ export class GitService {
return stdout;
}
async fetchLastCommitId(): Promise<string> {
return this.fetch('git log --format=%H -n 1');
}
/**
* Fetches remote tracking branch name of current branch.
* This should be used in link openers.
......
......@@ -140,9 +140,8 @@ export async function compareCurrentBranch(): Promise<void> {
if (!repository) return;
const project = await gitLabService.fetchCurrentProject(repository.rootFsPath);
const lastCommitId = await repository.gitService.fetchLastCommitId();
if (project && lastCommitId) {
openUrl(`${project.webUrl}/compare/master...${lastCommitId}`);
if (project && repository.lastCommitSha) {
openUrl(`${project.webUrl}/compare/master...${repository.lastCommitSha}`);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册