feat(models): add catalog and filesystem utilities
- Introduce models for managing repository catalog and categories - Add utilities for directory size and Git status checks - Enable repository metadata management, validation, and operations
This commit is contained in:
43
src/repocat/utils/fsutils.py
Normal file
43
src/repocat/utils/fsutils.py
Normal file
@@ -0,0 +1,43 @@
|
||||
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
|
Reference in New Issue
Block a user