diff --git a/CHANGELOG.md b/CHANGELOG.md index a064e6b..c1fac5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v2.9.2 +- [Fix fetching git history](https://github.com/dorny/paths-filter/pull/75) + ## v2.9.1 - [Fix fetching git history + fallback to unshallow repo](https://github.com/dorny/paths-filter/pull/74) diff --git a/dist/index.js b/dist/index.js index 71893ad..e79004f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3865,36 +3865,33 @@ async function getChangesOnHead() { return parseGitDiffOutput(output); } exports.getChangesOnHead = getChangesOnHead; -async function getChangesSinceMergeBase(baseRef, ref, initialFetchDepth) { +async function getChangesSinceMergeBase(base, ref, initialFetchDepth) { + const baseRef = `remotes/origin/${base}`; async function hasMergeBase() { return (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 { - let init = true; - let lastCommitCount = await getCommitCount(); - let depth = Math.max(lastCommitCount * 2, initialFetchDepth); - while (!(await hasMergeBase())) { - if (init) { - await exec_1.default('git', ['fetch', `--depth=${depth}`, 'origin', `${baseRef}:${baseRef}`, `${ref}`]); - init = false; - } - else { - await exec_1.default('git', ['fetch', `--deepen=${depth}`, 'origin', baseRef, ref]); - } - const commitCount = await getCommitCount(); - if (commitCount === lastCommitCount) { - core.info('No more commits were fetched'); - core.info('Last attempt will be to fetch full history'); - await exec_1.default('git', ['fetch', '--unshallow']); - if (!(await hasMergeBase())) { - noMergeBase = true; + if (!(await hasMergeBase())) { + await exec_1.default('git', ['fetch', `--depth=${initialFetchDepth}`, 'origin', base, ref]); + let depth = initialFetchDepth; + let lastCommitCount = await getCommitCount(); + while (!(await hasMergeBase())) { + depth = Math.min(depth * 2, Number.MAX_SAFE_INTEGER); + await exec_1.default('git', ['fetch', `--deepen=${depth}`, 'origin', base, ref]); + const commitCount = await getCommitCount(); + if (commitCount === lastCommitCount) { + core.info('No more commits were fetched'); + core.info('Last attempt will be to fetch full history'); + await exec_1.default('git', ['fetch']); + if (!(await hasMergeBase())) { + noMergeBase = true; + } + break; } - break; + lastCommitCount = commitCount; } - depth = Math.min(depth * 2, Number.MAX_SAFE_INTEGER); - lastCommitCount = commitCount; } } finally { diff --git a/src/git.ts b/src/git.ts index a55faa6..531c301 100644 --- a/src/git.ts +++ b/src/git.ts @@ -54,11 +54,9 @@ export async function getChangesOnHead(): Promise { return parseGitDiffOutput(output) } -export async function getChangesSinceMergeBase( - baseRef: string, - ref: string, - initialFetchDepth: number -): Promise { +export async function getChangesSinceMergeBase(base: string, ref: string, initialFetchDepth: number): Promise { + const baseRef = `remotes/origin/${base}` + async function hasMergeBase(): Promise { return (await exec('git', ['merge-base', baseRef, ref], {ignoreReturnCode: true})).code === 0 } @@ -66,28 +64,25 @@ export async function getChangesSinceMergeBase( let noMergeBase = false core.startGroup(`Searching for merge-base ${baseRef}...${ref}`) try { - let init = true - let lastCommitCount = await getCommitCount() - let depth = Math.max(lastCommitCount * 2, initialFetchDepth) - while (!(await hasMergeBase())) { - if (init) { - await exec('git', ['fetch', `--depth=${depth}`, 'origin', `${baseRef}:${baseRef}`, `${ref}`]) - init = false - } else { - await exec('git', ['fetch', `--deepen=${depth}`, 'origin', baseRef, ref]) - } - const commitCount = await getCommitCount() - if (commitCount === lastCommitCount) { - core.info('No more commits were fetched') - core.info('Last attempt will be to fetch full history') - await exec('git', ['fetch', '--unshallow']) - if (!(await hasMergeBase())) { - noMergeBase = true + if (!(await hasMergeBase())) { + await exec('git', ['fetch', `--depth=${initialFetchDepth}`, 'origin', base, ref]) + let depth = initialFetchDepth + let lastCommitCount = await getCommitCount() + while (!(await hasMergeBase())) { + depth = Math.min(depth * 2, Number.MAX_SAFE_INTEGER) + await exec('git', ['fetch', `--deepen=${depth}`, 'origin', base, ref]) + const commitCount = await getCommitCount() + if (commitCount === lastCommitCount) { + core.info('No more commits were fetched') + core.info('Last attempt will be to fetch full history') + await exec('git', ['fetch']) + if (!(await hasMergeBase())) { + noMergeBase = true + } + break } - break + lastCommitCount = commitCount } - depth = Math.min(depth * 2, Number.MAX_SAFE_INTEGER) - lastCommitCount = commitCount } } finally { core.endGroup()