|
1 | 1 | from functools import partial |
| 2 | +from typing import Set |
2 | 3 | from unittest.mock import patch |
3 | 4 |
|
4 | 5 | import pytest |
@@ -44,6 +45,55 @@ def test_atom_target(self, repo, capsys, tool): |
44 | 45 | matches = [x.cpvstr for x in repo.itermatch(options.restriction)] |
45 | 46 | assert matches == ['cat/pkg-0'] |
46 | 47 |
|
| 48 | + def test_if_modified_target(self, repo, make_git_repo, tool): |
| 49 | + def manifest_matches() -> Set[str]: |
| 50 | + repo.sync() |
| 51 | + with chdir(repo.location): |
| 52 | + options, _ = tool.parse_args(['manifest', '--if-modified']) |
| 53 | + return {x.cpvstr for x in repo.itermatch(options.restriction)} |
| 54 | + |
| 55 | + git_repo = make_git_repo(repo.location) |
| 56 | + repo.create_ebuild('cat/oldpkg-0') |
| 57 | + git_repo.add_all('cat/oldpkg-0') |
| 58 | + |
| 59 | + # New package |
| 60 | + repo.create_ebuild('cat/newpkg-0') |
| 61 | + assert manifest_matches() == {'cat/newpkg-0'} |
| 62 | + git_repo.add_all('cat/newpkg-0') |
| 63 | + |
| 64 | + # Untracked file |
| 65 | + ebuild_path = repo.create_ebuild('cat/newpkg-1') |
| 66 | + assert manifest_matches() == {'cat/newpkg-1'} |
| 67 | + |
| 68 | + # Staged file |
| 69 | + git_repo.add(ebuild_path, commit=False) |
| 70 | + assert manifest_matches() == {'cat/newpkg-1'} |
| 71 | + |
| 72 | + # No modified files |
| 73 | + git_repo.add_all('cat/newpkg-1') |
| 74 | + assert manifest_matches() == set() |
| 75 | + |
| 76 | + # Modified file |
| 77 | + ebuild_path = repo.create_ebuild('cat/newpkg-1', eapi=8) |
| 78 | + assert manifest_matches() == {'cat/newpkg-1'} |
| 79 | + git_repo.add_all('cat/newpkg-1: eapi 8') |
| 80 | + |
| 81 | + # Renamed file |
| 82 | + git_repo.remove(ebuild_path, commit=False) |
| 83 | + ebuild_path = repo.create_ebuild('cat/newpkg-2') |
| 84 | + git_repo.add(ebuild_path, commit=False) |
| 85 | + assert manifest_matches() == {'cat/newpkg-2'} |
| 86 | + git_repo.add_all('cat/newpkg-2: rename') |
| 87 | + |
| 88 | + # Deleted file |
| 89 | + git_repo.remove(ebuild_path, commit=False) |
| 90 | + assert manifest_matches() == set() |
| 91 | + |
| 92 | + # Deleted package |
| 93 | + ebuild_path = repo.create_ebuild('cat/newpkg-0') |
| 94 | + git_repo.remove(ebuild_path, commit=False) |
| 95 | + assert manifest_matches() == set() |
| 96 | + |
47 | 97 | def test_non_repo_dir_target(self, tmp_path, repo, capsys, tool): |
48 | 98 | with pytest.raises(SystemExit) as excinfo, \ |
49 | 99 | chdir(repo.location): |
|
0 commit comments