Ejemplo n.º 1
0
def test_basic_local_update_empty_patch(
    distgit_and_remote,
    mock_remote_functionality_sourcegit,
    api_instance_source_git,
    ref,
):
    """propose-downstream for sourcegit test: mock remote API, use local upstream and dist-git
    Check that by default commit origin is not marked in dist-git.
    """

    distgit, _ = distgit_and_remote
    mock_spec_download_remote_s(distgit)
    api_instance_source_git.sync_release(
        dist_git_branch="main",
        version="0.1.0",
        upstream_ref=ref,
    )

    assert (distgit / TARBALL_NAME).is_file()
    spec = Specfile(distgit / "beer.spec")
    assert spec.expanded_version == "0.1.0"

    with spec.patches() as patches:
        assert not patches
    assert "From-source-git-commit" not in git.Repo(
        distgit).head.commit.message
Ejemplo n.º 2
0
def test_patch_id_digits(specfile, lines, digits):
    """Check detecting the number of digits used for patch IDs (indices)"""
    content = specfile.read_text()
    content = content.replace("### patches ###\n", lines)
    specfile.write_text(content)
    spec = Specfile(specfile, sourcedir=specfile.parent, autosave=True)
    with spec.patches() as patches:
        assert patches[0].number_digits == digits
Ejemplo n.º 3
0
def test_read_patch_comments(specfile, lines, files, expectation):
    """Check reading comment lines that belong to patches"""
    content = specfile.read_text()
    content = content.replace("### patches ###\n", lines)
    specfile.write_text(content)
    for patch_file in files:
        Path(specfile.parent, patch_file).touch()
    spec = Specfile(specfile, sourcedir=specfile.parent, autosave=True)
    with spec.patches() as patches:
        comments = {p.filename: [c.text for c in p.comments] for p in patches}
        assert comments == expectation
Ejemplo n.º 4
0
    def create_from_upstream(self):
        """Create a source-git repo, by transforming downstream patches
        in Git commits applied on top of the selected upstream ref.
        """
        upstream_ref_sha = self.source_git.git.rev_list(
            "-1", self.upstream_ref)
        if upstream_ref_sha != self.source_git.head.commit.hexsha:
            raise PackitException(
                f"{self.upstream_ref!r} is not pointing to the current HEAD "
                f"in {self.source_git.working_dir!r}.")
        with self.dist_git_specfile.prep() as prep:
            if "%autosetup" not in prep:
                if not self.ignore_missing_autosetup:
                    raise PackitException(
                        "Initializing source-git repos for packages "
                        "not using %autosetup is not allowed by default. "
                        "You can use --ignore-missing-autosetup option to enforce "
                        "running the command without %autosetup.")
                logger.warning(
                    "Source-git repos for packages not using %autosetup may be not initialized"
                    "properly or may not work with other packit commands.")

        self._populate_distro_dir()
        self._reset_gitignore()
        self._configure_syncing()

        spec = Specfile(
            f"{self.distro_dir}/{self.pkg_name}.spec",
            sourcedir=self.dist_git.working_dir,
            autosave=True,
        )
        with spec.patches() as patches:
            patches.clear()

        self.source_git.git.stage(DISTRO_DIR, force=True)
        message = f"""Initialize as a source-git repository

{FROM_DIST_GIT_TOKEN}: {self.dist_git.head.commit.hexsha}
"""
        self.source_git.git.commit(message=message)

        pkg_tool = PkgTool(
            fas_username=self.config.fas_user,
            directory=self.dist_git.working_dir,
            tool=self.pkg_tool or self.config.pkg_tool,
        )
        pkg_tool.sources()
        self._run_prep()
        self._rebase_patches()
Ejemplo n.º 5
0
def test_remove_patches_no_blanklines(specfile):
    no_blanks = specfile.read_text().replace("\n\n", "\n")
    no_patches = no_blanks.replace("\n### patches ###\n", "\n")
    patches = no_blanks.replace(
        "### patches ###\n",
        """\
# Some comment line to be removed
Patch1: yellow.patch
Patch2: blue.patch
# One
# Or more lines
Patch : dark.patch
""",
    )
    specfile.write_text(patches)
    spec = Specfile(specfile, sourcedir=specfile.parent, autosave=True)
    with spec.patches() as patches:
        patches.clear()
    assert specfile.read_text() == no_patches