From f3c89ecbc03b48c058c1039ec979e0baeee7fdea Mon Sep 17 00:00:00 2001 From: VALLONGOL Date: Mon, 24 Mar 2025 13:03:53 +0100 Subject: [PATCH] Autocommit --- .gitignore | 1 + Git_Utility.py | 57 +++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..90ec22b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.svn diff --git a/Git_Utility.py b/Git_Utility.py index 33afca6..b00604b 100644 --- a/Git_Utility.py +++ b/Git_Utility.py @@ -26,7 +26,7 @@ class GitSvnSyncApp: self.file_handler.setLevel(logging.INFO) self.file_handler.setFormatter(self.log_formatter) self.logger.addHandler(self.file_handler) - self.log_text = scrolledtext.ScrolledText(master, height=10, width=80) + self.log_text = scrolledtext.ScrolledText(master, height=10, width=100, font=("Courier New", 8, "normal")) self.log_text.pack(pady=10) self.log_text.config(state=tk.DISABLED) self.text_handler = TextHandler(self.log_text) @@ -94,6 +94,13 @@ class GitSvnSyncApp: self.bundle_updated_name_label.grid(row=3, column=0, sticky=tk.W) self.bundle_updated_name_entry = ttk.Entry(self.settings_frame, width=60) self.bundle_updated_name_entry.grid(row=3, column=1, sticky=tk.W) + + # Aggiungi questa variabile all'inizio della classe GitSvnSyncApp + self.autocommit_var = tk.BooleanVar() + + # Aggiungi questo checkbox nell'interfaccia grafica (nel metodo __init__) + self.autocommit_checkbox = ttk.Checkbutton(master, text="Autocommit", variable=self.autocommit_var) + self.autocommit_checkbox.pack(pady=5) # Pulsanti self.prepare_svn_button = ttk.Button(master, text="Prepare SVN for Git", command=self.prepare_svn_for_git) @@ -259,10 +266,45 @@ class GitSvnSyncApp: messagebox.showerror("Error", f"Il percorso SVN '{svn_path}' non esiste.") return - bundle_path = os.path.join(self.usb_path_entry.get(), self.bundle_name_entry.get()).replace("\\", "/") # Modifica qui + # Verifica se ci sono commit nel repository Git + try: + command = ["git", "log", "--oneline"] + result = self.log_and_execute(command, check=False) # Non generare un errore se non ci sono commit + if not result.stdout: + self.logger.error("Errore: Il repository Git è vuoto. Assicurati di aver aggiunto e committato i file.") + messagebox.showerror("Error", "Errore: Il repository Git è vuoto. Assicurati di aver aggiunto e committato i file.") + return + except Exception as e: + self.logger.error(f"Errore durante la verifica dei commit: {e}") + messagebox.showerror("Error", f"Errore durante la verifica dei commit: {e}") + return + + # Autocommit + if self.autocommit_var.get(): + self.logger.info("Autocommit abilitato.") + try: + # Verifica se ci sono modifiche + command = ["git", "status", "-s"] + result = self.log_and_execute(command, check=False) + if result.stdout: + self.logger.info("Rilevate modifiche nel repository Git. Esecuzione autocommit...") + # Esegui git add . + command = ["git", "add", "."] + self.log_and_execute(command) + # Esegui git commit -m "Autocommit" + command = ["git", "commit", "-m", "Autocommit"] + self.log_and_execute(command) + self.logger.info("Autocommit eseguito con successo.") + else: + self.logger.info("Nessuna modifica rilevata nel repository Git. Autocommit non necessario.") + except Exception as e: + self.logger.error(f"Errore durante l'autocommit: {e}") + messagebox.showerror("Error", f"Errore durante l'autocommit: {e}") + + bundle_path = os.path.join(self.usb_path_entry.get(), self.bundle_name_entry.get()).replace("\\", "/") command = ["git", "bundle", "create", bundle_path, "--all"] try: - self.log_and_execute(command) + result = self.log_and_execute(command) self.logger.info("Bundle Git creato con successo.") except Exception as e: self.logger.error(f"Errore durante la creazione del bundle: {e}") @@ -272,9 +314,14 @@ class GitSvnSyncApp: """Recupera le modifiche dal bundle nel repository Git locale.""" self.save_profile_settings() # Salva le impostazioni del profilo corrente self.logger.info("Recupero delle modifiche dal bundle Git...") - bundle_path = os.path.join(self.usb_path_entry.get(), self.bundle_updated_name_entry.get()) + bundle_path = os.path.join(self.usb_path_entry.get(), self.bundle_updated_name_entry.get()).replace("\\", "/") + # Verifica che il file bundle esista + if not os.path.exists(bundle_path): + self.logger.error(f"Il file bundle '{bundle_path}' non esiste.") + messagebox.showerror("Error", f"Il file bundle '{bundle_path}' non esiste.") + return try: - fetch_command = ["git", "fetch", bundle_path, "--all"] + fetch_command = ["git", "fetch", bundle_path] # Rimuovi --all self.log_and_execute(fetch_command) merge_command = ["git", "merge", "FETCH_HEAD"] self.log_and_execute(merge_command)