def test_basic_local_update_patch_content_with_metadata_and_patch_ignored( 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\nignore: true", ) 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() 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 + + %description """ assert patches in git_diff
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() == ""
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() == ""
def sourcegit_n_distgit(tmpdir): temp_dir = Path(str(tmpdir)) sourcegit_remote = temp_dir / "source_git_remote" sourcegit_remote.mkdir() subprocess.check_call(["git", "init", "--bare", "."], cwd=sourcegit_remote) sourcegit_dir = temp_dir / "source_git" shutil.copytree(SOURCEGIT_UPSTREAM, sourcegit_dir) initiate_git_repo(sourcegit_dir, tag="0.1.0") subprocess.check_call(["cp", "-R", SOURCEGIT_SOURCEGIT, temp_dir], cwd=sourcegit_remote) git_add_and_commit(directory=sourcegit_dir, message="sourcegit content") distgit_dir = temp_dir / "dist_git" shutil.copytree(DISTGIT, distgit_dir) initiate_git_repo(distgit_dir, push=True, upstream_remote=str(sourcegit_remote)) prepare_dist_git_repo(distgit_dir) return sourcegit_dir, distgit_dir
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-downstream 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
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
def upstream_instance_with_two_commits(upstream_instance): u, ups = upstream_instance new_file = u / "new.file" new_file.write_text("Some content") git_add_and_commit(u, message="Add new file") return u, ups
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) 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") spec = Specfile(str(distgit / "beer.spec")) spec_package_section = "" for section in spec.spec_content.sections: if "%package" in section[0]: spec_package_section += "\n".join(section[1]) assert "Patch0001: 0001" in spec_package_section assert "Patch0002: 0002" not in spec_package_section # no empty patches git_diff = subprocess.check_output(["git", "diff", "HEAD~", "HEAD"], cwd=distgit).decode() assert "-Version: 0.0.0\n+Version: 0.1.0" in git_diff assert "+# PATCHES FROM SOURCE GIT:" in git_diff assert ( " - 0.1.0-1\n" "+- new upstream release: 0.1.0\n" "+\n" " * Sun Feb 24 2019 Tomas Tomecek <*****@*****.**> - 0.0.0-1\n" " - No brewing, yet.\n" in git_diff) # direct diff in the synced file assert ("diff --git a/.packit.yaml b/.packit.yaml\n" "new file mode 100644" in git_diff) assert "--- /dev/null\n" "+++ 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\n" "+new file mode 100644\n" not in git_diff) # diff of the source file (not synced) has to be in the patch assert ("patch\n" "@@ -0,0 +1,9 @@\n" "+diff --git a/big-source-file.txt b/big-source-file.txt\n" in git_diff) assert ("+--- a/big-source-file.txt\n" "++++ b/big-source-file.txt\n" "+@@ -1,2 +1 @@\n" "+-This is a testing file\n" "+-containing some text.\n" "++new changes\n" in git_diff) # diff of the source files (not synced) should not be directly in the git diff assert ("--- a/big-source-file.txt\n" "+++ b/big-source-file.txt\n" "@@ -1,2 +1 @@\n" "-This is a testing file\n" "-containing some text.\n" "+new changes\n" not in git_diff) # ignored file should not be in the diff assert "--- a/ignored_file.txt\n" not in git_diff
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) 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 ) assert ( """ +# PATCHES FROM SOURCE GIT: + +# source change +# Author: Packit Test Suite <*****@*****.**> +Patch0001: 0001-source-change.patch + + %description """ in git_diff ) assert "Patch0002:" not in git_diff # no empty patches assert ( """ %prep -%autosetup -n %{upstream_name}-%{version} +%autosetup -p1 -n %{upstream_name}-%{version}""" 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 ) # diff of the source file (not synced) has to be in the patch assert ( """ +Subject: [PATCH] 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 ) 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 ( """ --- a/big-source-file.txt +++ b/big-source-file.txt @@ -1,2 +1 @@ -This is a testing file -containing some text. +new changes""" not in git_diff ) # ignored file should not be in the diff assert "--- a/ignored_file.txt\n" not in git_diff
def test_basic_local_update_patch_content( 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 commit origin is not marked when 'mark_commit_origin' is set to False. """ 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( dist_git_branch="main", version="0.1.0", upstream_ref="0.1.0", mark_commit_origin=False, ) git_diff = subprocess.check_output(["git", "diff", "HEAD~", "HEAD"], cwd=distgit).decode() assert "From-source-git-commit" not in git.Repo( distgit).head.commit.message assert (""" -Version: 0.0.0 +Version: 0.1.0""" in git_diff) # Make sure the patches are placed after Source0, but outside %if %endif patches = """\ Source0: %{upstream_name}-%{version}.tar.gz %endif +# 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 BuildArch: noarch """ assert patches in git_diff assert "Patch0004:" not in git_diff assert (""" - 0.1.0-1 +- Initial brewing + * Sun Feb 24 2019 Tomas Tomecek <*****@*****.**> - 0.0.0-1 - No brewing, yet.""" 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