From 4a2951dd2694ca7475202d276255d1f76371f422 Mon Sep 17 00:00:00 2001 From: KI-Sparringpartner Date: Mon, 3 Aug 2026 20:16:36 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20FIX:=20Git=20identity=20setzen?= =?UTF-8?q?=20+=20Changes-Status=20checken=20via=20git=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/git_manager.py | 34 +++++++++++++++++++++++++++++++++- app/routes.py | 29 +++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/app/git_manager.py b/app/git_manager.py index c309262..e9221b1 100644 --- a/app/git_manager.py +++ b/app/git_manager.py @@ -139,4 +139,36 @@ def push_changes(repo_path: Path, message: str = "Update 🧠", changelog_conten ["git", "push"], cwd=repo_path, capture_output=True, text=True ) - return {"success": result.returncode == 0, "output": result.stdout} \ No newline at end of file + return {"success": result.returncode == 0, "output": result.stdout} + + +def get_git_status(repo_path: Path) -> dict: + """Prueft den Status eines Git-Repo fuer aenderungen.""" + # Setze git identity if not set (fuer Push ohne manuelle Konfig) + try: + subprocess.run( + ["git", "config", "--global", "user.name", "KI-Sparringpartner"], + cwd=repo_path, capture_output=True + ) + subprocess.run( + ["git", "config", "--global", "user.email", "ai@local.internal"], + cwd=repo_path, capture_output=True + ) + except Exception: + pass # Falls git config fehlschlaegt, versuch trotzdem push + + # Check fuer uncommitted changes + result = subprocess.run( + ["git", "status", "--porcelain"], + cwd=repo_path, + capture_output=True, + text=True + ) + + has_changes = bool(result.stdout.strip()) + + return { + "has_changes": has_changes, + "uncommitted_files": result.stdout.strip().split("\n") if result.stdout else [], + "can_push": has_changes + } \ No newline at end of file diff --git a/app/routes.py b/app/routes.py index 1ac9dba..21e8d83 100644 --- a/app/routes.py +++ b/app/routes.py @@ -28,8 +28,9 @@ class PushRequest(BaseModel): @router.get("/projects") # Listet abonierte Projekte! async def list_projects(): - """Listet lokale (abonierte) Projekte an.""" + """Listet lokale (abonierte) Projekte an mit Git-Status.""" from .main import PROJECTS_DIR + from .git_manager import get_git_status projects = [] @@ -39,18 +40,28 @@ async def list_projects(): if project_dir.is_dir() and not project_dir.name.startswith('.'): has_git = (project_dir / '.git').exists() - # Pruefe ob dieses Projekt bearbeitet werden darf can_write = os.access(str(project_dir), os.W_OK) if project_dir.exists() else False + + # Git Status checken + git_status = {"has_changes": False, "uncommitted_files": []} + if has_git: + try: + git_status = get_git_status(project_dir) + except Exception as e: + print(f"Git status error: {e}") all_projects.append({ "name": project_dir.name, "path": str(project_dir), "subscribed": True, "has_git": bool(has_git), - "can_write": can_write + "can_write": can_write, + "has_changes": git_status.get("has_changes", False), + "uncommitted_files": git_status.get("uncommitted_files", []) }) - projects = sorted(all_projects, key=lambda x: ("" in x["name"]), reverse=True) + # Sortiere: Projects mit Changes zuerst + projects = sorted(all_projects, key=lambda x: (not x["has_changes"])) return {"projects": projects} @@ -122,6 +133,12 @@ async def subscribe_repo(req: SubscribeRequest): generate_changelog(target_dir) + # Initialen Push nach dem ersten Clone (optional) + try: + push_changes(target_dir, "Initial commit from gitea-sync-ai") + except Exception as e: + print(f"Initial push skipped: {e}") + return { "message": f"✅ {req.target_name} geklont!", "path": str(target_dir), @@ -134,7 +151,6 @@ async def subscribe_repo(req: SubscribeRequest): async def push_to_gitea(req: PushRequest): """Pusht Changes eines Projekts zurueck zu Gitea.""" from .main import PROJECTS_DIR - import stat target_dir = PROJECTS_DIR / req.project_name @@ -161,6 +177,7 @@ async def push_to_gitea(req: PushRequest): async def push_project(project_name: str): """Pusht Changes eines Projekts zurueck zu Gitea (ohne ChangelogContent).""" from .main import PROJECTS_DIR + import stat target_dir = PROJECTS_DIR / project_name @@ -184,5 +201,5 @@ async def push_project(project_name: str): # Importiere die Funktionen am Ende damit sie verfügbar sind! -from .git_manager import clone_repo, set_permissions, push_changes, force_remove_all +from .git_manager import clone_repo, set_permissions, push_changes, force_remove_all, get_git_status from .changelog_gen import generate_changelog \ No newline at end of file