Repository: packit/packit
Issue: Additional options of files_to_sync ignored

For [this release](https://src.fedoraproject.org/rpms/python-scikit-build-core/pull-request/15), the `filters` were not propagated to the `rsync` command, see logs: https://dashboard.packit.dev/results/propose-downstream/2532.

I suspect this bug could be caused [in this place](https://github.com/packit/packit/blob/672eac32fd4f03f53ea5df760c2c48c6086feb7c/packit/sync.py#L177) (called from [here](https://github.com/packit/packit/blob/672eac32fd4f03f53ea5df760c2c48c6086feb7c/packit/api.py#L1006))  since only `src` and `dest` are defined in the new `SyncFilesItem` created there.

Changed files:
packit/sync.py, tests/unit/test_sync.py, tests/unit/test_api.py

diff --git a/packit/sync.py b/packit/sync.py
index 887354ff..861ca378 100644
--- a/packit/sync.py
+++ b/packit/sync.py
@@ -4,7 +4,7 @@
 """
 Functions and classes dealing with syncing files between repositories
 """
-
+import copy
 import os
 import glob
 import logging
@@ -174,7 +174,11 @@ class SyncFilesItem:
             Otherwise returns None.
         """
         new_src = [s for s in self.src if not criteria(s, src)]
-        return SyncFilesItem(new_src, self.dest) if new_src else None
+        if new_src:
+            self_copy = copy.copy(self)
+            self_copy.src = new_src
+            return self_copy
+        return None
 
 
 def iter_srcs(synced_files: Sequence[SyncFilesItem]) -> Iterator[str]:
diff --git a/tests/unit/test_api.py b/tests/unit/test_api.py
index cd87f91f..65d3a9b5 100644
--- a/tests/unit/test_api.py
+++ b/tests/unit/test_api.py
@@ -9,10 +9,14 @@ import pytest
 from flexmock import flexmock
 
 from packit.api import PackitAPI
+from packit.config import PackageConfig, CommonPackageConfig
 from packit.copr_helper import CoprHelper
 from packit.exceptions import PackitException
 from packit.local_project import LocalProjectBuilder
 from packit.patches import PatchGenerator
+from packit.sync import SyncFilesItem
+from packit.utils.changelog_helper import ChangelogHelper
+from packit import api as packit_api
 
 
 def build_dict(copr_url, id):
@@ -194,3 +198,53 @@ def test_dg_downstream_package_name_is_set(
     api_mock.package_config.downstream_package_name = downstream_package_name
     api_mock.downstream_local_project = LocalProjectBuilder().build(working_dir=path)
     assert api_mock.dg.package_config.downstream_package_name == expectation
+
+
+def test_sync_release_sync_files_call(config_mock, upstream_mock, distgit_mock):
+    pc = PackageConfig(
+        packages={
+            "package": CommonPackageConfig(
+                specfile_path="xxx",
+                files_to_sync=[
+                    SyncFilesItem(
+                        ["src/a"],
+                        "dest",
+                        filters=["dummy filter"],
+                        mkpath=True,
+                        delete=True,
+                    )
+                ],
+                upstream_package_name="test_package_name",
+                downstream_package_name="test_package_name",
+                upstream_tag_template="_",
+                upstream_project_url="_",
+                upstream_ref="_",
+            )
+        },
+    )
+    upstream_mock.package_config = pc
+    distgit_mock.package_config = pc
+    api = PackitAPI(config=config_mock, package_config=pc)
+    flexmock(api)
+    api._up = upstream_mock
+    api._dg = distgit_mock
+    api.should_receive("_handle_sources")
+    flexmock(PatchGenerator).should_receive("undo_identical")
+    flexmock(pathlib.Path).should_receive("write_text").once()
+    api.up.should_receive("get_specfile_version").and_return("0")
+    api.should_receive("push_and_create_pr").and_return(flexmock())
+    flexmock(ChangelogHelper).should_receive("update_dist_git")
+
+    flexmock(packit_api).should_receive("sync_files").with_args(
+        [
+            SyncFilesItem(
+                src=["/mock_dir/src/a"],
+                dest="/mock_dir/dest",
+                mkpath=True,
+                delete=True,
+                filters=["dummy filter"],
+            )
+        ]
+    )
+
+    api.sync_release(version="1.1", dist_git_branch="_")
diff --git a/tests/unit/test_sync.py b/tests/unit/test_sync.py
index 308dd33d..bd2503c2 100644
--- a/tests/unit/test_sync.py
+++ b/tests/unit/test_sync.py
@@ -62,6 +62,15 @@ def test_check_subpath(subpath, path, trailing_slash, result):
             {"src": "a", "criteria": lambda x, y: Path(x).name == y},
             SyncFilesItem(["src/b"], "dest"),
         ),
+        (
+            SyncFilesItem(
+                ["src/a"], "dest", filters=["dummy filter"], mkpath=True, delete=True
+            ),
+            {"src": "c"},
+            SyncFilesItem(
+                ["src/a"], "dest", filters=["dummy filter"], mkpath=True, delete=True
+            ),
+        ),
     ],
 )
 def test_drop_src(item, drop, result):