sistemata funzione di update wiki

This commit is contained in:
VALLONGOL 2025-12-01 14:21:13 +01:00
parent fb4ac21de9
commit b9f9a95f11

View File

@ -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,