"""Create the six-file reproduction in an empty GitLab repository.
Usage: python3 seed.py <empty-repository-url> <new-local-directory>
Then open an MR from feature to main using the real GitLab service.
"""
from pathlib import Path
import subprocess
import sys
repo, directory = sys.argv[1:]
p = Path(directory)
p.mkdir(parents=True)
def git(*args):
    subprocess.run(['git', *args], cwd=p, check=True)
git('init', '-b', 'main')
git('config', 'user.name', 'Scenario')
git('config', 'user.email', 'scenario@example.invalid')
for pkg in ['pkg-a', 'pkg-b']:
    for name in ['index', 'utils']:
        f = p / pkg / 'src' / f'{name}.ts'
        f.parent.mkdir(parents=True, exist_ok=True)
        f.write_text(f'export const {"u" if name == "utils" else "i"} = 1;\n')
git('add', '.')
git('commit', '-m', 'Initial sources')
git('remote', 'add', 'origin', repo)
git('push', '-u', 'origin', 'main')
git('checkout', '-b', 'feature')
for pkg in ['pkg-a', 'pkg-b']:
    for name in ['index', 'utils']:
        content = 'import { u } from "./utils";\nexport const i = u + 1;\n' if pkg == 'pkg-b' and name == 'index' else f'export const {"u" if name == "utils" else "i"} = 2;\n'
        (p / pkg / 'src' / f'{name}.ts').write_text(content)
for name in ['index', 'utils']:
    (p / 'pkg-b' / 'src' / f'{name}.test.ts').write_text(f'import {{ {"u" if name == "utils" else "i"} }} from "./{name}";\n')
git('add', '.')
git('commit', '-m', 'Change sources and add colocated tests')
git('push', '-u', 'origin', 'feature')
