#!/usr/bin/env python3 """Check the fixed wrapper using real Git in a disposable isolated repository. Usage: python3 test_git_integration.py /path/to/fixed/git-external-diff Do not run this test on the original buggy wrapper; use the recording-Git unit test for the baseline to prevent recursive documentation examples. """ import os from pathlib import Path import subprocess import sys import tempfile script = Path(sys.argv[1]).resolve() with tempfile.TemporaryDirectory(prefix='pg-diff-integration-') as tmp: root = Path(tmp) env = {**os.environ, 'HOME': tmp, 'GIT_CONFIG_NOSYSTEM': '1', 'GIT_CONFIG_GLOBAL': str(root / 'global-config')} def git(*args): return subprocess.run(['git', *args], cwd=root, env=env, check=True, text=True, capture_output=True, timeout=10).stdout git('init', '--quiet') source = root / 'source file.c' source.write_text('old line\n') git('add', 'source file.c') git('-c', 'user.name=Test', '-c', 'user.email=test@example.invalid', 'commit', '--quiet', '-m', 'fixture') config_before = (root / '.git/config').read_bytes() source.write_text('new line\n') output = git('-c', f'diff.external=/bin/bash {script}', 'diff') assert '*** a/source file.c\n--- b/source file.c\n' in output assert '! old line' in output and '! new line' in output assert (root / '.git/config').read_bytes() == config_before assert not (root / 'global-config').exists() print('Real Git integration: PASS (spaced filename, context diff, no config changes)')