precheck_remote_unmerged

This commit is contained in:
Amber 2024-10-26 08:53:22 +02:00
parent f2ed6de92e
commit 4127df814b

View File

@ -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':