Skip to content

Commit 719fede

Browse files
committed
Use rev-list for tags
1 parent f095bcc commit 719fede

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

dist/index.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,18 @@ class GitCommandManager {
722722
return output.stdout.trim();
723723
});
724724
}
725+
/**
726+
* Lists SHAs pointed to by a revision.
727+
* @param {string} ref For example: 'refs/heads/main' or '/refs/tags/v1'
728+
* @param {number} numberOfRefs
729+
* @param value
730+
*/
731+
revList(ref, numberOfRefs) {
732+
return __awaiter(this, void 0, void 0, function* () {
733+
const output = yield this.execGit(['rev-list', ref, `-${numberOfRefs}`]);
734+
return output.stdout.trim();
735+
});
736+
}
725737
setEnvironmentVariable(name, value) {
726738
this.gitEnv[name] = value;
727739
}
@@ -1982,7 +1994,7 @@ function testRef(git, ref, commit) {
19821994
// refs/tags/
19831995
else if (upperRef.startsWith('REFS/TAGS/')) {
19841996
const tagName = ref.substring('refs/tags/'.length);
1985-
return ((yield git.tagExists(tagName)) && commit === (yield git.revParse(ref)));
1997+
return ((yield git.tagExists(tagName)) && commit === (yield git.revList(ref, 1)));
19861998
}
19871999
// Unexpected
19882000
else {

src/git-command-manager.ts

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface IGitCommandManager {
3535
log1(format?: string): Promise<string>
3636
remoteAdd(remoteName: string, remoteUrl: string): Promise<void>
3737
removeEnvironmentVariable(name: string): void
38+
revList(ref: string, numberOfRefs: number): Promise<string>
3839
revParse(ref: string): Promise<string>
3940
setEnvironmentVariable(name: string, value: string): void
4041
shaExists(sha: string): Promise<boolean>
@@ -314,6 +315,17 @@ class GitCommandManager {
314315
return output.stdout.trim()
315316
}
316317

318+
/**
319+
* Lists SHAs pointed to by a revision.
320+
* @param {string} ref For example: 'refs/heads/main' or '/refs/tags/v1'
321+
* @param {number} numberOfRefs
322+
* @param value
323+
*/
324+
async revList(ref: string, numberOfRefs: number): Promise<string> {
325+
const output = await this.execGit(['rev-list', ref, `-${numberOfRefs}`])
326+
return output.stdout.trim()
327+
}
328+
317329
setEnvironmentVariable(name: string, value: string): void {
318330
this.gitEnv[name] = value
319331
}

src/ref-helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export async function testRef(
167167
else if (upperRef.startsWith('REFS/TAGS/')) {
168168
const tagName = ref.substring('refs/tags/'.length)
169169
return (
170-
(await git.tagExists(tagName)) && commit === (await git.revParse(ref))
170+
(await git.tagExists(tagName)) && commit === (await git.revList(ref, 1))
171171
)
172172
}
173173
// Unexpected

0 commit comments

Comments
 (0)