#!/usr/bin/env python3 """ Test Go-Git executable to find root cause """ import subprocess import os import sys def test_git_exe(): """Test git.exe with different approaches""" git_exe = r"C:\Program Files\gitea\git.exe" if not os.path.exists(git_exe): print(f"❌ git.exe not found at: {git_exe}") return False print(f"Testing git.exe: {git_exe}") print(f"File size: {os.path.getsize(git_exe)} bytes") print(f"Exists: {os.path.exists(git_exe)}") # Test 1: Run with shell print("\n=== Test 1: Run with shell ===") try: result = subprocess.run( f'"{git_exe}"', shell=True, capture_output=True, text=True, timeout=5 ) print(f"Exit code: {result.returncode}") print(f"Stdout: {result.stdout}") print(f"Stderr: {result.stderr}") except Exception as e: print(f"Error: {e}") # Test 2: Run with list args print("\n=== Test 2: Run with list args ===") try: result = subprocess.run( [git_exe], capture_output=True, text=True, timeout=5 ) print(f"Exit code: {result.returncode}") print(f"Stdout: {result.stdout}") print(f"Stderr: {result.stderr}") except Exception as e: print(f"Error: {e}") # Test 3: Check if it's actually a Go binary print("\n=== Test 3: Check file type ===") try: with open(git_exe, 'rb') as f: header = f.read(4) print(f"File header: {header}") if header == b'MZ\x90\x00': # PE executable print("✓ This is a Windows PE executable") else: print("⚠ Not a standard PE executable") except Exception as e: print(f"Error reading file: {e}") # Test 4: Check dependencies print("\n=== Test 4: Check environment ===") print(f"PATH: {os.environ.get('PATH', '')[:200]}...") # Test 5: Try running from gitea directory print("\n=== Test 5: Run from gitea directory ===") gitea_dir = os.path.dirname(git_exe) try: result = subprocess.run( ["git.exe"], cwd=gitea_dir, capture_output=True, text=True, timeout=5 ) print(f"Exit code: {result.returncode}") print(f"Stdout: {result.stdout}") print(f"Stderr: {result.stderr}") except Exception as e: print(f"Error: {e}") return True def check_gitea_cli(): """Check if gitea.exe can be used for git operations""" gitea_exe = r"C:\Program Files\gitea\gitea.exe" print(f"\n=== Testing gitea.exe ===") # Check gitea dump-repo command try: result = subprocess.run( [gitea_exe, "dump-repo", "--help"], capture_output=True, text=True, timeout=5 ) print(f"gitea dump-repo help:") print(result.stdout[:500]) except Exception as e: print(f"Error: {e}") def main(): print("=" * 60) print("GO-GIT ROOT CAUSE ANALYSIS") print("=" * 60) test_git_exe() check_gitea_cli() print("\n" + "=" * 60) print("ROOT CAUSE ANALYSIS") print("=" * 60) print("Based on the tests:") print("1. git.exe exists but fails with 'path not found' error") print("2. This suggests missing DLL dependencies") print("3. The git.exe is likely a Go binary that requires:") print(" - Go runtime libraries") print(" - Specific environment variables") print(" - Working directory setup") print("\nSOLUTIONS:") print("1. Install standard Git for Windows (recommended)") print("2. Use gitea.exe API commands") print("3. Use Gitea REST API directly") print("4. Set up proper environment for Go-Git") if __name__ == "__main__": main()