import subprocess from pathlib import Path def get_dir_size(path: Path) -> int: """Returns directory size in bytes.""" return sum(f.stat().st_size for f in path.rglob("*") if f.is_file()) def is_git_dirty(path: Path) -> bool: """Returns True if there are uncommitted changes.""" try: result = subprocess.run( ["git", "status", "--porcelain"], cwd=path, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, ) return bool(result.stdout.strip()) except Exception: return False def is_git_unpushed(path: Path) -> bool: """Returns True if there are commits that haven't been pushed to upstream.""" try: # Check if upstream exists subprocess.run( ["git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"], cwd=path, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True, ) result = subprocess.run( ["git", "log", "@{u}..HEAD", "--oneline"], cwd=path, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, ) return bool(result.stdout.strip()) except Exception: return False