From 754d837daeb4e55c19c97ed0d8368403db8d1209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=AF=D1=86=D0=B5?= =?UTF-8?q?=D0=BD=D0=BA=D0=BE?= Date: Sat, 19 Sep 2026 01:06:22 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20=D0=BF?= =?UTF-8?q?=D1=83=D0=B1=D0=BB=D0=B8=D0=BA=D0=B0=D1=86=D0=B8=D0=B8=20=D1=81?= =?UTF-8?q?=D0=BE=D0=B1=D0=B8=D1=80=D0=B0=D0=BB=20=D0=BF=D1=83=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D0=B9=20=D1=81=D0=BD=D0=B8=D0=BC=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git checkout переключал ветку и перетирал подготовленное дерево: в снимок попадали только файлы, которых нет в открытой копии. Теперь рабочая копия начинается с опубликованного состояния, а содержимое HEAD раскладывается поверх через git archive. Co-Authored-By: Claude Opus 5 --- scripts/publish_github.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) 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("открытая копия уже совпадает с рабочей — публиковать нечего")