Skip to content

Commit

Permalink
Use combination of --depth and --deepen
Browse files Browse the repository at this point in the history
  • Loading branch information
dorny committed Mar 8, 2021
1 parent 8801c88 commit 49abb09
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3872,10 +3872,17 @@ async function getChangesSinceMergeBase(baseRef, ref, initialFetchDepth) {
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())) {
await exec_1.default('git', ['fetch', `--depth=${depth}`, 'origin', `${baseRef}:${baseRef}`, `${ref}`]);
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');
Expand Down
8 changes: 7 additions & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ 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())) {
await exec('git', ['fetch', `--depth=${depth}`, 'origin', `${baseRef}:${baseRef}`, `${ref}`])
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')
Expand Down

0 comments on commit 49abb09

Please sign in to comment.