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

refactor: migrate getLastCommitSha to use the Git Extension

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