Skip to content

Detect renamed files so renamed classes are reported#2

Merged
Seldaek merged 1 commit into
mainfrom
fix/rename-detection
Jun 4, 2026
Merged

Detect renamed files so renamed classes are reported#2
Seldaek merged 1 commit into
mainfrom
fix/rename-detection

Conversation

@Seldaek

@Seldaek Seldaek commented Jun 4, 2026

Copy link
Copy Markdown
Member

Problem

On composer/composer#12919 the file/class src/Composer/Platform/Version.php (class Version) was renamed to VersionRenamed.php (class VersionRenamed). The posted comment reported the in-place edits (Cache/Installer/Runtime) but omitted the rename entirely — neither Composer\Platform\Version (removed) nor Composer\Platform\VersionRenamed (added) appeared.

Root cause

scripts/detect.sh built its changed-file list with git diff "${BASE_REF}..HEAD" --diff-filter=AMD --name-only. With git's default rename detection on, a 99%-similar rename is reported as a single rename (R) entry, and --diff-filter=AMD keeps only A/M/D — dropping R entirely. So neither the old nor the new path ever reached the snapshotter.

The snapshot side was already correct: Snapshotter::snapshot() resolves each path with realpath() and silently skips paths absent on a given ref, so once both paths are in the (shared) file list, BASE yields Version and HEAD yields VersionRenamed on its own.

Fix

  • scripts/detect.sh — add --no-renames, which decomposes a rename into a Delete(old) + Add(new); both pass the existing AMD filter, so the old FQCN is reported as removed and the new one as added.
  • scripts/preflight.sh — add --no-renames for consistency. It makes a rename emit the full old/new content as -/+ lines so the token scan reliably triggers analysis, closing a blind spot where a rename that only changes a namespace could wrongly gate analysis off. Preflight stays biased toward "true".
  • tests/DetectTest.phptestRenamedClassIsReportedAsRemovedAndAdded, an integration test mirroring this scenario. It fails on the old code (empty body) and passes with the fix.
  • README.md — note that a rename is reported as removal of the old FQCN + addition of the new one (no rename-pairing).

Verification

  • New test fails without the fix (rendered body is empty) and passes with it.
  • Full suite green: 57 tests, 140 assertions.

🤖 Generated with Claude Code

detect.sh built its changed-file list with `git diff --diff-filter=AMD`.
With git's default rename detection, a renamed file (e.g.
Version.php -> VersionRenamed.php) is reported as a single rename (R)
entry, which the AMD filter drops entirely — so neither the old nor the
new path reached the snapshotter and the rename was reported as no change
at all (composer/composer#12919).

Add `--no-renames` so a rename is decomposed into a delete (old path) +
add (new path), both of which pass the AMD filter: the old FQCN is then
reported as removed and the new FQCN as added. The snapshot side already
ignores paths absent on a given ref, so the same file list works for both.

Also add `--no-renames` to preflight.sh for consistency: it makes a rename
emit the full old/new content as -/+ lines, so the token scan reliably
triggers analysis even for a rename that only changes a namespace.

Adds an integration test mirroring composer/composer#12919.
@Seldaek Seldaek merged commit bba9f1c into main Jun 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant