Skip to content

Commit 8817bcd

Browse files
Seldaekclaude
andcommitted
Diff against the merge base instead of the BASE_REF tip
The previous shallow fetch of BASE_REF and `git diff BASE_REF..HEAD` produced a meaningless cross-tree diff when the PR head was rebased onto an older base commit: everything BASE_REF gained since the rebase point showed up as "removed in PR". Resolve the merge base via the GitHub compare API and fetch that commit by SHA so the diff matches GitHub's "Files changed" semantics. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7bfe3bc commit 8817bcd

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

action.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,35 @@ runs:
9393
fetch-depth: 1
9494
persist-credentials: false
9595

96-
- name: Fetch base ref
96+
- name: Fetch merge base
97+
id: base
9798
if: steps.pr.outputs.number
9899
shell: bash
99100
env:
101+
GH_TOKEN: ${{ github.token }}
102+
REPO: ${{ github.repository }}
100103
BASE_REF: ${{ steps.pr.outputs.base-ref }}
101-
run: git fetch --no-tags --depth=1 origin "${BASE_REF}:refs/remotes/origin/${BASE_REF}"
104+
run: |
105+
# Resolve the merge base server-side: shallow fetches mean the local
106+
# repo can't compute it, and diffing against the BASE_REF tip produces
107+
# garbage when the PR is rebased onto an older commit (everything main
108+
# has gained since the rebase point shows up as "removed in PR").
109+
head_sha=$(git rev-parse HEAD)
110+
merge_base=$(gh api "repos/${REPO}/compare/${BASE_REF}...${head_sha}" --jq '.merge_base_commit.sha')
111+
if [[ -z "${merge_base}" || "${merge_base}" == "null" ]]; then
112+
echo "::error::Could not determine merge base for ${BASE_REF}...${head_sha}"
113+
exit 1
114+
fi
115+
git fetch --no-tags --depth=1 origin "${merge_base}"
116+
echo "merge-base=${merge_base}" >> "$GITHUB_OUTPUT"
102117
103118
- name: Preflight scan
104119
id: preflight
105120
if: steps.pr.outputs.number
106121
shell: bash
107122
working-directory: ${{ inputs.working-directory }}
108123
env:
109-
BASE_REF: origin/${{ steps.pr.outputs.base-ref }}
124+
BASE_REF: ${{ steps.base.outputs.merge-base }}
110125
PATHS_GLOB: ${{ inputs.paths }}
111126
OUTPUT_FILE: api-surface-preflight.txt
112127
ACTION_PATH: ${{ github.action_path }}
@@ -155,7 +170,7 @@ runs:
155170
shell: bash
156171
working-directory: ${{ inputs.working-directory }}
157172
env:
158-
BASE_REF: origin/${{ steps.pr.outputs.base-ref }}
173+
BASE_REF: ${{ steps.base.outputs.merge-base }}
159174
PATHS_GLOB: ${{ inputs.paths }}
160175
SOURCE_ROOTS: ${{ inputs.source-roots }}
161176
COMPOSER_PROJECT_PATH: ${{ steps.project-deps.outputs.project-path }}

0 commit comments

Comments
 (0)