From b9f9a95f118f8e16d78ac6741f25453671f287a5 Mon Sep 17 00:00:00 2001 From: VALLONGOL Date: Mon, 1 Dec 2025 14:21:13 +0100 Subject: [PATCH] sistemata funzione di update wiki --- gitutility/core/wiki_updater.py | 45 +++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/gitutility/core/wiki_updater.py b/gitutility/core/wiki_updater.py index b7bc3ef..bcf23ea 100644 --- a/gitutility/core/wiki_updater.py +++ b/gitutility/core/wiki_updater.py @@ -165,8 +165,38 @@ class WikiUpdater: ) self.git_commands.add_file(temp_dir, ".", renormalize=True) + # Sometimes local/global exclude rules may prevent files from being + # staged by a normal `git add`. If after the add there are still no + # changes detected, attempt a forced add to ensure files get tracked. + try: + if not self.git_commands.git_status_has_changes(temp_dir): + log_handler.log_warning( + "No changes detected after staging; attempting forced add (-f).", + func_name=func_name, + ) + try: + # Use log_and_execute to run a forced add with renormalize + self.git_commands.log_and_execute( + ["git", "add", "-f", "--renormalize", "--", "."], + temp_dir, + check=True, + ) + except Exception as force_add_e: + log_handler.log_warning( + f"Forced add failed: {force_add_e}", func_name=func_name + ) + except Exception: + # If status check itself fails, continue and let commit attempt handle it + pass + + # Ensure files are staged before committing. Some environments + # (notably Windows with temp dirs) can leave files untracked + # even after an explicit add call due to timing/locking; calling + # git_commit with `stage_all_first=True` makes this operation + # more robust by running a final `git add .` inside the repo + # before the commit. commit_success = self.git_commands.git_commit( - temp_dir, commit_message, stage_all_first=False + temp_dir, commit_message, stage_all_first=True ) if not commit_success: msg = "Staged changes, but commit reported no changes to commit. Push will be skipped." @@ -220,9 +250,20 @@ class WikiUpdater: f"Attempting to clean up temporary directory: {temp_dir}", func_name=func_name, ) + def _on_rm_error(func, path, exc_info): + # Attempt to fix permissions and retry file removal (Windows) + try: + os.chmod(path, 0o666) + except Exception: + pass + try: + func(path) + except Exception: + raise + for attempt in range(3): try: - shutil.rmtree(temp_dir) + shutil.rmtree(temp_dir, onerror=_on_rm_error) log_handler.log_info( f"Cleanup of temporary directory successful.", func_name=func_name,