From 97ec4a6f66f50f564f715c47d6b98e7986869fb5 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Sun, 29 Dec 2024 16:51:21 +0100 Subject: [PATCH] adds git update checks --- bin/check | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/bin/check b/bin/check index f394092..0fc6cb1 100755 --- a/bin/check +++ b/bin/check @@ -132,7 +132,41 @@ def check_scripts() -> Dict[str, List[Tuple[bool, str|None]]]: } return checks +def check_git_updates() -> Tuple[bool, str|None]: + try: + script_dir = Path(__file__).parent.parent + if not (script_dir / '.git').exists(): + return (False, "Not a git repository") + original_dir = os.getcwd() + os.chdir(script_dir) + + try: + # git fetch + subprocess.run(['git', 'fetch'], check=True, capture_output=True) + + # git status + result = subprocess.run(['git', 'status'], check=True, capture_output=True, text=True) + + if "Your branch is up to date" in result.stdout: + return (True, None) + else: + return (False, result.stdout) + finally: + os.chdir(original_dir) + except subprocess.CalledProcessError as e: + return (False, f"Git command failed: {e}") + except Exception as e: + return (False, f"Error checking git status: {e}") + def main(): + # First check git status + git_status, git_message = check_git_updates() + status = CHECK if git_status else CROSS + print(f"{status} Repository status") + if git_message: + print(f"\t{status} {git_message}") + print() # Empty line for separation + results = check_scripts() for script, checks in results.items():