add current branch in status

This commit is contained in:
VALLONGOL 2025-04-23 10:38:44 +02:00
parent d4c11a5b70
commit 69cacd26ec
2 changed files with 303 additions and 689 deletions

File diff suppressed because it is too large Load Diff

59
gui.py
View File

@ -714,18 +714,15 @@ class MainFrame(ttk.Frame):
status_frame.columnconfigure(0, weight=1) # Label si espande status_frame.columnconfigure(0, weight=1) # Label si espande
# Label per Ahead/Behind # Label per Ahead/Behind
self.ahead_behind_label = ttk.Label( self.sync_status_label = ttk.Label(
status_frame, status_frame,
textvariable=self.remote_ahead_behind_var, # Collegato alla variabile textvariable=self.remote_ahead_behind_var, # Collegato alla variabile
anchor=tk.W, # Allinea testo a sinistra anchor=tk.W, # Allinea testo a sinistra
# relief=tk.SUNKEN, # Forse senza bordo è meglio? # relief=tk.SUNKEN, # Forse senza bordo è meglio?
padding=(5, 2), padding=(5, 2),
) )
self.ahead_behind_label.grid(row=0, column=0, sticky=tk.EW, padx=(5, 10)) self.sync_status_label.grid(row=0, column=0, sticky=tk.EW, padx=(5, 10))
self.create_tooltip( self.create_tooltip(self.sync_status_label, "Shows the current local branch and its sync status (ahead/behind) relative to its upstream.")
self.ahead_behind_label,
"Indicates if the local branch is ahead (needs push) or behind (needs pull) the remote branch.",
)
# Pulsante Refresh Status # Pulsante Refresh Status
self.refresh_sync_status_button = ttk.Button( self.refresh_sync_status_button = ttk.Button(
@ -737,10 +734,7 @@ class MainFrame(ttk.Frame):
self.refresh_sync_status_button.grid( self.refresh_sync_status_button.grid(
row=0, column=1, sticky=tk.E, padx=(0, 5), pady=2 row=0, column=1, sticky=tk.E, padx=(0, 5), pady=2
) )
self.create_tooltip( self.create_tooltip(self.refresh_sync_status_button, "Check sync status (ahead/behind) for the current branch.")
self.refresh_sync_status_button,
"Check how many commits the local branch is ahead or behind the remote branch.",
)
# --- Sezione Azioni Remote --- # --- Sezione Azioni Remote ---
actions_frame = ttk.LabelFrame(frame, text="Remote Actions", padding=(10, 5)) actions_frame = ttk.LabelFrame(frame, text="Remote Actions", padding=(10, 5))
@ -1935,43 +1929,56 @@ class MainFrame(ttk.Frame):
def update_ahead_behind_status( def update_ahead_behind_status(
self, self,
current_branch: str | None = None, # Aggiunto parametro branch
status_text: str | None = None, status_text: str | None = None,
ahead: int | None = None, ahead: int | None = None,
behind: int | None = None, behind: int | None = None
): ):
"""Updates the ahead/behind status label.""" """Updates the synchronization status label, including the current branch."""
label = getattr(self, "ahead_behind_label", None) label = getattr(self, "sync_status_label", None) # Usa nuovo nome label
var = getattr(self, "remote_ahead_behind_var", None) var = getattr(self, "remote_ahead_behind_var", None)
if not label or not var or not label.winfo_exists(): if not label or not var or not label.winfo_exists():
return return
text_to_display = "Sync Status: Unknown" # Default # Determina il testo da visualizzare
if current_branch:
branch_part = f"Branch '{current_branch}': "
else:
# Se non conosciamo il branch (es. detached head o errore iniziale)
branch_part = "Current Branch: "
status_part = "Unknown" # Default
if status_text is not None: if status_text is not None:
# Se viene passato un testo specifico (es. errore, no upstream), usa quello # Testo esplicito fornito (es. errore, no upstream, detached)
text_to_display = status_text status_part = status_text # Il testo dovrebbe già includere "Sync Status:" o simile
# Sovrascrivi branch_part se il testo contiene già info sul branch o stato
if "Branch" in status_part or "Detached" in status_part or "Upstream" in status_part:
text_to_display = status_part # Usa direttamente il testo fornito
else:
text_to_display = branch_part + status_part
elif ahead is not None and behind is not None: elif ahead is not None and behind is not None:
# Se abbiamo i conteggi, costruisci il messaggio # Costruisci messaggio da conteggi
if ahead == 0 and behind == 0: if ahead == 0 and behind == 0:
text_to_display = "Sync Status: Up to date" status_part = "Up to date"
else: else:
parts = [] parts = []
if ahead > 0: if ahead > 0:
plural_a = "s" if ahead > 1 else "" plural_a = 's' if ahead > 1 else ''
parts.append(f"{ahead} commit{plural_a} ahead (Push needed)") parts.append(f"{ahead} commit{plural_a} ahead (Push needed)")
if behind > 0: if behind > 0:
plural_b = "s" if behind > 1 else "" plural_b = 's' if behind > 1 else ''
parts.append(f"{behind} commit{plural_b} behind (Pull needed)") parts.append(f"{behind} commit{plural_b} behind (Pull needed)")
text_to_display = "Sync Status: " + ", ".join(parts) status_part = ", ".join(parts)
# else: Se non viene passato testo e i conteggi sono None, rimane "Unknown" text_to_display = branch_part + status_part
else: # Caso di default o conteggi None senza testo esplicito
text_to_display = branch_part + "Unknown Status"
try: try:
var.set(text_to_display) var.set(text_to_display)
except Exception as e: except Exception as e:
log_handler.log_error( log_handler.log_error(f"Failed to update sync status variable: {e}", func_name="update_ahead_behind_status")
f"Failed to update ahead/behind status variable: {e}",
func_name="update_ahead_behind_status",
)
# --- END OF FILE gui.py --- # --- END OF FILE gui.py ---