Skip to content

Commit 033277b

Browse files
committed
GitCommitMessageCheck: match git cat-file replies to tags by order
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 6987786 commit 033277b

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

‎NEWS.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ pkgcheck 0.10.47 (unreleased)
2626
- ``pkgcheck scan``: a bare ``-j`` or ``-j0`` in ``MAKEOPTS`` no longer fails
2727
the scan (Arthur Zamarin)
2828

29+
- InvalidCommitTag: report ``Fixes`` and ``Reverts`` naming a blob or tree
30+
instead of crashing (Arthur Zamarin)
31+
2932
-----------------------------
3033
pkgcheck 0.10.46 (2026-09-26)
3134
-----------------------------

‎src/pkgcheck/checks/git.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -850,15 +850,15 @@ def _commit_tag(self, tag, values, commit: git.GitCommit):
850850
return
851851
self.git_cat_file.stdin.write("\n".join(commits.keys()) + "\n")
852852
if self.git_cat_file.poll() is None:
853-
for _ in range(len(commits)):
853+
# replies come in request order, naming found objects by their full hash
854+
for value in commits.values():
854855
line = self.git_cat_file.stdout.readline().strip()
855856
if mo := self._git_cat_file_regex.match(line):
856-
value = mo.group("object")
857-
status = mo.group("status")
858-
if not status.startswith("commit "):
859-
yield InvalidCommitTag(
860-
tag, commits[value], f"{status} commit", commit=commit
861-
)
857+
status = mo.group("status").split()[0]
858+
if status in ("missing", "ambiguous"):
859+
yield InvalidCommitTag(tag, value, f"{status} commit", commit=commit)
860+
elif status != "commit":
861+
yield InvalidCommitTag(tag, value, f"{status}, not a commit", commit=commit)
862862

863863
def feed(self, commit: git.GitCommit):
864864
if len(commit.message) == 0:

‎tests/checks/test_git.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ def test_commit_tags(self):
125125
assert isinstance(r, git_mod.InvalidCommitTag)
126126
assert f"{status} commit" in r.error
127127

128+
# existing non-commit object, which git names by its full hash
129+
self.check._git_cat_file = None
130+
with patch("pkgcheck.checks.git.subprocess.Popen") as git_cat:
131+
git_cat.return_value.poll.return_value = None
132+
git_cat.return_value.stdout.readline.return_value = f"{ref}0123456789abc blob 3"
133+
commit = self.SO_commit(tags=[f"{tag}: {ref}"])
134+
r = self.assertReport(self.check, commit)
135+
assert isinstance(r, git_mod.InvalidCommitTag)
136+
assert "blob, not a commit" in r.error
137+
128138
# valid tag reference
129139
with patch("pkgcheck.checks.git.subprocess.Popen") as git_cat:
130140
self.check._git_cat_file = None

0 commit comments

Comments
 (0)