@@ -153,25 +153,35 @@ stages:
153153
154154 # Resolve the PR commit range. A PR-policy build checks out the MERGE
155155 # commit (Build.SourceVersion): parent ^1 is the target-branch tip,
156- # parent ^2 is the PR head. The diff ^1..^2 is exactly the PR's
157- # changes relative to the target branch. We read the range here and
158- # set pipeline variables so the wiring stays visible in the YAML.
156+ # parent ^2 is the PR head. The PR's true change set is the diff
157+ # between their MERGE BASE (the fork point) and ^2 -- i.e.
158+ # `git diff merge-base(^1,^2)..^2`, the same three-dot set GitHub's
159+ # "Files changed" shows. We deliberately compare against the merge
160+ # base, NOT the target tip: comparing against the tip additionally
161+ # flags every component that landed on the target branch after the PR
162+ # forked (the PR head still carries their pre-update state), which can
163+ # balloon a 1-component PR into dozens. We read the range here and set
164+ # pipeline variables so the wiring stays visible in the YAML.
159165 - script : |
160166 set -euo pipefail
161167 if ! git rev-parse --verify -q "HEAD^2" >/dev/null; then
162168 echo "##[error]HEAD is not a merge commit -- this pipeline must run as a PR build (Build.Reason=PullRequest)."
163169 exit 1
164170 fi
165- target_commit="$(git rev-parse HEAD^1)"
166171 source_commit="$(git rev-parse HEAD^2)"
172+ # Baseline = the MERGE BASE (fork point) of the target-branch tip
173+ # (HEAD^1) and the PR head (HEAD^2), NOT the target tip itself.
174+ # See the block comment above for why; this is passed as the
175+ # `--target-commit` (from) baseline to the change-set helper.
176+ target_commit="$(git merge-base HEAD^1 HEAD^2)"
167177 # PR-supplied data is untrusted: validate both SHAs before use.
168178 for sha in "$target_commit" "$source_commit"; do
169179 if [[ ! "$sha" =~ ^[0-9a-f]{40}$ ]]; then
170180 echo "##[error]invalid commit SHA: $sha"
171181 exit 1
172182 fi
173183 done
174- echo "Resolved range: target =$target_commit source=$source_commit"
184+ echo "Resolved range: base(merge-base) =$target_commit source=$source_commit"
175185 echo "##vso[task.setvariable variable=sourceCommit;isreadonly=true]$source_commit"
176186 echo "##vso[task.setvariable variable=targetCommit;isreadonly=true]$target_commit"
177187 displayName: "Determine PR commit range"
0 commit comments