From 4cc2407ac5646a7fa3d6c67c0795294d00d4893e Mon Sep 17 00:00:00 2001 From: "marcel.kocisek" Date: Tue, 12 May 2026 16:20:16 +0200 Subject: [PATCH] Fix for unfinished pull in subfolders Co-authored-by: Copilot --- mergin/merginproject.py | 11 +++++------ mergin/test/test_client.py | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/mergin/merginproject.py b/mergin/merginproject.py index f9312fa..87f3c5f 100644 --- a/mergin/merginproject.py +++ b/mergin/merginproject.py @@ -1042,15 +1042,14 @@ def resolve_unfinished_pull(self, user_name): self.log.info("resolving unfinished pull") - temp_dir = tempfile.mkdtemp(prefix="python-api-client-") - for root, dirs, files in os.walk(self.unfinished_pull_dir): for file_name in files: src = os.path.join(root, file_name) - dest = self.fpath(file_name) - basefile = self.fpath_meta(file_name) + file_path = os.path.relpath(src, self.unfinished_pull_dir) + dest = self.fpath(file_path) + basefile = self.fpath_meta(file_path) - self.log.info("trying to resolve unfinished pull for: " + file_name) + self.log.info("trying to resolve unfinished pull for: " + file_path) # 'src' here is a server version of the file from unfinished # pull and 'dest' is a local version of the same file. @@ -1058,7 +1057,7 @@ def resolve_unfinished_pull(self, user_name): # replace local file with the changes from the server. try: # conflicted copy - conflict = self.create_conflicted_copy(dest, user_name) + conflict = self.create_conflicted_copy(file_path, user_name) conflicts.append(conflict) # original file synced with server self.geodiff.make_copy_sqlite(src, basefile) diff --git a/mergin/test/test_client.py b/mergin/test/test_client.py index 1c02883..bd987d0 100644 --- a/mergin/test/test_client.py +++ b/mergin/test/test_client.py @@ -1973,17 +1973,15 @@ def test_unfinished_pull(mc): project = create_project_path(test_project, mc) project_dir = os.path.join(TMP_DIR, test_project) # primary project dir project_dir_2 = os.path.join(TMP_DIR, test_project + "_2") # concurrent project dir - unfinished_pull_dir = os.path.join( - TMP_DIR, test_project, ".mergin", "unfinished_pull" - ) # unfinished_pull dir for the primary project - test_gpkg = os.path.join(project_dir, "test.gpkg") - test_gpkg_2 = os.path.join(project_dir_2, "test.gpkg") - test_gpkg_basefile = os.path.join(project_dir, ".mergin", "test.gpkg") + test_gpkg = os.path.join(project_dir, "subfolder", "test.gpkg") + test_gpkg_2 = os.path.join(project_dir_2, "subfolder", "test.gpkg") + test_gpkg_basefile = os.path.join(project_dir, ".mergin", "subfolder", "test.gpkg") test_gpkg_conflict = conflicted_copy_file_name(test_gpkg, mc.username(), 2) - test_gpkg_unfinished_pull = os.path.join(project_dir, ".mergin", "unfinished_pull", "test.gpkg") + test_gpkg_unfinished_pull = os.path.join(project_dir, ".mergin", "unfinished_pull", "subfolder", "test.gpkg") cleanup(mc, project, [project_dir, project_dir_2]) os.makedirs(project_dir) + os.makedirs(os.path.join(project_dir, "subfolder"), exist_ok=True) shutil.copy(os.path.join(TEST_DATA_DIR, "base.gpkg"), test_gpkg) _use_wal(test_gpkg) # make sure we use WAL, that's the more common and more difficult scenario mc.create_project_and_push(project, project_dir) @@ -1998,8 +1996,8 @@ def test_unfinished_pull(mc): _use_wal(test_gpkg) # make sure we use WAL pull_changes, push_changes, _ = mc.project_status(project_dir) - assert _is_file_updated("test.gpkg", pull_changes) - assert _is_file_updated("test.gpkg", push_changes) + assert _is_file_updated("subfolder/test.gpkg", pull_changes) + assert _is_file_updated("subfolder/test.gpkg", push_changes) assert not os.path.exists(test_gpkg_conflict) assert not mc.has_unfinished_pull(project_dir) @@ -2050,6 +2048,9 @@ def test_unfinished_pull(mc): assert _get_table_row_count(test_gpkg_basefile, "simple") == 3 assert _get_table_row_count(test_gpkg_conflict, "simple") == 4 + mc.push_project(project_dir) + mc.push_project(project_dir_2) + @pytest.mark.skipif(sudo_works(), reason="needs working sudo") def test_unfinished_pull_push(mc):