Branches, Pull Requests, Merge Requests, and Edition-Aware Analysis: Diagnostics, Failure Modes, and Production Practices
Diagnose wrong PR identity, shallow SCM history, edition mismatches, invalid metric comparisons, and project-key misuse without hiding the original evidence.
Learning objectives
- Diagnose wrong PR key/source/target parameters without deleting or renaming the project.
- Distinguish shallow-SCM failures from scanner, server, gate, provider, and edition failures.
- Reject Community Build guidance that silently assumes Developer+ branch/PR capability.
- Recognize invalid comparisons between main overall metrics and PR New Code metrics.
- Repair project-key and provider-decoration mistakes with evidence-preserving corrections.
1. Evidence-first diagnostic sequence
-
Preserve CI checkout logs, scanner command/effective context,
report-task.txt, task ID, and provider status. - Record server edition/version, scanner version/runtime, analyzer/plugin versions, and integration versions.
- Record Git SHA, current branch, shallow state, refs, target branch, and merge base.
- Record effective project key and branch/PR parameters or auto-detected provider metadata.
- Inspect scanner indexing/report upload and Compute Engine result.
- Inspect SonarQube PR/branch identity, New Code, profile/gate, and issue population.
- Inspect provider binding/permissions/status delivery only after SonarQube analysis state is proven.
- Apply the least-destructive correction and rerun the same intended revision/question.
2. Failure: wrong PR target or key
Symptom: the PR analysis exists but New Code contains unexpected files, or decoration appears on the wrong pull request.
Likely cause:
sonar.pullrequest.base or
sonar.pullrequest.key was manually set incorrectly and
overrode correct CI metadata.
git branch --show-current
git rev-parse HEAD
git merge-base HEAD origin/main
git diff --name-status origin/main...HEAD
# Preserve intended identity separately:
printf '%s\n' \
'sonar.pullrequest.key=17' \
'sonar.pullrequest.branch=feature/demo' \
'sonar.pullrequest.base=main' \
| tee evidence/intended-pr.properties
Repair the CI identity parameters; do not create a replacement SonarQube project key to escape the incorrect PR analysis.
3. Failure: shallow clone breaks comparison/blame
Evidence:
git rev-parse --is-shallow-repository returns
true, the target ref is absent or
merge-base fails, and scanner logs report missing
SCM/blame context.
Repair: fetch full history and all required target
refs. In GitHub Actions, use actions/checkout with
fetch-depth: 0. Do not remove .git after
checkout.
4. Failure: teaching commercial branch analysis as Community Build
Anti-pattern: “Just add
-Dsonar.branch.name=feature/a to Community Build.” This
confuses a scanner parameter with a licensed server feature. The
correct Community Build fallback is main-branch analysis plus a
clearly labeled Git/configuration simulation, or a separate
simulation project if an executable feature revision must be
analyzed.
5. Failure: comparing PR New Code metrics to main overall metrics
A PR can have 100% New Code coverage while main overall coverage is 62%. Both can be correct because they describe different code populations. Likewise, a PR may report only issues on changed lines while the first main analysis after merge can reveal issues on old code that PR analysis did not report. Interpret the population before interpreting the number.
6. Failure: reusing/changing project keys to model branches
In Developer+, branches and PRs belong to the same project identity.
Creating myapp-feature-a, myapp-feature-b,
and myapp-release as unrelated projects fragments
history and prevents proper comparison/synchronization. In Community
Build, a second project key is acceptable only as an explicitly
temporary simulation—not as a claim of branch support.
7. Failure: analysis succeeds but decoration is missing
| Evidence | Interpretation | Next layer |
|---|---|---|
| Scanner failed before upload | No server analysis to decorate | Scanner/build/auth/network |
| Upload succeeded; CE failed | Server processing incomplete | Compute Engine/server |
| CE succeeded; gate computed; no provider status | Sonar result exists | Project binding/provider app permissions/PR identity |
| Provider status visible but merge still allowed | Decoration works | Provider branch-protection/ruleset policy |
8. Intentionally broken example: wrong base + shallow checkout
Suppose a CI job manually sets
sonar.pullrequest.base=develop for a PR that actually
targets main, and the checkout has depth 1. Preserve
both defects before changing anything:
mkdir -p evidence/broken
git rev-parse HEAD | tee evidence/broken/sha.txt
git branch --show-current | tee evidence/broken/branch.txt
git rev-parse --is-shallow-repository | tee evidence/broken/is-shallow.txt
git show-ref | tee evidence/broken/refs.txt
printf '%s\n' 'sonar.pullrequest.base=develop' \
| tee evidence/broken/effective-override.txt
# Expected to fail or show missing target context; preserve output:
git merge-base HEAD origin/main 2>&1 \
| tee evidence/broken/merge-base.txt || true
Repair one layer at a time: restore Git history/target ref first, prove the merge base, then remove/fix the incorrect manual base parameter. Rerun the same feature SHA. This lets you attribute the corrected behavior causally.
9. Troubleshooting shortcuts to reject
- Do not switch to a different project key after a failed PR analysis.
- Do not delete SonarQube branch/PR history before preserving evidence.
- Do not disable SCM to hide shallow-clone warnings.
- Do not lower Quality Gate thresholds to make a misidentified PR green.
- Do not use administrator tokens for routine analysis/decoration.
- Do not disable TLS verification or directly edit database/search state.
- Do not repeatedly retry before recording the first Compute Engine/provider failure.
Knowledge check
PR analysis exists but shows the wrong changed files. Which two identity facts are highest priority?
The PR target/base and the actual source revision/history/merge base.
Why repair shallow history before changing SonarQube policy?
The evidence needed to calculate the comparison is missing; policy changes do not restore SCM truth.
A green SonarQube PR gate is visible, but merge is not blocked. Is SonarQube necessarily broken?
No. The provider must configure that SonarQube status as a required merge check.
What does a Community Build second-project feature simulation prove?
That the feature revision can be analyzed as an independent project; it does not prove branch/PR New Code semantics.
Why preserve manual overrides in the incident packet?
They may have overridden correct CI auto-detection and changed the analysis identity.
ceTaskId and its server-side result before retrying a
branch/PR analysis; a later successful task must not erase the causal
evidence from the failed run.
Official references and version notes
- SonarQube downloads / edition matrix — Community Build 26.9.0.129388; Server 2026 Release 4.1; 2026.1.5 LTA; branch and pull-request analysis plus PR decoration start in Developer Edition.
- Branch analysis introduction — retained branch state, New Code and Quality Gate behavior.
- Setting up branch analysis — branch-name identity, CI integration and branch-level New Code guidance.
- Pull request analysis introduction — changed code relative to the target, New Code-only gate conditions, and provider decoration boundary.
-
Setting up pull request analysis
— CI prerequisite and
sonar.pullrequest.key/branch/baseparameters. -
Checked-out code
— full Git history, target refs, merge-base relevance and
fetch-depth: 0. - Quality standards and New Code — PR New Code is the code changed relative to the target branch.
- GitHub integration — CI auto-detection and PR quality-gate reporting; Chapter 18 expands provider setup.
- SonarScanner CLI 8.1.0.6389 — scanner baseline used by the mandatory lab.
Rechecked 2026-09-08. Mandatory examples target SonarQube
Community Build 26.9.0.129388 and SonarScanner
CLI 8.1.0.6389. Current commercial reference
points are SonarQube Server 2026 Release 4.1 and
2026.1.5 LTA. Current product packaging places
analysis of feature/maintenance branches, pull/merge requests, and
PR quality-gate decoration in
Developer Edition and above. Pull-request
analysis must run in a CI pipeline; the source branch must be
checked out, the target fetched, valid .git metadata
retained, and full-enough history available. SonarSource
recommends full depth; for GitHub Actions the documented pattern
is fetch-depth: 0. Supported CI systems can
auto-detect branch/PR parameters; manually supplied PR properties
override automatic detection. Recheck provider-specific
integration limits and CI auto-detection behavior before
production rollout.
Keep the academy open
Support free, practical DevOps education.
Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this
address.