| 1 | """Exercise Git's target object, index, reference and PCRE code offline.""" |
| 2 | from pathlib import Path |
| 3 | import os |
| 4 | import subprocess |
| 5 | |
| 6 | source = Path.cwd() |
| 7 | binary = source / "git-2.47.3/git" |
| 8 | work = source / "git-check" |
| 9 | work.mkdir() |
| 10 | os.chdir(work) |
| 11 | os.environ.update(GIT_CONFIG_NOSYSTEM="1", HOME=str(work), GIT_TERMINAL_PROMPT="0", |
| 12 | GIT_AUTHOR_NAME="Vinix", GIT_AUTHOR_EMAIL="test@invalid", |
| 13 | GIT_COMMITTER_NAME="Vinix", GIT_COMMITTER_EMAIL="test@invalid") |
| 14 | |
| 15 | def git(*args, data=None): |
| 16 | return subprocess.check_output(["vinix-run", str(binary), *args], input=data, text=True).strip() |
| 17 | |
| 18 | git("init", "-q", "--template=") |
| 19 | (work / "file").write_text("Vinix\n") |
| 20 | git("add", "file") |
| 21 | tree = git("write-tree") |
| 22 | commit = git("commit-tree", tree, data="First commit\n") |
| 23 | git("update-ref", "HEAD", commit) |
| 24 | if git("show", "HEAD:file") != "Vinix" or git("grep", "-P", "(?=Vini)Vinix") != "file:Vinix": |
| 25 | raise SystemExit("target Git object or PCRE result did not match") |
| 26 | if not (source / "git-2.47.3/git-remote-http").is_file(): |
| 27 | raise SystemExit("target Git HTTP transport is missing") |
| 28 | |