1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Run with stagit, stagit-index, git and rsync on PATH."""
import os
from pathlib import Path
import subprocess
import tempfile
here = Path(__file__).resolve().parent
hook = Path(os.environ["STAGIT_TEST_HOOK"]).resolve() if "STAGIT_TEST_HOOK" in os.environ else None
def run(*args, cwd=None, env=None):
return subprocess.check_output(args, cwd=cwd, env=env, text=True)
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
repos, docroot = root / "repos", root / "www"
docroot.mkdir()
(docroot / "style.css").write_text("/* user styles */")
for name in ("group/public", "group/private"):
repo = repos / (name + ".git")
repo.parent.mkdir(parents=True, exist_ok=True)
run("git", "init", "--bare", str(repo))
public = repos / "group/public.git"
private = repos / "group/private.git"
run("git", "--git-dir=" + str(public), "config", "gitolite.stagit", "true")
env = os.environ.copy()
env.update(STAGIT_SITE_NAME="Test", STAGIT_CLONE_PREFIX="https://git.example.org/",
STAGIT_SCRIPT="/enhancements.js", STAGIT_SITE_LOGO="/logo.png")
publisher = str(here / "setup-stagit-pages.sh")
run("sh", publisher, str(repos), cwd=docroot, env=env)
assert 'href="group/public/"' in (docroot / "index.html").read_text()
assert "group/private" not in (docroot / "index.html").read_text()
assert not (docroot / "group/private").exists()
assert "https://git.example.org/group/public" in (docroot / "group/public/index.html").read_text()
(docroot / "group/public/style.css").write_text("/* custom repo styles */")
run("sh", publisher, str(repos), cwd=docroot, env=env)
assert (docroot / "style.css").read_text() == "/* user styles */"
assert (docroot / "group/public/style.css").read_text() == "/* custom repo styles */"
if hook:
pending = root / "pending"
env.update(GL_REPO="group/private", STAGIT_PENDING=str(pending))
subprocess.run(["sh", str(hook)], cwd=private, env=env, input="", check=True, text=True)
assert not pending.exists()
env["GL_REPO"] = "group/public"
subprocess.run(["sh", str(hook)], cwd=public, env=env, input="", check=True, text=True)
assert pending.exists()
print("Publisher and hook checks passed")