commit:     7410c137c57c645b5e502f279eb183a14d7ef216
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Sat Mar 11 07:10:29 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Sat Mar 11 07:10:29 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=7410c137

GitPkgCommitsCheck: fix modification check for added ebuild in pkgset

When commit range has modification for multiple versions, with one of
them modifying a newly added version in the same range, it wouldn't find
the correct base commit and fail. Fix it by grouping based on fullver.

The test is special with time.sleep, since I need the commits be in
different seconds, otherwise the sorting by time might be bad.

Resolves: https://github.com/pkgcore/pkgcheck/issues/563
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgcheck/checks/git.py |  6 +++++-
 tests/checks/test_git.py   | 15 +++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/pkgcheck/checks/git.py b/src/pkgcheck/checks/git.py
index 7309a08f..aec3b05f 100644
--- a/src/pkgcheck/checks/git.py
+++ b/src/pkgcheck/checks/git.py
@@ -497,7 +497,11 @@ class GitPkgCommitsCheck(GentooRepoCheck, GitCommitsCheck):
             yield from self.rename_checks(list(pkg_map["R"]))
         # run modified package checks
         if modified := [pkg for pkg in pkg_map["M"] if pkg not in 
pkg_map["D"]]:
-            yield from self.modified_checks(modified, list(pkg_map["A"]))
+            version_modifications = defaultdict(list)
+            for pkg in modified:
+                version_modifications[pkg.fullver].append(pkg)
+            for modified in version_modifications.values():
+                yield from self.modified_checks(modified, pkg_map["A"])
 
         for git_pkg in pkgset:
             # remaining checks are irrelevant for removed packages

diff --git a/tests/checks/test_git.py b/tests/checks/test_git.py
index 7eb7907a..03687451 100644
--- a/tests/checks/test_git.py
+++ b/tests/checks/test_git.py
@@ -1,5 +1,6 @@
 import os
 import textwrap
+import time
 from datetime import datetime, timedelta
 from unittest.mock import patch
 
@@ -736,6 +737,20 @@ class TestGitPkgCommitsCheck(ReportTestCase):
         self.init_check()
         self.assertNoReport(self.check, self.source)
 
+    def test_modified_added_file(self):
+        self.child_repo.create_ebuild("cat/pkg-0", 
homepage="https://gentoo.org";)
+        self.child_git_repo.add_all("cat/pkg: update HOMEPAGE")
+        time.sleep(1)
+        self.child_repo.create_ebuild("cat/pkg-1", eapi="7")
+        self.child_git_repo.add_all("cat/pkg: add 1")
+        time.sleep(1)
+        self.child_repo.create_ebuild("cat/pkg-1", eapi="8")
+        self.child_git_repo.add_all("cat/pkg: bump EAPI")
+        self.init_check()
+        r = self.assertReport(self.check, self.source)
+        expected = git_mod.EAPIChangeWithoutRevbump(pkg=CPV("cat/pkg-1"))
+        assert r == expected
+
 
 class TestGitEclassCommitsCheck(ReportTestCase):
     check_kls = git_mod.GitEclassCommitsCheck

Reply via email to