use compare API to deepen by exact divergence instead of fixed 1000

This commit is contained in:
Colin McDonnell
2026-03-05 23:50:22 +00:00
committed by pullfrog[bot]
parent 8bac460177
commit ed91fbb18d
2 changed files with 50 additions and 22 deletions
+22 -6
View File
@@ -146647,15 +146647,33 @@ async function checkoutPrBranch(pullNumber, params) {
const baseBranch = pr.data.base.ref;
const headBranch = pr.data.head.ref;
const localBranch = `pr-${pullNumber}`;
const isShallow = $("git", ["rev-parse", "--is-shallow-repository"], { log: false }).trim() === "true";
let deepenArgs = [];
if (isShallow) {
let depth = 1e3;
try {
const comparison = await octokit.rest.repos.compareCommits({
owner,
repo: name,
base: baseBranch,
head: `pull/${pullNumber}/head`
});
depth = comparison.data.behind_by + 10;
log.debug(
`\xBB PR is ${comparison.data.behind_by} commits behind ${baseBranch}, deepening by ${depth}`
);
} catch {
log.debug(`\xBB compare API failed, falling back to --deepen=${depth}`);
}
deepenArgs = [`--deepen=${depth}`];
}
const currentSha = $("git", ["rev-parse", "HEAD"], { log: false }).trim();
const alreadyOnBranch = currentSha === pr.data.head.sha;
if (alreadyOnBranch) {
log.debug(`already on PR branch ${localBranch}, skipping checkout`);
} else {
log.debug(`\xBB fetching base branch (${baseBranch})...`);
const isShallow = $("git", ["rev-parse", "--is-shallow-repository"], { log: false }).trim();
const baseFetchArgs = isShallow === "true" ? ["--deepen=1000", "--no-tags", "origin", baseBranch] : ["--no-tags", "origin", baseBranch];
$git("fetch", baseFetchArgs, {
$git("fetch", [...deepenArgs, "--no-tags", "origin", baseBranch], {
token: gitToken,
restricted: shell !== "enabled"
});
@@ -146670,9 +146688,7 @@ async function checkoutPrBranch(pullNumber, params) {
}
if (alreadyOnBranch) {
log.debug(`\xBB fetching base branch (${baseBranch})...`);
const isShallow = $("git", ["rev-parse", "--is-shallow-repository"], { log: false }).trim();
const baseFetchArgs = isShallow === "true" ? ["--deepen=1000", "--no-tags", "origin", baseBranch] : ["--no-tags", "origin", baseBranch];
$git("fetch", baseFetchArgs, {
$git("fetch", [...deepenArgs, "--no-tags", "origin", baseBranch], {
token: gitToken,
restricted: shell !== "enabled"
});