Skip to content

Commit

Permalink
Fix unnecessary calls to getLocalRef()
Browse files Browse the repository at this point in the history
Michal Dorner committed Apr 12, 2021
1 parent 78b1672 commit e597431
Showing 2 changed files with 20 additions and 19 deletions.
20 changes: 10 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -3967,7 +3967,7 @@ async function listAllFilesAsAdded() {
}
exports.listAllFilesAsAdded = listAllFilesAsAdded;
async function getCurrentRef() {
core.startGroup(`Determining current ref`);
core.startGroup(`Get current git ref`);
try {
const branch = (await exec_1.default('git', ['branch', '--show-current'])).stdout.trim();
if (branch) {
@@ -4010,7 +4010,7 @@ async function getCommitCount() {
}
async function getLocalRef(shortName) {
if (isGitSha(shortName)) {
return await hasCommit(shortName) ? shortName : undefined;
return (await hasCommit(shortName)) ? shortName : undefined;
}
const output = (await exec_1.default('git', ['show-ref', shortName], { ignoreReturnCode: true })).stdout;
const refs = output
@@ -4032,14 +4032,14 @@ async function ensureRefAvailable(name) {
let ref = await getLocalRef(name);
if (ref === undefined) {
await exec_1.default('git', ['fetch', '--depth=1', '--no-tags', 'origin', name]);
}
ref = await getLocalRef(name);
if (ref === undefined) {
await exec_1.default('git', ['fetch', '--depth=1', '--tags', 'origin', name]);
}
ref = await getLocalRef(name);
if (ref === undefined) {
throw new Error(`Could not determine what is ${name} - fetch works but it's not a branch, tag or commit SHA`);
ref = await getLocalRef(name);
if (ref === undefined) {
await exec_1.default('git', ['fetch', '--depth=1', '--tags', 'origin', name]);
ref = await getLocalRef(name);
if (ref === undefined) {
throw new Error(`Could not determine what is ${name} - fetch works but it's not a branch, tag or commit SHA`);
}
}
}
return ref;
}
19 changes: 10 additions & 9 deletions src/git.ts
Original file line number Diff line number Diff line change
@@ -163,7 +163,7 @@ export async function listAllFilesAsAdded(): Promise<File[]> {
}

export async function getCurrentRef(): Promise<string> {
core.startGroup(`Determining current ref`)
core.startGroup(`Get current git ref`)
try {
const branch = (await exec('git', ['branch', '--show-current'])).stdout.trim()
if (branch) {
@@ -236,15 +236,16 @@ async function ensureRefAvailable(name: string): Promise<string> {
let ref = await getLocalRef(name)
if (ref === undefined) {
await exec('git', ['fetch', '--depth=1', '--no-tags', 'origin', name])
ref = await getLocalRef(name)
if (ref === undefined) {
await exec('git', ['fetch', '--depth=1', '--tags', 'origin', name])
ref = await getLocalRef(name)
if (ref === undefined) {
throw new Error(`Could not determine what is ${name} - fetch works but it's not a branch, tag or commit SHA`)
}
}
}
ref = await getLocalRef(name)
if (ref === undefined) {
await exec('git', ['fetch', '--depth=1', '--tags', 'origin', name])
}
ref = await getLocalRef(name)
if (ref === undefined) {
throw new Error(`Could not determine what is ${name} - fetch works but it's not a branch, tag or commit SHA`)
}

return ref
} finally {
core.endGroup()

0 comments on commit e597431

Please sign in to comment.