From 017e948079113a23f5612546c7f27e49b072b065 Mon Sep 17 00:00:00 2001 From: Deep Mistry Date: Mon, 15 Dec 2025 09:08:53 -0500 Subject: [PATCH] fix: use merge-base for accurate change detection in pj-rehearse When a PR is created from an outdated base branch commit, git diff-tree comparisons can be incorrect because they compare against the old base SHA instead of finding the actual merge point. This fix uses git merge-base to find the common ancestor between the base SHA and HEAD, ensuring accurate change detection even when: - The base branch has moved forward significantly - The PR was created from an outdated commit - Merge commits exist in the PR history This resolves the issue where pj-rehearse fails to detect changes until the PR is rebased onto the latest base branch. Related: Fixes issue where rehearsable tests are not detected when PR base branch is outdated --- pkg/config/release.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/config/release.go b/pkg/config/release.go index 7800878e4c..4bb3c3689d 100644 --- a/pkg/config/release.go +++ b/pkg/config/release.go @@ -274,7 +274,18 @@ func getRevChanges(root, path, base string, ignoreModified bool) ([]string, erro if ignoreModified { filter = "--diff-filter=ACR" } - cmd := []string{"diff-tree", "-r", filter, base + ":" + path, "HEAD:" + path} + // Find merge base to handle cases where base branch has moved forward. + // This ensures accurate change detection even when the PR was created from + // an outdated base branch commit. + mergeBase, err := git(root, "merge-base", base, "HEAD") + if err != nil { + // Fallback to original behavior if merge-base fails (e.g., no common ancestor) + // This can happen in edge cases, so we use the provided base directly + mergeBase = base + } else { + mergeBase = strings.TrimSpace(mergeBase) + } + cmd := []string{"diff-tree", "-r", filter, mergeBase + ":" + path, "HEAD:" + path} diff, err := git(root, cmd...) if err != nil || diff == "" { return nil, err