Skip to content

Commit 4cc2407

Browse files
MarcelGeoCopilot
andcommitted
Fix for unfinished pull in subfolders
Co-authored-by: Copilot <copilot@github.com>
1 parent fd0381b commit 4cc2407

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

mergin/merginproject.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,23 +1042,22 @@ def resolve_unfinished_pull(self, user_name):
10421042

10431043
self.log.info("resolving unfinished pull")
10441044

1045-
temp_dir = tempfile.mkdtemp(prefix="python-api-client-")
1046-
10471045
for root, dirs, files in os.walk(self.unfinished_pull_dir):
10481046
for file_name in files:
10491047
src = os.path.join(root, file_name)
1050-
dest = self.fpath(file_name)
1051-
basefile = self.fpath_meta(file_name)
1048+
file_path = os.path.relpath(src, self.unfinished_pull_dir)
1049+
dest = self.fpath(file_path)
1050+
basefile = self.fpath_meta(file_path)
10521051

1053-
self.log.info("trying to resolve unfinished pull for: " + file_name)
1052+
self.log.info("trying to resolve unfinished pull for: " + file_path)
10541053

10551054
# 'src' here is a server version of the file from unfinished
10561055
# pull and 'dest' is a local version of the same file.
10571056
# to resolve unfinished pull we create a conflicted copy and
10581057
# replace local file with the changes from the server.
10591058
try:
10601059
# conflicted copy
1061-
conflict = self.create_conflicted_copy(dest, user_name)
1060+
conflict = self.create_conflicted_copy(file_path, user_name)
10621061
conflicts.append(conflict)
10631062
# original file synced with server
10641063
self.geodiff.make_copy_sqlite(src, basefile)

mergin/test/test_client.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,17 +1973,15 @@ def test_unfinished_pull(mc):
19731973
project = create_project_path(test_project, mc)
19741974
project_dir = os.path.join(TMP_DIR, test_project) # primary project dir
19751975
project_dir_2 = os.path.join(TMP_DIR, test_project + "_2") # concurrent project dir
1976-
unfinished_pull_dir = os.path.join(
1977-
TMP_DIR, test_project, ".mergin", "unfinished_pull"
1978-
) # unfinished_pull dir for the primary project
1979-
test_gpkg = os.path.join(project_dir, "test.gpkg")
1980-
test_gpkg_2 = os.path.join(project_dir_2, "test.gpkg")
1981-
test_gpkg_basefile = os.path.join(project_dir, ".mergin", "test.gpkg")
1976+
test_gpkg = os.path.join(project_dir, "subfolder", "test.gpkg")
1977+
test_gpkg_2 = os.path.join(project_dir_2, "subfolder", "test.gpkg")
1978+
test_gpkg_basefile = os.path.join(project_dir, ".mergin", "subfolder", "test.gpkg")
19821979
test_gpkg_conflict = conflicted_copy_file_name(test_gpkg, mc.username(), 2)
1983-
test_gpkg_unfinished_pull = os.path.join(project_dir, ".mergin", "unfinished_pull", "test.gpkg")
1980+
test_gpkg_unfinished_pull = os.path.join(project_dir, ".mergin", "unfinished_pull", "subfolder", "test.gpkg")
19841981
cleanup(mc, project, [project_dir, project_dir_2])
19851982

19861983
os.makedirs(project_dir)
1984+
os.makedirs(os.path.join(project_dir, "subfolder"), exist_ok=True)
19871985
shutil.copy(os.path.join(TEST_DATA_DIR, "base.gpkg"), test_gpkg)
19881986
_use_wal(test_gpkg) # make sure we use WAL, that's the more common and more difficult scenario
19891987
mc.create_project_and_push(project, project_dir)
@@ -1998,8 +1996,8 @@ def test_unfinished_pull(mc):
19981996
_use_wal(test_gpkg) # make sure we use WAL
19991997

20001998
pull_changes, push_changes, _ = mc.project_status(project_dir)
2001-
assert _is_file_updated("test.gpkg", pull_changes)
2002-
assert _is_file_updated("test.gpkg", push_changes)
1999+
assert _is_file_updated("subfolder/test.gpkg", pull_changes)
2000+
assert _is_file_updated("subfolder/test.gpkg", push_changes)
20032001

20042002
assert not os.path.exists(test_gpkg_conflict)
20052003
assert not mc.has_unfinished_pull(project_dir)
@@ -2050,6 +2048,9 @@ def test_unfinished_pull(mc):
20502048
assert _get_table_row_count(test_gpkg_basefile, "simple") == 3
20512049
assert _get_table_row_count(test_gpkg_conflict, "simple") == 4
20522050

2051+
mc.push_project(project_dir)
2052+
mc.push_project(project_dir_2)
2053+
20532054

20542055
@pytest.mark.skipif(sudo_works(), reason="needs working sudo")
20552056
def test_unfinished_pull_push(mc):

0 commit comments

Comments
 (0)