Coverage for src/pullapprove/trust/renames.py: 89%
18 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-07-28 14:54 -0500
« prev ^ index » next coverage.py v7.14.1, created at 2026-07-28 14:54 -0500
1"""The file-level pure-rename rule.
3A pure rename — git found byte-identical content at a new path — produces no
4hunks, only header metadata, so it never reaches the per-hunk rules. This rule
5classifies the file itself, from its header lines alone.
7Default-deny like every hunk rule: the ONLY recognized shape is the exact
8three metadata lines git emits for a same-content, same-mode rename. A rename
9that also changes mode (`old mode`/`new mode` lines), a binary rename with
10changes (`index` + `Binary files` lines), a copy (`copy from`/`copy to`), or
11anything else adds or substitutes lines and is declined — those changes are
12real and must be shown.
13"""
15from __future__ import annotations
17from ..diff import DiffFile
18from .labels import Trust
21def trust_file_label(file: DiffFile) -> Trust | None:
22 """Return the trust label for a hunkless file, or None when nothing matches."""
23 if file.hunks:
24 return None
25 if not file.is_move():
26 return None
27 # After the `diff --git` line: exactly the pure-rename metadata, nothing
28 # else. The paths themselves were already read from the `diff --git` line
29 # (is_move above); prefix checks avoid re-parsing the C-quoted forms.
30 meta = file.header_lines[1:]
31 if len(meta) != 3:
32 return None
33 if meta[0] != "similarity index 100%":
34 return None
35 if not meta[1].startswith("rename from "):
36 return None
37 if not meta[2].startswith("rename to "):
38 return None
39 return Trust.FILE_RENAMED