commit:     6cf5a11fc6ff12af7c62e13329694f3c22a5e32d
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 14 19:21:07 2022 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Fri Oct 14 19:34:13 2022 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgdev.git/commit/?id=6cf5a11f

manifest: better handling of path target

When passing a `.` path while inside a package directory, it passed to
path restrict generator as a simple path, which resulted in broken
restrict which collected all ebuilds in the repository.

By using `os.path.relpath` to base of repository, we make sure the
correct path is passed and the correct restricts are generated.

Fixes: https://github.com/pkgcore/pkgdev/issues/85
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgdev/scripts/pkgdev_manifest.py |  2 ++
 tests/scripts/test_pkgdev_manifest.py | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/src/pkgdev/scripts/pkgdev_manifest.py 
b/src/pkgdev/scripts/pkgdev_manifest.py
index de36fcc..229238c 100644
--- a/src/pkgdev/scripts/pkgdev_manifest.py
+++ b/src/pkgdev/scripts/pkgdev_manifest.py
@@ -66,6 +66,8 @@ def _restrict_targets(repo, targets):
     for target in targets:
         if os.path.exists(target):
             try:
+                if target in repo:
+                    target = os.path.relpath(target, repo.location)
                 restrictions.append(repo.path_restrict(target))
             except ValueError as exc:
                 manifest.error(exc)

diff --git a/tests/scripts/test_pkgdev_manifest.py 
b/tests/scripts/test_pkgdev_manifest.py
index 0c1c8c8..2800236 100644
--- a/tests/scripts/test_pkgdev_manifest.py
+++ b/tests/scripts/test_pkgdev_manifest.py
@@ -24,6 +24,38 @@ class TestPkgdevManifestParseArgs:
         matches = [x.cpvstr for x in repo.itermatch(options.restriction)]
         assert matches == ['cat/pkg-0']
 
+    def test_repo_relative_pkg(self, repo, capsys, tool):
+        repo.create_ebuild('cat/pkg-0')
+        repo.create_ebuild('cat/newpkg-0')
+        with chdir(pjoin(repo.location, 'cat/pkg')):
+            options, _ = tool.parse_args(['manifest', '.'])
+        matches = [x.cpvstr for x in repo.itermatch(options.restriction)]
+        assert matches == ['cat/pkg-0']
+
+    def test_repo_relative_category(self, repo, capsys, tool):
+        repo.create_ebuild('cat/pkg-0')
+        repo.create_ebuild('cat/newpkg-0')
+
+        with chdir(pjoin(repo.location, 'cat')):
+            options, _ = tool.parse_args(['manifest', 'pkg'])
+        matches = [x.cpvstr for x in repo.itermatch(options.restriction)]
+        assert matches == ['cat/pkg-0']
+
+        with chdir(pjoin(repo.location, 'cat')):
+            options, _ = tool.parse_args(['manifest', '.'])
+        matches = [x.cpvstr for x in repo.itermatch(options.restriction)]
+        assert set(matches) == {'cat/pkg-0', 'cat/newpkg-0'}
+
+    def test_repo_relative_outside(self, tmp_path, repo, capsys, tool):
+        repo.create_ebuild('cat/pkg-0')
+        (ebuild := tmp_path / 'pkg.ebuild').touch()
+        with pytest.raises(SystemExit) as excinfo:
+            with chdir(repo.location):
+                tool.parse_args(['manifest', str(ebuild)])
+        assert excinfo.value.code == 2
+        out, err = capsys.readouterr()
+        assert err.strip() == f"pkgdev manifest: error: {repo.repo_id!r} repo 
doesn't contain: {str(ebuild)!r}"
+
     def test_dir_target(self, repo, capsys, tool):
         repo.create_ebuild('cat/pkg-0')
         with chdir(repo.location):

Reply via email to