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

61
gui.py
View File

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