Skip to content

Commit 71d51d8

Browse files
authored
Merge pull request #91 from dorny/issue-90-get-local-branch
Fix #90 getLocalRef() returns wrong ref
2 parents 78ab00f + af2564d commit 71d51d8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

dist/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4015,8 +4015,9 @@ async function getLocalRef(shortName) {
40154015
const output = (await exec_1.default('git', ['show-ref', shortName], { ignoreReturnCode: true })).stdout;
40164016
const refs = output
40174017
.split(/\r?\n/g)
4018-
.map(l => { var _a, _b; return (_b = (_a = l.match(/refs\/.*$/)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : ''; })
4019-
.filter(l => l !== '');
4018+
.map(l => l.match(/refs\/(?:(?:heads)|(?:tags)|(?:remotes\/origin))\/(.*)$/))
4019+
.filter(match => match !== null && match[1] === shortName)
4020+
.map(match => { var _a; return (_a = match === null || match === void 0 ? void 0 : match[0]) !== null && _a !== void 0 ? _a : ''; }); // match can't be null here but compiler doesn't understand that
40204021
if (refs.length === 0) {
40214022
return undefined;
40224023
}

src/git.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ async function getLocalRef(shortName: string): Promise<string | undefined> {
215215
const output = (await exec('git', ['show-ref', shortName], {ignoreReturnCode: true})).stdout
216216
const refs = output
217217
.split(/\r?\n/g)
218-
.map(l => l.match(/refs\/.*$/)?.[0] ?? '')
219-
.filter(l => l !== '')
218+
.map(l => l.match(/refs\/(?:(?:heads)|(?:tags)|(?:remotes\/origin))\/(.*)$/))
219+
.filter(match => match !== null && match[1] === shortName)
220+
.map(match => match?.[0] ?? '') // match can't be null here but compiler doesn't understand that
220221

221222
if (refs.length === 0) {
222223
return undefined

0 commit comments

Comments
 (0)