import os
import sys
from pathlib import Path
+from shutil import rmtree
from subprocess import CalledProcessError, check_output, run
GITWEB_CONFIGS = {
def main():
base_dir = Path.home() / "git"
- mismatched = set(GITWEB_CONFIGS) ^ {p.name for p in base_dir.iterdir() if p.is_dir()}
- if mismatched:
- print(
- f"Warning: gitweb_configs mismatch: {', '.join(mismatched)}",
- file=sys.stderr,
- )
+ for p in base_dir.iterdir():
+ if p.is_dir() and p.name not in GITWEB_CONFIGS:
+ rmtree(p)
+ print(f"removed {p.name}")
for repository, configs in GITWEB_CONFIGS.items():
p = base_dir / repository
if not p.exists():
- continue
- os.chdir(p)
+ p.mkdir(0o755)
+ os.chdir(p)
+ run(["git", "init", "--bare"])
+ print(f"created {p.name}")
+ else:
+ os.chdir(p)
description = p / "description"
if description.exists():
description.unlink()