Skip to content

Commit 90c6ffd

Browse files
committed
fix: use main branch ref instead of merge-base for --head scan base
When --head is passed without --base, resolveBase() returned merge-base(HEAD, origin/main) — a commit depending on the current checkout. Passing that into a second merge-base with the target ref could include unrelated main commits when HEAD is not the reviewed branch. Add resolveMainRef() that returns the branch ref name (origin/main or main) so the --head path computes merge-base(origin/main, head) directly, giving the correct fork point regardless of the local checkout.
1 parent 615fd9f commit 90c6ffd

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎scripts/perf-review-scan.mjs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,16 @@ function git(args) {
476476
return execFileSync('git', args, { cwd: ROOT, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 });
477477
}
478478

479+
function resolveMainRef() {
480+
for (const ref of ['origin/main', 'main']) {
481+
try {
482+
git(['rev-parse', '--verify', ref]);
483+
return ref;
484+
} catch {}
485+
}
486+
throw new Error('Could not resolve main; pass --base <ref> or --diff <file>.');
487+
}
488+
479489
function resolveBase(ref) {
480490
for (const candidate of [ref, 'origin/main', 'main'].filter(Boolean)) {
481491
try {
@@ -513,7 +523,7 @@ function collect(options) {
513523
}
514524
const unified = `--unified=${CONTEXT_LINES}`;
515525
if (options.head !== undefined) {
516-
const base = git(['merge-base', options.base ?? resolveBase(), options.head]).trim();
526+
const base = git(['merge-base', options.base ?? resolveMainRef(), options.head]).trim();
517527
return {
518528
text: git([
519529
'diff',

0 commit comments

Comments
 (0)