diff --git a/src/git/wrapped_repository.ts b/src/git/wrapped_repository.ts index 0eb179edd2781d0223feccd56fd01a035f8c6c62..c937450964ba228a3afecb4a6323461c59ef658b 100644 --- a/src/git/wrapped_repository.ts +++ b/src/git/wrapped_repository.ts @@ -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) diff --git a/src/git_service.test.ts b/src/git_service.test.ts index 3955180c3b6ba9b6db56faf1b6ee54e469f0b94c..340c36121dbb2744c79f32133702e72e306b47c2 100644 --- a/src/git_service.test.ts +++ b/src/git_service.test.ts @@ -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); }); diff --git a/src/git_service.ts b/src/git_service.ts index 7ae0b81ede3db9c5ea02165cfa8d5036b4bb6b87..8afcef199b5936913bf52d675471409364e837f0 100644 --- a/src/git_service.ts +++ b/src/git_service.ts @@ -27,10 +27,6 @@ export class GitService { return stdout; } - async fetchLastCommitId(): Promise { - return this.fetch('git log --format=%H -n 1'); - } - /** * Fetches remote tracking branch name of current branch. * This should be used in link openers. diff --git a/src/openers.ts b/src/openers.ts index 121b80d9e4e2b447f89fb3a1a53b83804b3b4f61..20ea15379064c63446c7edc87f4f1a383730a9d6 100644 --- a/src/openers.ts +++ b/src/openers.ts @@ -140,9 +140,8 @@ export async function compareCurrentBranch(): Promise { 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}`); } }