diff --git a/scripts/publish_github.py b/scripts/publish_github.py index 6eae578..d649955 100644 --- a/scripts/publish_github.py +++ b/scripts/publish_github.py @@ -59,15 +59,30 @@ def changelog(remote: str) -> list[str]: return [line for line in lines if not line.startswith("Открытая копия")] -def build_tree(target: Path) -> None: - """Рабочее дерево без лишнего плюс накладка из publish/.""" - git("worktree", "add", "--detach", str(target), "HEAD") +def fill_tree(target: Path) -> None: + """Кладём в рабочую копию дерево HEAD: без лишнего и с накладкой. + + Именно кладём поверх, а не переключаем ветку: `git checkout` перетёр бы + подготовленное содержимое состоянием открытой копии, и снимок вышел бы + пустым. + """ + for item in target.iterdir(): + if item.name == ".git": + continue + shutil.rmtree(item) if item.is_dir() else item.unlink() + + archive = subprocess.run( + ["git", "archive", "HEAD"], cwd=ROOT, check=True, stdout=subprocess.PIPE + ).stdout + subprocess.run(["tar", "-x", "-C", str(target)], input=archive, check=True) + for name in EXCLUDE: path = target / name if path.is_dir(): shutil.rmtree(path) elif path.exists(): path.unlink() + for item in OVERLAY.iterdir(): destination = target / item.name if item.is_dir(): @@ -92,11 +107,11 @@ def main() -> int: with tempfile.TemporaryDirectory() as tmp: tree = Path(tmp) / "publish-tree" - build_tree(tree) + # Рабочая копия начинается с того, что уже опубликовано, — тогда git + # сам увидит и удаления, и добавления. + git("worktree", "add", "--detach", str(tree), f"{args.remote}/main") try: - git("checkout", "-B", "github-publish", f"{args.remote}/main", cwd=tree) - # Переносим содержимое снимка поверх открытой ветки: git сам - # увидит и удаления, и добавления. + fill_tree(tree) git("add", "-A", cwd=tree) if not git("status", "--porcelain", cwd=tree): print("открытая копия уже совпадает с рабочей — публиковать нечего")