Skip to content

Commit

Permalink
Update dist
Browse files Browse the repository at this point in the history
  • Loading branch information
dorny committed Mar 25, 2021
1 parent e59197f commit 3d4a250
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
49 changes: 41 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3866,15 +3866,26 @@ async function getChangesOnHead() {
}
exports.getChangesOnHead = getChangesOnHead;
async function getChangesSinceMergeBase(base, ref, initialFetchDepth) {
const baseRef = `remotes/origin/${base}`;
let baseRef;
async function hasMergeBase() {
return (await exec_1.default('git', ['merge-base', baseRef, ref], { ignoreReturnCode: true })).code === 0;
return (baseRef !== undefined && (await exec_1.default('git', ['merge-base', baseRef, ref], { ignoreReturnCode: true })).code === 0);
}
let noMergeBase = false;
core.startGroup(`Searching for merge-base ${baseRef}...${ref}`);
try {
baseRef = await getFullRef(base);
if (!(await hasMergeBase())) {
await exec_1.default('git', ['fetch', `--depth=${initialFetchDepth}`, 'origin', base, ref]);
await exec_1.default('git', ['fetch', '--no-tags', `--depth=${initialFetchDepth}`, 'origin', base, ref]);
if (baseRef === undefined) {
baseRef = await getFullRef(base);
if (baseRef === undefined) {
await exec_1.default('git', ['fetch', '--tags', `--depth=1`, 'origin', base, ref]);
baseRef = await getFullRef(base);
if (baseRef === undefined) {
throw new Error(`Could not determine what is ${base} - fetch works but it's not a branch or tag`);
}
}
}
let depth = initialFetchDepth;
let lastCommitCount = await getCommitCount();
while (!(await hasMergeBase())) {
Expand All @@ -3897,16 +3908,17 @@ async function getChangesSinceMergeBase(base, ref, initialFetchDepth) {
finally {
core.endGroup();
}
let diffArg = `${baseRef}...${ref}`;
if (noMergeBase) {
core.warning('No merge base found - all files will be listed as added');
return await listAllFilesAsAdded();
core.warning('No merge base found - change detection will use direct <commit>..<commit> comparison');
diffArg = `${baseRef}..${ref}`;
}
// Get changes introduced on HEAD compared to ref
core.startGroup(`Change detection ${baseRef}...${ref}`);
// Get changes introduced on ref compared to base
core.startGroup(`Change detection ${diffArg}`);
let output = '';
try {
// Three dots '...' change detection - finds merge-base and compares against it
output = (await exec_1.default('git', ['diff', '--no-renames', '--name-status', '-z', `${baseRef}...${ref}`])).stdout;
output = (await exec_1.default('git', ['diff', '--no-renames', '--name-status', '-z', diffArg])).stdout;
}
finally {
fixStdOutNullTermination();
Expand Down Expand Up @@ -3994,6 +4006,27 @@ async function getCommitCount() {
const count = parseInt(output);
return isNaN(count) ? 0 : count;
}
async function getFullRef(shortName) {
if (isGitSha(shortName)) {
return shortName;
}
const remoteRef = `refs/remotes/origin/${shortName}`;
const tagRef = `refs/tags/${shortName}`;
const headRef = `refs/heads/${shortName}`;
if (await verifyRef(remoteRef)) {
return remoteRef;
}
else if (await verifyRef(tagRef)) {
return tagRef;
}
else if (await verifyRef(headRef)) {
return headRef;
}
return undefined;
}
async function verifyRef(ref) {
return (await exec_1.default('git', ['show-ref', '--verify', ref], { ignoreReturnCode: true })).code === 0;
}
function fixStdOutNullTermination() {
// Previous command uses NULL as delimiters and output is printed to stdout.
// We have to make sure next thing written to stdout will start on new line.
Expand Down
8 changes: 5 additions & 3 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export async function getChangesOnHead(): Promise<File[]> {
export async function getChangesSinceMergeBase(base: string, ref: string, initialFetchDepth: number): Promise<File[]> {
let baseRef: string | undefined
async function hasMergeBase(): Promise<boolean> {
return baseRef !== undefined && (await exec('git', ['merge-base', baseRef, ref], {ignoreReturnCode: true})).code === 0
return (
baseRef !== undefined && (await exec('git', ['merge-base', baseRef, ref], {ignoreReturnCode: true})).code === 0
)
}

let noMergeBase = false
Expand Down Expand Up @@ -200,8 +202,8 @@ async function getCommitCount(): Promise<number> {
return isNaN(count) ? 0 : count
}

async function getFullRef(shortName: string) {
if(isGitSha(shortName)) {
async function getFullRef(shortName: string): Promise<string | undefined> {
if (isGitSha(shortName)) {
return shortName
}

Expand Down

0 comments on commit 3d4a250

Please sign in to comment.