Skip to content

Commit 9c3dc16

Browse files
committed
Fix a problem when a pull of an empty project would break it
Initial download would save "v0" as the version, then pull was changing it to "" and afterwards push was crashing because it was expecting "v0"
1 parent 4c40878 commit 9c3dc16

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

mergin/client_pull.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def pull_project_finalize(job):
475475
conflicts = job.mp.apply_pull_changes(job.pull_changes, job.temp_dir)
476476
job.mp.metadata = {
477477
'name': job.project_path,
478-
'version': job.version,
478+
'version': job.version if job.version else "v0", # for new projects server version is ""
479479
'files': job.project_info['files']
480480
}
481481

mergin/test/test_client.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,30 @@ def test_force_gpkg_update(mc):
364364
f_remote = next((f for f in project_info['files'] if f['path'] == f_updated), None)
365365
assert f_remote['checksum'] == updated_checksum
366366
assert 'diff' not in f_remote
367+
368+
369+
def test_new_project_sync(mc):
370+
""" Create a new project, download it, add a file and then do sync - it should not fail """
371+
372+
test_project = 'test_new_project_sync'
373+
project = API_USER + '/' + test_project
374+
project_dir = os.path.join(TMP_DIR, test_project) # primary project dir for updates
375+
376+
cleanup(mc, project, [project_dir])
377+
# create remote project
378+
mc.create_project(test_project)
379+
380+
# download the project
381+
mc.download_project(project, project_dir)
382+
383+
# add a test file
384+
shutil.copy(os.path.join(TEST_DATA_DIR, "test.txt"), project_dir)
385+
386+
# do a full sync - it should not fail
387+
mc.pull_project(project_dir)
388+
mc.push_project(project_dir)
389+
390+
# make sure everything is up-to-date
391+
mp = MerginProject(project_dir)
392+
local_changes = mp.get_push_changes()
393+
assert not local_changes["added"] and not local_changes["removed"] and not local_changes["updated"]

0 commit comments

Comments
 (0)