Ejemplo n.º 1
0
def test_basic_local_update_without_patching(
    sourcegit_and_remote,
    distgit_and_remote,
    mock_remote_functionality_sourcegit,
    api_instance_source_git,
):
    """propose-downstream for sourcegit test: mock remote API, use local upstream and dist-git
    Check that the upstream commit hash is saved when 'mock_commit_origin' is set.
    """

    sourcegit, _ = sourcegit_and_remote
    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="0.1.0",
        mark_commit_origin=True,
    )

    assert (distgit / TARBALL_NAME).is_file()
    spec = Specfile(distgit / "beer.spec")
    assert spec.expanded_version == "0.1.0"
    assert (f"From-source-git-commit: {git.Repo(sourcegit).head.commit.hexsha}"
            in git.Repo(distgit).head.commit.message)
Ejemplo n.º 2
0
def test_local_update_generated_spec(cwd_upstream, api_instance,
                                     mock_remote_functionality_upstream):
    """Check that specfile can be generated on clone."""
    u, d, api = api_instance
    mock_spec_download_remote_s(d)
    flexmock(api).should_receive("init_kerberos_ticket").at_least().once()

    # Simulate generation by moving the spec to a different location
    current_spec_location = u / "beer.spec"
    new_spec_location = u / "tmp.spec"
    shutil.move(current_spec_location, new_spec_location)
    api.up.package_config.actions = {
        ActionName.post_upstream_clone:
        [f"mv {new_spec_location} {current_spec_location}"]
    }
    api.sync_release(dist_git_branch="main")

    assert (d / TARBALL_NAME).is_file()
    spec = Specfile(d / "beer.spec")
    assert spec.get_version() == "0.1.0"
    assert (d / "README.packit").is_file()
    # assert that we have changelog entries for both versions
    changelog = "\n".join(spec.spec_content.section("%changelog"))
    assert "0.0.0" in changelog
    assert "0.1.0" in changelog
Ejemplo n.º 3
0
def test_srpm_git_no_prefix_patches(mock_remote_functionality_sourcegit,
                                    api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, "0.1.0")

    with api_instance_source_git.up.specfile.sections() as sections:
        sections.package[10:10] = (
            "Patch1: amarillo.patch",
            "Patch2: citra.patch",
            "Patch8: malt.patch",
        )
        sections.prep[0:2] = [
            "%setup -n %{upstream_name}-%{version}",
            "%patch1 -p1",
            "%patch2 -p0",
            "%patch8 -p1",
        ]

    create_patch_mixed_history(sg_path)

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)

    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)

    assert {x.name
            for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == {
                "amarillo.patch",
                "citra.patch",
                "malt.patch",
            }
Ejemplo n.º 4
0
def test_srpm_add_patch_with_ids(mock_remote_functionality_sourcegit,
                                 api_instance_source_git):
    ref = "0.1.0"
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, ref)

    create_history_with_patch_ids(sg_path)

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)

    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)

    assert {x.name
            for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == {
                "amarillo.patch",
                "citra.patch",
                "malt.patch",
            }
    with api_instance_source_git.up.specfile.patches() as patches:
        assert patches[0].filename == "amarillo.patch"
        assert patches[0].number == 3
        assert patches[1].filename == "citra.patch"
        assert patches[1].number == 4
        assert patches[2].filename == "malt.patch"
        assert patches[2].number == 100
Ejemplo n.º 5
0
def test_srpm_empty_patch(mock_remote_functionality_sourcegit,
                          api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, "0.1.0")

    with api_instance_source_git.up.specfile.sections() as sections:
        sections.package[10:10] = (
            "Patch1: amarillo.patch",
            "Patch2: citra.patch",
            "Patch5: saaz.patch",
            "Patch8: malt.patch",
        )

    create_history_with_empty_commit(sg_path)

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)

    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)

    assert {x.name
            for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == {
                "amarillo.patch",
                "citra.patch",
                "saaz.patch",
                "malt.patch",
            }
    assert sg_path.joinpath(DISTRO_DIR, "saaz.patch").read_text() == ""
Ejemplo n.º 6
0
def test_srpm_merge_storm(mock_remote_functionality_sourcegit,
                          api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, "0.1.0")
    create_merge_commit_in_source_git(sg_path, go_nuts=True)

    # linearization creates a new branch, make some arbitrary moves to verify
    # we end up in the former branch after the build
    subprocess.check_call(["git", "checkout", "-B", "test-branch"],
                          cwd=sg_path)
    subprocess.check_call(["git", "checkout", "main"], cwd=sg_path)

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)
    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)
    branches = subprocess.check_output(
        ["git", "for-each-ref", "--format=%(refname:short)", "refs/heads/"],
        cwd=sg_path).split(b"\n")
    for b in branches:
        if b and b.startswith(b"packit-patches-"):
            break
    else:
        raise AssertionError(
            "packit-patches- branch was not found - this should trigger the linearization"
        )
    # make sure we are on the main branch
    assert ("main" == subprocess.check_output(
        ["git", "branch", "--show-current"], cwd=sg_path).decode().strip())
    assert {x.name
            for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == {
                "0001-MERGE-COMMIT.patch",
                "0002-ugly-merge-commit.patch",
            }
Ejemplo n.º 7
0
def test_srpm_git_am(mock_remote_functionality_sourcegit,
                     api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, "0.1.0")

    with api_instance_source_git.up.specfile.prep() as prep:
        prep.autosetup.options.S = "git_am"

    create_git_am_style_history(sg_path)

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)

    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)

    assert {x.name
            for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == {
                "citra.patch",
                "0001-m04r-malt.patch",
                "malt.patch",
            }
    run_prep_for_srpm(srpm_path)
    prep_root = sg_path.joinpath("beerware-0.1.0")
    assert prep_root.joinpath("malt").read_text() == "Munich\n"
    assert prep_root.joinpath("hops").read_text() == "Saaz\n"
Ejemplo n.º 8
0
def test_basic_local_update_empty_patch(
    distgit_and_remote,
    mock_remote_functionality_sourcegit,
    api_instance_source_git,
    ref,
):
    """ propose-update for sourcegit test: mock remote API, use local upstream and dist-git """

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

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

    spec_package_section = ""
    for section in spec.spec_content.sections:
        if "%package" in section[0]:
            spec_package_section += "\n".join(section[1])
    assert "# PATCHES FROM SOURCE GIT" not in spec_package_section
    assert not spec.patches["applied"]
    assert not spec.patches["not_applied"]
Ejemplo n.º 9
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.º 10
0
def test_srpm_merge_storm(mock_remote_functionality_sourcegit,
                          api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / "fedora", "0.1.0")
    create_merge_commit_in_source_git(sg_path, go_nuts=True)
    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)
    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)
    branches = subprocess.check_output(
        ["git", "for-each-ref", "--format=%(refname:short)", "refs/heads/"],
        cwd=sg_path).split(b"\n")
    for b in branches:
        if b and b.startswith(b"packit-patches-"):
            break
    else:
        raise AssertionError(
            "packit-patches- branch was not found - this should trigger the linearization"
        )
    assert {x.name
            for x in sg_path.joinpath("fedora").glob("*.patch")} == {
                "0001-MERGE-COMMIT.patch",
                "0002-ugly-merge-commit.patch",
            }
Ejemplo n.º 11
0
def test_basic_local_update_copy_upstream_release_description(
        cwd_upstream, api_instance, mock_remote_functionality_upstream):
    """basic propose-downstream test: mock remote API, use local upstream and dist-git,
    set copy_upstream_release_description in package config to True"""
    u, d, api = api_instance
    mock_spec_download_remote_s(d)
    flexmock(api).should_receive("init_kerberos_ticket").at_least().once()
    release = flexmock(body="Some description of the upstream release")
    api.up.local_project.git_project = flexmock(
        get_release=lambda name, tag_name: release)
    api.package_config.copy_upstream_release_description = True
    api.sync_release(dist_git_branch="main", version="0.1.0")

    assert (d / TARBALL_NAME).is_file()
    spec = Specfile(d / "beer.spec")
    assert spec.expanded_version == "0.1.0"
    assert (d / "README.packit").is_file()
    # assert that we have changelog entries for both versions
    with spec.sections() as sections:
        changelog = "\n".join(sections.changelog)

    assert ("""- 0.1.0-1
Some description of the upstream release
""" in changelog)

    assert "0.0.0" in changelog
    assert "0.1.0" in changelog
Ejemplo n.º 12
0
def test_basic_local_update_using_distgit(cwd_upstream, api_instance,
                                          mock_remote_functionality_upstream):
    """ basic propose-update test: mock remote API, use local upstream and dist-git """
    u, d, api = api_instance
    mock_spec_download_remote_s(d)

    api.sync_release(dist_git_branch="main", version="0.1.0")

    assert (d / TARBALL_NAME).is_file()
    spec = Specfile(d / "beer.spec")
    assert spec.get_version() == "0.1.0"

    package_section = spec.spec_content.section("%package")

    assert package_section[2] == "# some change"
    assert package_section[4] == "Name:           beer"
    assert package_section[5] == "Version:        0.1.0"
    assert package_section[6] == "Release:        1%{?dist}"
    assert package_section[7] == "Summary:        A tool to make you happy"

    assert (d / "README.packit").is_file()
    # assert that we have changelog entries for both versions
    changelog = "\n".join(spec.spec_content.section("%changelog"))
    assert "0.0.0" in changelog
    assert "0.1.0" in changelog
Ejemplo n.º 13
0
def test_srpm(mock_remote_functionality_sourcegit, api_instance_source_git):
    # TODO: we need a better test case here which will mimic the systemd use case
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path / "fedora")
    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref="0.1.0")
    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)
Ejemplo n.º 14
0
def test_basic_local_update_patch_content_with_metadata(
    sourcegit_and_remote,
    distgit_and_remote,
    mock_remote_functionality_sourcegit,
    api_instance_source_git,
):
    """ propose-update for sourcegit test: mock remote API, use local upstream and dist-git """

    sourcegit, _ = sourcegit_and_remote
    distgit, _ = distgit_and_remote
    mock_spec_download_remote_s(distgit)

    create_merge_commit_in_source_git(sourcegit)

    source_file = sourcegit / "big-source-file.txt"
    source_file.write_text("new changes")
    git_add_and_commit(
        directory=sourcegit,
        message="source change\n"
        "patch_name: testing.patch\n"
        "description: Few words for info.",
    )

    source_file = sourcegit / "ignored_file.txt"
    source_file.write_text(" And I am sad.")
    git_add_and_commit(directory=sourcegit, message="make a file sad")

    api_instance_source_git.sync_release(
        dist_git_branch="master",
        version="0.1.0",
        use_local_content=True,
        upstream_ref="0.1.0",
    )

    git_diff = subprocess.check_output(["git", "diff", "HEAD~", "HEAD"],
                                       cwd=distgit).decode()

    patches = """
+# PATCHES FROM SOURCE GIT:
+
+# switching to amarillo hops
+# Author: Packit Test Suite <*****@*****.**>
+Patch0001: 0001-switching-to-amarillo-hops.patch
+
+# actually, let's do citra
+# Author: Packit Test Suite <*****@*****.**>
+Patch0002: 0002-actually-let-s-do-citra.patch
+
+# source change
+# Author: Packit Test Suite <*****@*****.**>
+# Few words for info.
+Patch0003: testing.patch
+
+
 %description
"""
    assert patches in git_diff
Ejemplo n.º 15
0
def test_srpm(mock_remote_functionality_sourcegit, api_instance_source_git):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path / "fedora")
    create_merge_commit_in_source_git(sg_path)
    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref="0.1.0")
    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)
Ejemplo n.º 16
0
def test_srpm_merge_storm_dirty(api_instance_source_git):
    """verify the linearization is halted when a source-git repo si dirty"""
    ref = "0.1.0"
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, ref)
    create_merge_commit_in_source_git(sg_path, go_nuts=True)
    (sg_path / "malt").write_text("Mordor\n")
    with pytest.raises(PackitException) as ex:
        with cwd("/"):  # let's mimic p-s by having different cwd than the project
            api_instance_source_git.create_srpm(upstream_ref=ref)
    assert "The source-git repo is dirty" in str(ex.value)
Ejemplo n.º 17
0
def test_basic_local_update_reset_after_exception(
        cwd_upstream, api_instance, mock_remote_functionality_upstream):
    """ check whether the distgit repo is not dirty after exception is raised """
    u, d, api = api_instance
    mock_spec_download_remote_s(d)
    flexmock(api).should_receive("init_kerberos_ticket").at_least().once()
    flexmock(api).should_receive("_handle_sources").and_raise(Exception)
    with pytest.raises(Exception):
        api.sync_release("master", "0.1.0")

    assert not api.dg.is_dirty()
Ejemplo n.º 18
0
def test_linearization(api_instance_source_git):
    ref = "0.1.0"
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, ref)
    create_merge_commit_in_source_git(sg_path, go_nuts=True)
    with cwd("/"):  # let's mimic p-s by having different cwd than the project
        pg = PatchGenerator(api_instance_source_git.upstream_local_project)
        pg.create_patches(ref, sg_path / DISTRO_DIR)
    assert {x.name for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == {
        "0001-sourcegit-content.patch",
        "0002-MERGE-COMMIT.patch",
        "0003-ugly-merge-commit.patch",
    }
Ejemplo n.º 19
0
def test_basic_local_update(cwd_upstream, api_instance,
                            mock_remote_functionality_upstream):
    """ basic propose-update test: mock remote API, use local upstream and dist-git """
    u, d, api = api_instance
    mock_spec_download_remote_s(d)
    flexmock(api).should_receive("init_kerberos_ticket").at_least().once()

    api.sync_release("master", "0.1.0")

    assert (d / TARBALL_NAME).is_file()
    spec = Specfile(d / "beer.spec")
    assert spec.get_version() == "0.1.0"
    assert (d / "README.packit").is_file()
    # assert that we have changelog entries for both versions
    changelog = "\n".join(spec.spec_content.section("%changelog"))
    assert "0.0.0" in changelog
    assert "0.1.0" in changelog
Ejemplo n.º 20
0
def test_srpm_patch_non_conseq_indices(mock_remote_functionality_sourcegit,
                                       api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / "fedora", "0.1.0")

    api_instance_source_git.up.specfile.spec_content.section(
        "%package")[10:10] = (
            "Patch0: amarillo.patch",
            "Patch3: citra.patch",
            "Patch4: saaz.patch",
            "Patch5: malt.patch",
        )
    api_instance_source_git.up.specfile.save()

    create_history_with_empty_commit(sg_path)

    malt = sg_path.joinpath("malt")
    malt.write_text("Wheat\n")
    git_add_and_commit(directory=sg_path,
                       message="Weißbier! Summer is coming!")

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)

    # make sure the patch is inserted AFTER existing patches
    patches = api_instance_source_git.up.specfile.tags.filter(name="Patch*",
                                                              valid=None)
    last_patch = list(patches)[-1]
    assert last_patch.name == "Patch6"
    assert (os.path.basename(
        api_instance_source_git.up.specfile.get_applied_patches()[-1].path) ==
            "0004-Wei-bier-Summer-is-coming.patch")

    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)

    assert {x.name
            for x in sg_path.joinpath("fedora").glob("*.patch")} == {
                "amarillo.patch",
                "citra.patch",
                "saaz.patch",
                "malt.patch",
                "0004-Wei-bier-Summer-is-coming.patch",
            }
    assert sg_path.joinpath("fedora", "saaz.patch").read_text() == ""
Ejemplo n.º 21
0
def test_basic_local_update_without_patching(
    sourcegit_and_remote,
    distgit_and_remote,
    mock_patching,
    mock_remote_functionality_sourcegit,
    api_instance_source_git,
):
    """ propose-update for sourcegit test: mock remote API, use local upstream and dist-git """

    sourcegit, _ = sourcegit_and_remote
    distgit, _ = distgit_and_remote
    mock_spec_download_remote_s(distgit)

    api_instance_source_git.sync_release("master", "0.1.0", upstream_ref="0.1.0")

    assert (distgit / TARBALL_NAME).is_file()
    spec = Specfile(distgit / "beer.spec")
    assert spec.get_version() == "0.1.0"
Ejemplo n.º 22
0
def test_basic_local_update_direct_push(
    cwd_upstream, api_instance, distgit_and_remote, mock_remote_functionality_upstream
):
    """ basic propose-update test: mock remote API, use local upstream and dist-git """
    u, d, api = api_instance
    _, distgit_remote = distgit_and_remote
    mock_spec_download_remote_s(d)

    api.sync_release("master", "0.1.0", create_pr=False)

    remote_dir_clone = Path(f"{distgit_remote}-clone")
    subprocess.check_call(
        ["git", "clone", distgit_remote, str(remote_dir_clone)],
        cwd=str(remote_dir_clone.parent),
    )

    spec = Specfile(remote_dir_clone / "beer.spec")
    assert spec.get_version() == "0.1.0"
    assert (remote_dir_clone / "README.packit").is_file()
Ejemplo n.º 23
0
def test_srpm_patch_non_conseq_indices(mock_remote_functionality_sourcegit,
                                       api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, "0.1.0")

    with api_instance_source_git.up.specfile.sections() as sections:
        sections.package[10:10] = (
            "Patch0: amarillo.patch",
            "Patch3: citra.patch",
            "Patch4: saaz.patch",
            "Patch5: malt.patch",
        )

    create_history_with_empty_commit(sg_path)

    malt = sg_path.joinpath("malt")
    malt.write_text("Wheat\n")
    git_add_and_commit(directory=sg_path,
                       message="Weißbier! Summer is coming!")

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)

    # make sure the patch is inserted AFTER existing patches
    with api_instance_source_git.up.specfile.patches() as patches:
        last_patch = patches[-1]
    assert last_patch.number == 6
    assert last_patch.filename == "0004-Wei-bier-Summer-is-coming.patch"

    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)

    assert {x.name
            for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == {
                "amarillo.patch",
                "citra.patch",
                "saaz.patch",
                "malt.patch",
                "0004-Wei-bier-Summer-is-coming.patch",
            }
    assert sg_path.joinpath(DISTRO_DIR, "saaz.patch").read_text() == ""
Ejemplo n.º 24
0
def test_srpm(mock_remote_functionality_sourcegit, api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, "0.1.0")
    create_merge_commit_in_source_git(sg_path)
    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)
    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)
    branches = subprocess.check_output(
        ["git", "for-each-ref", "--format=%(refname:short)", "refs/heads/"], cwd=sg_path
    ).split(b"\n")
    for b in branches:
        if b and b.startswith(b"packit-patches-"):
            raise AssertionError(
                "packit-patches- branch was found - the history shouldn't have been linearized"
            )
    assert {x.name for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == {
        "0001-switching-to-amarillo-hops.patch",
        "0002-actually-let-s-do-citra.patch",
    }
Ejemplo n.º 25
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"""

    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.get_version() == "0.1.0"

    assert not spec.patches["applied"]
    assert not spec.patches["not_applied"]
Ejemplo n.º 26
0
def test_basic_local_update_direct_push_no_dg_spec(
    cwd_upstream, api_instance, distgit_and_remote, mock_remote_functionality_upstream
):
    u, d, api = api_instance
    d.joinpath("beer.spec").unlink()
    subprocess.check_call(
        ["git", "commit", "-m", "remove spec", "-a"], cwd=str(d),
    )
    _, distgit_remote = distgit_and_remote
    mock_spec_download_remote_s(d)

    api.sync_release("master", "0.1.0", create_pr=False)

    remote_dir_clone = Path(f"{distgit_remote}-clone")
    subprocess.check_call(
        ["git", "clone", distgit_remote, str(remote_dir_clone)],
        cwd=str(remote_dir_clone.parent),
    )

    spec = Specfile(remote_dir_clone / "beer.spec")
    assert spec.get_version() == "0.1.0"
    assert (remote_dir_clone / "README.packit").is_file()
Ejemplo n.º 27
0
def test_basic_local_update_patch_content_with_downstream_patch(
    sourcegit_and_remote,
    distgit_and_remote,
    mock_remote_functionality_sourcegit,
    api_instance_source_git,
):
    """ propose-update for sourcegit test: mock remote API, use local upstream and dist-git """

    sourcegit, _ = sourcegit_and_remote
    distgit, _ = distgit_and_remote
    mock_spec_download_remote_s(distgit)

    create_merge_commit_in_source_git(sourcegit)

    source_file = sourcegit / "ignored_file.txt"
    source_file.write_text(" And I am sad.")
    git_add_and_commit(directory=sourcegit, message="make a file sad")

    api_instance_source_git.sync_release(
        dist_git_branch="main",
        version="0.1.0",
        upstream_ref="0.1.0",
    )

    git_diff = subprocess.check_output(["git", "diff", "HEAD~", "HEAD"],
                                       cwd=distgit).decode()

    patches = """
+# switching to amarillo hops
+# Author: Packit Test Suite <*****@*****.**>
+Patch0001: 0001-switching-to-amarillo-hops.patch
+
+# actually, let's do citra
+# Author: Packit Test Suite <*****@*****.**>
+Patch0002: 0002-actually-let-s-do-citra.patch
+
+
"""
    assert patches in git_diff
Ejemplo n.º 28
0
def check_ready_api_sg_first(
    sourcegit_and_remote,
    distgit_and_remote,
    mock_remote_functionality_sourcegit,
    api_instance_update_source_git,
) -> PackitAPI:
    """Fixture returning an API instance where dist-git and source-git
    repos contain commits with git-trailers. The latest trailing commit
    is dist-git update (From-source-git trailer)."""
    sourcegit, _ = sourcegit_and_remote
    distgit, _ = distgit_and_remote
    (distgit / "file").write_text("foo")
    api_instance_update_source_git.dg.commit("add new file", "")
    api_instance_update_source_git.update_source_git("HEAD~..")
    mock_spec_download_remote_s(distgit)
    api_instance_update_source_git.sync_release(
        dist_git_branch="main",
        version="0.1.0",
        upstream_ref="0.1.0",
        mark_commit_origin=True,
    )
    return api_instance_update_source_git
Ejemplo n.º 29
0
def test_srpm_git_am(mock_remote_functionality_sourcegit,
                     api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / "fedora", "0.1.0")

    api_instance_source_git.up.specfile.spec_content.section(
        "%package")[10:10] = (
            "Patch1: citra.patch",
            "Patch2: malt.patch",
            "Patch8: 0001-m04r-malt.patch",
        )
    autosetup_line = api_instance_source_git.up.specfile.spec_content.section(
        "%prep")[0]
    autosetup_line = autosetup_line.replace("-S patch", "-S git_am")
    api_instance_source_git.up.specfile.spec_content.section(
        "%prep")[0] = autosetup_line
    api_instance_source_git.up.specfile.save()

    create_git_am_style_history(sg_path)

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)

    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)

    assert {x.name
            for x in sg_path.joinpath("fedora").glob("*.patch")} == {
                "citra.patch",
                "0001-m04r-malt.patch",
                "malt.patch",
            }
    run_prep_for_srpm(srpm_path)
    prep_root = sg_path.joinpath("beerware-0.1.0")
    assert prep_root.joinpath("malt").read_text() == "Munich\n"
    assert prep_root.joinpath("hops").read_text() == "Saaz\n"
Ejemplo n.º 30
0
def test_basic_local_update_patch_content(
    sourcegit_and_remote,
    distgit_and_remote,
    mock_remote_functionality_sourcegit,
    api_instance_source_git,
):
    """ propose-update for sourcegit test: mock remote API, use local upstream and dist-git """

    sourcegit, _ = sourcegit_and_remote
    distgit, _ = distgit_and_remote
    mock_spec_download_remote_s(distgit)

    create_merge_commit_in_source_git(sourcegit)

    source_file = sourcegit / "big-source-file.txt"
    source_file.write_text("new changes")
    git_add_and_commit(directory=sourcegit, message="source change")

    source_file = sourcegit / "ignored_file.txt"
    source_file.write_text(" And I am sad.")
    git_add_and_commit(directory=sourcegit, message="make a file sad")

    api_instance_source_git.sync_release("master",
                                         "0.1.0",
                                         upstream_ref="0.1.0")

    git_diff = subprocess.check_output(["git", "diff", "HEAD~", "HEAD"],
                                       cwd=distgit).decode()
    assert ("""
-Version:        0.0.0
+Version:        0.1.0""" in git_diff)

    patches = """
+# PATCHES FROM SOURCE GIT:
+
+# switching to amarillo hops
+# Author: Packit Test Suite <*****@*****.**>
+Patch0001: 0001-switching-to-amarillo-hops.patch
+
+# actually, let's do citra
+# Author: Packit Test Suite <*****@*****.**>
+Patch0002: 0002-actually-let-s-do-citra.patch
+
+# source change
+# Author: Packit Test Suite <*****@*****.**>
+Patch0003: 0003-source-change.patch
+
+
 %description
"""
    assert patches in git_diff

    assert "Patch0004:" not in git_diff

    assert (""" - 0.1.0-1
+- new upstream release: 0.1.0
+
 * Sun Feb 24 2019 Tomas Tomecek <*****@*****.**> - 0.0.0-1
 - No brewing, yet.""" in git_diff)

    # direct diff in the synced file
    assert ("""diff --git a/.packit.yaml b/.packit.yaml
new file mode 100644""" in git_diff)

    assert ("""
--- /dev/null
+++ b/.packit.yaml""" in git_diff)

    # diff of the synced file should not be in the patch
    assert ("""
+diff --git a/.packit.yaml b/.packit.yaml
+new file mode 100644""" not in git_diff)

    patch_1_3 = """
+Subject: [PATCH 1/3] switching to amarillo hops
+
+---
+ hops | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/hops b/hops"""
    assert patch_1_3 in git_diff
    assert ("""\
+--- a/hops
++++ b/hops
+@@ -1 +1 @@
+-Cascade
++Amarillo
+--""" in git_diff)

    assert ("""\
+Subject: [PATCH 2/3] actually, let's do citra
+
+---
+ hops | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/hops b/hops""" in git_diff)
    assert (("""\
+--- a/hops
++++ b/hops
+@@ -1 +1 @@
+-Amarillo
++Citra
+--""") in git_diff)

    assert ("""
+--- a/big-source-file.txt
++++ b/big-source-file.txt
+@@ -1,2 +1 @@
+-This is a testing file
+-containing some text.
++new changes""" in git_diff)

    # diff of the source files (not synced) should not be directly in the git diff
    assert ("""
+Subject: [PATCH 3/3] source change
+
+---
+ big-source-file.txt | 3 +--
+ 1 file changed, 1 insertion(+), 2 deletions(-)
+
+diff --git a/big-source-file.txt b/big-source-file.txt""" in git_diff)

    # ignored file should not be in the diff
    assert "--- a/ignored_file.txt\n" not in git_diff