Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion rpmautospec/subcommands/process_distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def do_process_distgit(
target = processor.specfile
else:
target = Path(target)
if target.is_dir():
target /= processor.specfile.name

# Preserve mode of the target spec file if it is overwritten, otherwise use that of the
# processed spec file. Otherwise it would inherit the 0600 mode of the temporary file.
Expand Down Expand Up @@ -146,7 +148,7 @@ def do_process_distgit(

@click.command()
@click.argument("spec_or_path", type=click.Path())
@click.argument("target", type=click.Path())
@click.argument("target", type=click.Path(), required=False)
@click.pass_obj
@handle_expected_exceptions
def process_distgit(obj: dict[str, Any], spec_or_path: Path, target: Path) -> None:
Expand Down
21 changes: 16 additions & 5 deletions tests/rpmautospec/subcommands/test_process_distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import tarfile
import tempfile
from contextlib import nullcontext
from enum import Enum
from pathlib import Path
from subprocess import check_output, run
from unittest import mock
Expand All @@ -20,6 +21,11 @@
__HERE__.parent.parent / "test-data" / "repodata" / "dummy-test-package-gloster-git.tar.gz"
)

class TargetType(Enum):
NONE = None
FILE = 1
DIRECTORY = 2


@contextlib.contextmanager
def temporary_cd(path: str):
Expand Down Expand Up @@ -216,8 +222,8 @@ def run_git_amend(worktree_dir):
)
@pytest.mark.parametrize(
"overwrite_specfile",
(False, True),
ids=("without-overwrite-specfile", "with-overwrite-specfile"),
(TargetType.NONE, TargetType.FILE, TargetType.DIRECTORY),
ids=("without-overwrite-specfile", "with-overwrite-specfile-with-file", "with-overwrite-specfile-with-directory"),
)
@pytest.mark.parametrize("dirty_worktree", (False, True), ids=("clean-worktree", "dirty-worktree"))
@pytest.mark.parametrize("bump_release", (0, 15), ids=("without-bump-release", "with-bump-release"))
Expand Down Expand Up @@ -287,10 +293,12 @@ def test_do_process_distgit(
) and not dirty_worktree:
run_git_amend(unpacked_repo_dir)

if overwrite_specfile:
if overwrite_specfile == TargetType.NONE:
target_spec_file_path = None
else:
elif overwrite_specfile == TargetType.FILE:
target_spec_file_path = tmp_path / "test-this-specfile-please.spec"
else:
target_spec_file_path = tmp_path

orig_test_spec_file_stat = test_spec_file_path.stat()

Expand Down Expand Up @@ -412,7 +420,10 @@ def wrap_cls(*args, **kwargs):
]

if target_spec_file_path:
test_cmd = rpm_cmd + [target_spec_file_path]
if target_spec_file_path.is_dir():
test_cmd = rpm_cmd + [target_spec_file_path / test_spec_file_path.name]
else:
test_cmd = rpm_cmd + [target_spec_file_path]
else:
test_cmd = rpm_cmd + [test_spec_file_path]
expected_cmd = rpm_cmd + [expected_spec_file_path]
Expand Down