From e3bf97eeb54fe59d2fc7334ec10e9d9d70ad3830 Mon Sep 17 00:00:00 2001 From: VALLONGOL Date: Fri, 18 Apr 2025 13:13:39 +0200 Subject: [PATCH] Chore: Stop tracking files based on .gitignore update. Summary: - Rule "*.ini" untracked 1 file(s). - Rule "*.log" untracked 1 file(s). - Rule "_build/" untracked 15 file(s). - Rule "_dist/" untracked 946 file(s). --- .gitignore | 12 +++++---- git_commands.py | 72 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 59 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 37bad11..28fceb2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ -.svn -.log -dist -build -.ini \ No newline at end of file +.svn/ +*.log +dist/ +build/ +_dist/ +_build/ +*.ini \ No newline at end of file diff --git a/git_commands.py b/git_commands.py index 8c4e175..50740c1 100644 --- a/git_commands.py +++ b/git_commands.py @@ -976,41 +976,73 @@ class GitCommands: def remove_from_tracking(self, working_directory, files_to_untrack): """ Removes specified files/directories from Git tracking (index) - without deleting them from the working directory. + without deleting them from the working directory. Processes files in batches + to avoid command line length limits. Args: working_directory (str): Path to the Git repository. files_to_untrack (list): List of relative paths to untrack. Returns: - bool: True if the command executed successfully (even if nothing was removed). + bool: True if all batches executed successfully. Raises: - GitCommandError: If the git command fails. + GitCommandError: If any git rm batch command fails. ValueError: If the list of files is empty. """ if not files_to_untrack: - raise ValueError("File list cannot be empty for remove_from_tracking.") + # Non è un errore se la lista è vuota, semplicemente non c'è nulla da fare. + self.logger.debug("No files provided to remove_from_tracking.") + return True # Considera successo non fare nulla - self.logger.info(f"Removing {len(files_to_untrack)} items from Git tracking...") - self.logger.debug(f"Items to untrack: {files_to_untrack}") + self.logger.info(f"Removing {len(files_to_untrack)} items from Git tracking in batches...") - # Base command - command = ["git", "rm", "--cached", "--"] # "--" separates options from paths - # Add all file paths to the command - command.extend(files_to_untrack) + # --- MODIFICA: Logica Batch --- + batch_size = 100 # Processa N file alla volta (regola se necessario) + all_batches_succeeded = True - try: - # check=True ensures an error is raised if `git rm` fails - self.log_and_execute(command, working_directory, check=True) - self.logger.info("Successfully removed items from tracking index.") + for i in range(0, len(files_to_untrack), batch_size): + batch = files_to_untrack[i : i + batch_size] + if not batch: # Salta batch vuoti (non dovrebbe succedere con range) + continue + + self.logger.info(f"Processing untrack batch {i // batch_size + 1}: {len(batch)} items...") + self.logger.debug(f"Batch items: {batch}") + + # Costruisci il comando per questo batch + command = ["git", "rm", "--cached", "-r", "--ignore-unmatch", "--"] # Aggiunto -r e --ignore-unmatch + # -r: Necessario se alcuni 'file' sono in realtà directory (come _build/, _dist/) + # --ignore-unmatch: Evita errori se un file è già stato rimosso o non trovato per qualche motivo strano + command.extend(batch) + + try: + # Esegui il comando per il batch corrente + # Logga l'output a DEBUG per non inondare il log INFO + self.log_and_execute(command, working_directory, check=True, log_output_level=logging.DEBUG) + self.logger.info(f"Batch {i // batch_size + 1} untracked successfully.") + + except (GitCommandError, ValueError) as e: + self.logger.error(f"Failed to process untrack batch {i // batch_size + 1}: {e}") + # Puoi decidere se interrompere o continuare con gli altri batch. + # Interrompere è generalmente più sicuro. + all_batches_succeeded = False + raise GitCommandError(f"Failed untracking batch {i // batch_size + 1}. Error: {e}", command=command, stderr=getattr(e, 'stderr', None)) from e + except Exception as e: + self.logger.exception(f"Unexpected error processing untrack batch {i // batch_size + 1}: {e}") + all_batches_succeeded = False + raise GitCommandError(f"Unexpected untrack batch error: {e}", command=command) from e + + # Se arriviamo qui, il batch ha avuto successo + + # Ritorna True solo se TUTTI i batch hanno avuto successo + if all_batches_succeeded: + self.logger.info("All untracking batches completed successfully.") return True - except (GitCommandError, ValueError) as e: - self.logger.error(f"Failed to remove items from tracking: {e}") - raise # Re-raise original error - except Exception as e: - self.logger.exception(f"Unexpected error removing from tracking: {e}") - raise GitCommandError(f"Unexpected untrack error: {e}", command=command) from e + else: + # Questo caso non dovrebbe essere raggiunto se solleviamo eccezioni sopra, + # ma lo teniamo per sicurezza. + self.logger.error("Untracking process completed with errors in some batches.") + return False def get_matching_gitignore_rule(self, working_directory, path_to_check): """