Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/git_pulsar/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import datetime
import logging
import os
import subprocess
import sys
Expand All @@ -14,13 +15,15 @@
from . import daemon, ops, service, system
from .config import CONFIG_FILE, Config
from .constants import (
APP_NAME,
DEFAULT_IGNORES,
LOG_FILE,
PID_FILE,
REGISTRY_FILE,
)
from .git_wrapper import GitRepo

logger = logging.getLogger(APP_NAME)
console = Console()


Expand Down Expand Up @@ -86,8 +89,7 @@ def _analyze_logs(hours: int = 24) -> list[str]:


def _check_repo_health(path: Path) -> str | None:
"""
Evaluates the health of a repository, checking for stale backups or stalled states.
"""Evaluates the health of a repository, checking for stale backups or stalled states.

Args:
path (Path): The file system path to the repository.
Expand All @@ -112,8 +114,9 @@ def _check_repo_health(path: Path) -> str | None:
# Retrieve the raw Unix timestamp of the backup reference.
ts_str = repo._run(["log", "-1", "--format=%ct", ref])
last_backup_ts = int(ts_str.strip())
except Exception:
return "Has changes, but NO backup found."
except Exception as e:
logger.debug(f"Failed to retrieve backup timestamp for {path.name}: {e}")
return f"Has changes, but NO backup found. (Error: {e})"

# Check against the stale threshold (e.g., 2 hours).
# If changes are pending and no backup has occurred recently,
Expand Down Expand Up @@ -224,15 +227,17 @@ def show_status() -> None:
commit_ts = repo._run(["log", "-1", "--format=%ct", ref]).strip()
last_commit_time = datetime.datetime.fromtimestamp(int(commit_ts))
commit_str = last_commit_time.strftime("%Y-%m-%d %H:%M")
except Exception:
except Exception as e:
logger.debug(f"Failed to retrieve last commit time for {ref}: {e}")
commit_str = "Never"

# Get Push Time
try:
push_ts = repo._run(["log", "-1", "--format=%ct", remote_ref]).strip()
last_push_time = datetime.datetime.fromtimestamp(int(push_ts))
push_str = last_push_time.strftime("%Y-%m-%d %H:%M")
except Exception:
except Exception as e:
logger.debug(f"Failed to retrieve last push time for {remote_ref}: {e}")
push_str = "Never"

count = len(repo.status_porcelain())
Expand Down Expand Up @@ -312,11 +317,13 @@ def list_repos() -> None:
r = GitRepo(path)
ref = _get_ref(r)
last_backup = r.get_last_commit_time(ref)
except Exception:
except Exception as e:
logger.debug(f"Failed to retrieve backup info for {path}: {e}")
if status_text == "Active":
try:
GitRepo(path)
except Exception:
except Exception as inner_e:
logger.debug(f"Repo instantiation failed for {path}: {inner_e}")
status_text = "Error"
status_style = "bold red"

Expand Down Expand Up @@ -568,10 +575,12 @@ def setup_repo(registry_path: Path = REGISTRY_FILE) -> None:
if remotes:
console.print("Verifying git access...", style="dim")
repo._run(["push", "--dry-run"], capture=False)
except Exception:
except Exception as e:
logger.debug(f"Dry-run push verification failed: {e}")
console.print(
"⚠ WARNING: Git push failed. Ensure you have "
"SSH keys set up or credentials cached.",
f"⚠ WARNING: Git push failed. Ensure you have "
f"SSH keys set up or credentials cached.\n"
f"[dim]Diagnostic info: {e}[/dim]",
style="bold yellow",
)

Expand Down
3 changes: 2 additions & 1 deletion src/git_pulsar/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def get_remote_host(repo_path: Path, remote_name: str) -> str | None:
if "://" in url:
return url.split("://")[1].split("/")[0]
return None
except Exception:
except Exception as e:
logger.debug(f"Failed to parse remote host for '{remote_name}': {e}")
return None


Expand Down
6 changes: 4 additions & 2 deletions src/git_pulsar/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ def sync_session() -> None:
if ts > latest_time:
latest_time = ts
latest_ref = ref
except Exception:
except Exception as e:
logger.warning(f"Failed to parse timestamp for backup ref '{ref}': {e}")
continue

if not latest_ref:
Expand Down Expand Up @@ -389,7 +390,8 @@ def prune_backups(days: int, repo_path: Path | None = None) -> None:
console.print(f" Deleting {ref} (Age: {age_days:.1f} days)")
repo._run(["update-ref", "-d", ref], capture=False)
deleted_count += 1
except Exception:
except Exception as e:
logger.warning(f"Failed to process old backup ref '{ref}': {e}")
continue

if deleted_count == 0:
Expand Down
8 changes: 4 additions & 4 deletions src/git_pulsar/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ def get_machine_id() -> str:
mid = p.read_text().strip()
if mid:
return mid
except Exception:
pass
except Exception as e:
logger.debug(f"Failed to read machine-id from {p}: {e}")

# Optional extra fallback: product_uuid (common on x86)
try:
Expand All @@ -189,8 +189,8 @@ def get_machine_id() -> str:
v = p.read_text().strip()
if v:
return v
except Exception:
pass
except Exception as e:
logger.debug(f"Failed to read product_uuid from {p}: {e}")

# macOS: hardware UUID from IORegistry (IOPlatformUUID)
if sys.platform == "darwin":
Expand Down