From 4127df814b0a9829fe2fa04b68eb959a1f781ae6 Mon Sep 17 00:00:00 2001 From: Amber Date: Sat, 26 Oct 2024 08:53:22 +0200 Subject: [PATCH] precheck_remote_unmerged --- src/iface/sync_manager.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/iface/sync_manager.py b/src/iface/sync_manager.py index 5df08ba..963d221 100644 --- a/src/iface/sync_manager.py +++ b/src/iface/sync_manager.py @@ -291,18 +291,23 @@ class Manager(): remote_mount_point = self.get_remote_mount_point(node) return agent.copy_dir(absolute_local_path, remote_mount_point) - def ___(node, version_kept): + def precheck_remote_unode(self, node): ''' - before copying the node we expect: - 1. last_hash of remote is equal to node['last_hash'] -> this means in local we modified the server version - 2. if there is a conflict remote_hash is None if file is not in remote + Check the unmerged node on remote before solve conflict + Consideration about unode: + 1. We have generated `cur_hash` starting from `last_hash` version of node on local tree + 2. We are aware on remote the hash is changed at the moment we `sync`, the value is stored in `remote_hash` + + we expect + `remote_hash` is unchanged, then we can proceed with solving the conflict + `remote_hash` is changed, then we can generate a new conflict with `remote_hash` equals to the new remote hash ''' rstatus = self.get_rnode_status(node) rfile_buf, rhash, rexists = map(rstatus.get, ['iobuffer', 'hash', 'exists']) - if not rexists and version_kept == 'keep_local': - return True, 'You push local version on remote' + # if not rexists and version_kept == 'keep_local': + # return True, 'You push local version on remote' remote_hash = node['remote_hash'] @@ -322,11 +327,11 @@ class Manager(): n = -1 if n == -1: - return 'No node conflicting' + raise Exception('No node conflicting found!!') print(f'remote hash changed you...generate a new conflict') ## update the conflicting node by index - (cur_hash, cur_buf) = _genlocal.generate_file_hash(self.get_absolute_local_path(found)) + # (cur_hash, cur_buf) = _genlocal.generate_file_hash(self.get_absolute_local_path(found)) found['cur_hash'] = cur_hash found['last_hash'] = found['remote_hash'] found['remote_hash'] = rhash @@ -336,6 +341,8 @@ class Manager(): self.store_fdiff(found) return False, 'Generate conflict' + return True, 'You can proceed' + def show_conflicts(self): unmerged = self.load_unmerged_diff() @@ -359,6 +366,12 @@ class Manager(): i = n-1 unmerged = self.load_unmerged_diff() unode = unmerged[i] + + precheck_res, precheck_msg = self.precheck_remote_unode(unode) + if not precheck_res: + print(precheck_msg) + return + absolute_local_path = colors.CYAN(self.get_absolute_local_path(unode)) absolute_remote_path = colors.CYAN(self.get_absolute_remote_path(unode)) if version_kept == 'keep_local':