sistemato problema su revert to commit

This commit is contained in:
VALLONGOL 2025-11-21 13:00:08 +01:00
parent f61ac3f061
commit fb4ac21de9
3 changed files with 103 additions and 1 deletions

View File

@ -1,6 +1,6 @@
block_cipher = None block_cipher = None
import os import os
a = Analysis(scripts=['gitutility\\__main__.py'], pathex=['gitutility', '.'], binaries=[], datas=[('C:\\src\\____GitProjects\\GitUtility\\git_svn_sync.ini', '.')], hiddenimports=[], hookspath=[], hooksconfig={}, runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=None, noarchive=False) a = Analysis(scripts=['gitutility\\__main__.py'], pathex=['gitutility', '.'], binaries=[], datas=[('git_svn_sync.ini', '.')], hiddenimports=[], hookspath=[], hooksconfig={}, runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=None, noarchive=False)
pyz = PYZ(a.pure, a.zipped_data, cipher=None) pyz = PYZ(a.pure, a.zipped_data, cipher=None)
exe = EXE(pyz, a.scripts, [], exclude_binaries=True, name='GitUtility', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, runtime_tmpdir=None, console=False, disable_windowed_traceback=False, target_arch=None, codesign_identity=None, entitlements_file=None, icon='GitUtility.ico') exe = EXE(pyz, a.scripts, [], exclude_binaries=True, name='GitUtility', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, runtime_tmpdir=None, console=False, disable_windowed_traceback=False, target_arch=None, codesign_identity=None, entitlements_file=None, icon='GitUtility.ico')
coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, upx_exclude=[], name='GitUtility') coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, upx_exclude=[], name='GitUtility')

View File

@ -2122,6 +2122,53 @@ def run_revert_to_tag_async(
) )
def run_reset_to_commit_async(
action_handler: ActionHandler,
repo_path: str,
commit_hash: str,
results_queue: queue.Queue[Dict[str, Any]],
) -> None:
"""Worker to perform a hard reset to a commit asynchronously."""
func_name = "run_reset_to_commit_async"
log_handler.log_debug(
f"[Worker] Started: Reset to Commit '{commit_hash}' in '{repo_path}'",
func_name=func_name,
)
result_payload: Dict[str, Any] = {
"status": "error",
"result": False,
"message": f"Failed to reset to commit '{commit_hash}'.",
"exception": None,
}
try:
success = action_handler.execute_reset_to_commit(repo_path, commit_hash)
result_payload["status"] = "success"
result_payload["result"] = success
result_payload["message"] = (
f"Repository successfully reset to commit '{commit_hash[:7]}'."
)
log_handler.log_info(
f"[Worker] {result_payload['message']}", func_name=func_name
)
except (GitCommandError, ValueError, Exception) as e:
log_handler.log_exception(
f"[Worker] EXCEPTION resetting to commit: {e}", func_name=func_name
)
result_payload["exception"] = e
result_payload["message"] = f"Error resetting to commit '{commit_hash[:7]}': {e}"
finally:
try:
results_queue.put(result_payload)
except Exception as qe:
log_handler.log_error(
f"[Worker] Failed to put result in queue for {func_name}: {qe}",
func_name=func_name,
)
log_handler.log_debug(
f"[Worker] Finished: Reset to Commit '{commit_hash}'", func_name=func_name
)
def run_promote_branch_to_main_async( def run_promote_branch_to_main_async(
git_commands: GitCommands, git_commands: GitCommands,
repo_path: str, repo_path: str,

View File

@ -1695,5 +1695,60 @@ class ActionHandler:
# Rilancia come un'eccezione generica o GitCommandError per coerenza # Rilancia come un'eccezione generica o GitCommandError per coerenza
raise Exception(f"Unexpected revert error: {e}") from e raise Exception(f"Unexpected revert error: {e}") from e
def execute_reset_to_commit(self, repo_path: str, commit_hash: str) -> bool:
"""
Executes a hard reset to the specified commit and cleans the working directory.
This is a wrapper for a destructive operation.
Args:
repo_path (str): The path to the repository.
commit_hash (str): The commit hash to reset to.
Returns:
bool: True if the operation was successful.
Raises:
ValueError: If inputs are invalid.
GitCommandError: If the underlying git commands fail.
"""
func_name: str = "execute_reset_to_commit"
log_handler.log_warning(
f"Executing destructive reset to commit '{commit_hash}' in repo: {repo_path}",
func_name=func_name,
)
# --- Validazione Input ---
if not repo_path or not os.path.isdir(repo_path):
raise ValueError(f"Invalid repository path provided: '{repo_path}'")
if not commit_hash or commit_hash.isspace():
raise ValueError("Commit hash for reset cannot be empty.")
if not os.path.exists(os.path.join(repo_path, ".git")):
raise ValueError(f"Directory '{repo_path}' is not a valid Git repository.")
try:
# Chiama il metodo di basso livello in GitCommands
self.git_commands.git_reset_hard(repo_path, commit_hash)
log_handler.log_info(
f"Successfully reset repository to commit '{commit_hash}'.",
func_name=func_name,
)
return True # L'operazione è andata a buon fine
except (GitCommandError, ValueError) as e:
# Logga e rilancia l'eccezione per essere gestita dal worker
log_handler.log_error(
f"Failed to reset to commit '{commit_hash}': {e}", func_name=func_name
)
raise e
except Exception as e:
# Cattura altri errori imprevisti
log_handler.log_exception(
f"An unexpected error occurred during reset to commit '{commit_hash}': {e}",
func_name=func_name,
)
# Rilancia come un'eccezione generica o GitCommandError per coerenza
raise Exception(f"Unexpected reset error: {e}") from e
# --- END OF FILE gitsync_tool/core/action_handler.py --- # --- END OF FILE gitsync_tool/core/action_handler.py ---