Skip to content

Commit fccd67f

Browse files
MarcelGeowonder-sk
authored andcommitted
Reolving some comments requirements
1 parent 5e8c8a5 commit fccd67f

File tree

5 files changed

+22
-40
lines changed

5 files changed

+22
-40
lines changed

mergin/client_pull.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,6 @@ def dump(self):
372372
print("- {} {} {} {}".format(item.file_path, item.version, item.part_index, item.size))
373373
print("--- END ---")
374374

375-
def apply_changes(self):
376-
"""Apply changes to the project directory with MerginProject.apply_pull_changes"""
377-
return self.mp.apply_pull_changes(self.pull_changes, self.temp_dir, self.project_info, self.mc)
378-
379375

380376
def pull_project_async(mc, directory):
381377
"""
@@ -627,7 +623,7 @@ def pull_project_finalize(job: PullJob):
627623
raise ClientError("Cannot patch basefile {}! Please try syncing again.".format(basefile))
628624

629625
try:
630-
conflicts = job.apply_changes()
626+
conflicts = job.mp.apply_pull_changes(job.pull_changes, job.temp_dir, job.project_info, job.mc)
631627
except Exception as e:
632628
job.mp.log.error("Failed to apply pull changes: " + str(e))
633629
job.mp.log.info("--- pull aborted")

mergin/editor.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from itertools import filterfalse
2+
from typing import Callable
23

34
from .utils import is_mergin_config, is_qgis_file, is_versioned_file
45

@@ -10,7 +11,9 @@
1011
Returns:
1112
bool: True if the file change should be disallowed, False otherwise.
1213
"""
13-
_disallowed_added_changes = lambda change: is_qgis_file(change["path"]) or is_mergin_config(change["path"])
14+
disallowed_added_changes: Callable[[dict], bool] = lambda change: is_qgis_file(change["path"]) or is_mergin_config(
15+
change["path"]
16+
)
1417
"""
1518
Determines whether a given file change should be disallowed from being updated.
1619
@@ -22,7 +25,7 @@
2225
Returns:
2326
bool: True if the change should be disallowed, False otherwise.
2427
"""
25-
_disallowed_updated_changes = (
28+
_disallowed_updated_changes: Callable[[dict], bool] = (
2629
lambda change: is_qgis_file(change["path"])
2730
or is_mergin_config(change["path"])
2831
or (is_versioned_file(change["path"]) and change.get("diff") is None)
@@ -37,7 +40,7 @@
3740
3841
If any of these conditions are met, the change is considered disallowed from being removed.
3942
"""
40-
_disallowed_removed_changes = (
43+
_disallowed_removed_changes: Callable[[dict], bool] = (
4144
lambda change: is_qgis_file(change["path"]) or is_mergin_config(change["path"]) or is_versioned_file(change["path"])
4245
)
4346

@@ -67,7 +70,7 @@ def _apply_editor_filters(changes: dict[str, list[dict]]) -> dict[str, list[dict
6770
removed = changes.get("removed", [])
6871

6972
# filter out files that are not in the editor's list of allowed files
70-
changes["added"] = list(filterfalse(_disallowed_added_changes, added))
73+
changes["added"] = list(filterfalse(disallowed_added_changes, added))
7174
changes["updated"] = list(filterfalse(_disallowed_updated_changes, updated))
7275
changes["removed"] = list(filterfalse(_disallowed_removed_changes, removed))
7376
return changes
@@ -91,4 +94,16 @@ def filter_changes(mc, project_info: dict, changes: dict[str, list[dict]]) -> di
9194

9295

9396
def prevent_conflicted_copy(path: str, mc, project_info: dict) -> bool:
97+
"""
98+
Decides whether a file path should be blocked from creating a conflicted copy.
99+
Note: This is used when the editor is active and attempting to modify files (e.g., .ggs) that are also updated on the server, preventing unnecessary conflict files creation.
100+
101+
Args:
102+
path (str): The file path to check.
103+
mc: The Mergin client object.
104+
project_info (dict): Information about the Mergin project from server.
105+
106+
Returns:
107+
bool: True if the file path should be prevented from ceating conflicted copy, False otherwise.
108+
"""
94109
return is_editor_enabled(mc, project_info) and any([is_qgis_file(path), is_mergin_config(path)])

mergin/merginproject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ def apply_pull_changes(self, changes, temp_dir, server_project, mc):
548548
# We just apply the diff between our copy and server to both the local copy and its basefile
549549
self.update_without_rebase(path, src, dest, basefile, temp_dir)
550550
else:
551-
# creating conflicitn copy if both server and local changes are present on the files
551+
# creating conflicted copy if both server and local changes are present on the files
552552
if (
553553
path in modified_local_paths
554554
and item["checksum"] != local_files_map[path]["checksum"]

mergin/test/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2632,7 +2632,7 @@ def test_editor_push(mc: MerginClient, mc2: MerginClient):
26322632
# ggs and gpkg are still waiting to push
26332633
assert any(file["path"] == qgs_file_name for file in push_changes.get("added")) is True
26342634
assert any(file["path"] == gpkg_file_name for file in push_changes.get("updated")) is True
2635-
# push as owner do cleanup local changes and preparation to conflicitng copy simulate
2635+
# push as owner do cleanup local changes and preparation to conflicited copy simulate
26362636
mc.push_project(project_dir)
26372637

26382638
# simulate conflicting copy of qgis file

scripts/test_editor.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)