Skip to content

Commit 6cf5a11

Browse files
committed
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: #85 Signed-off-by: Arthur Zamarin <[email protected]>
1 parent 8bdc31e commit 6cf5a11

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/pkgdev/scripts/pkgdev_manifest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def _restrict_targets(repo, targets):
6666
for target in targets:
6767
if os.path.exists(target):
6868
try:
69+
if target in repo:
70+
target = os.path.relpath(target, repo.location)
6971
restrictions.append(repo.path_restrict(target))
7072
except ValueError as exc:
7173
manifest.error(exc)

tests/scripts/test_pkgdev_manifest.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,38 @@ def test_repo_cwd(self, repo, capsys, tool):
2424
matches = [x.cpvstr for x in repo.itermatch(options.restriction)]
2525
assert matches == ['cat/pkg-0']
2626

27+
def test_repo_relative_pkg(self, repo, capsys, tool):
28+
repo.create_ebuild('cat/pkg-0')
29+
repo.create_ebuild('cat/newpkg-0')
30+
with chdir(pjoin(repo.location, 'cat/pkg')):
31+
options, _ = tool.parse_args(['manifest', '.'])
32+
matches = [x.cpvstr for x in repo.itermatch(options.restriction)]
33+
assert matches == ['cat/pkg-0']
34+
35+
def test_repo_relative_category(self, repo, capsys, tool):
36+
repo.create_ebuild('cat/pkg-0')
37+
repo.create_ebuild('cat/newpkg-0')
38+
39+
with chdir(pjoin(repo.location, 'cat')):
40+
options, _ = tool.parse_args(['manifest', 'pkg'])
41+
matches = [x.cpvstr for x in repo.itermatch(options.restriction)]
42+
assert matches == ['cat/pkg-0']
43+
44+
with chdir(pjoin(repo.location, 'cat')):
45+
options, _ = tool.parse_args(['manifest', '.'])
46+
matches = [x.cpvstr for x in repo.itermatch(options.restriction)]
47+
assert set(matches) == {'cat/pkg-0', 'cat/newpkg-0'}
48+
49+
def test_repo_relative_outside(self, tmp_path, repo, capsys, tool):
50+
repo.create_ebuild('cat/pkg-0')
51+
(ebuild := tmp_path / 'pkg.ebuild').touch()
52+
with pytest.raises(SystemExit) as excinfo:
53+
with chdir(repo.location):
54+
tool.parse_args(['manifest', str(ebuild)])
55+
assert excinfo.value.code == 2
56+
out, err = capsys.readouterr()
57+
assert err.strip() == f"pkgdev manifest: error: {repo.repo_id!r} repo doesn't contain: {str(ebuild)!r}"
58+
2759
def test_dir_target(self, repo, capsys, tool):
2860
repo.create_ebuild('cat/pkg-0')
2961
with chdir(repo.location):

0 commit comments

Comments
 (0)