#!/usr/bin/env python3 import os import subprocess from pathlib import Path def check_git_status(repo_path): """Check if a git repository has uncommitted changes.""" try: # Check if directory is a git repo result = subprocess.run( ['git', 'rev-parse', '--git-dir'], cwd=repo_path, capture_output=True, text=True, timeout=5 ) if result.returncode != 0: return None, "Not a git repository" # Check for uncommitted changes status_result = subprocess.run( ['git', 'status', '--porcelain'], cwd=repo_path, capture_output=True, text=True, timeout=5 ) if status_result.returncode != 0: return None, "Error checking status" changes = status_result.stdout.strip() if changes: # Parse changed files lines = changes.split('\n') files = [line[2:].lstrip() if len(line) > 2 else line for line in lines] return True, (f"{len(lines)} uncommitted change(s)", files) else: return False, ("Clean (no uncommitted changes)", []) except subprocess.TimeoutExpired: return None, "Timeout" except Exception as e: return None, f"Error: {str(e)}" def main(): current_dir = Path.cwd() print(f"Checking projects in: {current_dir}\n") print("=" * 70) # Get all subdirectories subdirs = [d for d in current_dir.iterdir() if d.is_dir() and not d.name.startswith('.')] if not subdirs: print("No subdirectories found.") return projects_with_changes = [] clean_projects = [] non_git_dirs = [] for subdir in sorted(subdirs): result = check_git_status(subdir) if result[0] is None: # Not a git repo or error has_changes, message = result non_git_dirs.append((subdir.name, message)) elif result[0]: # Has changes has_changes, (message, files) = result projects_with_changes.append((subdir.name, message, files)) print(f"⚠️ {subdir.name}: {message}") for file in files: print(f" {file}") else: # Clean has_changes, (message, files) = result clean_projects.append(subdir.name) print(f"✓ {subdir.name}: {message}") # Summary print("\n" + "=" * 70) print("SUMMARY:") print(f" Projects with uncommitted changes: {len(projects_with_changes)}") print(f" Clean projects: {len(clean_projects)}") print(f" Non-git directories: {len(non_git_dirs)}") if projects_with_changes: print("\nProjects needing attention:") for name, msg, files in projects_with_changes: print(f" - {name}") if __name__ == "__main__": main()