Files
GladiatorIdle/tools/push_gitea.py
2026-11-08 13:29:26 +01:00

62 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Aktuellen Spielstand nach Gitea pushen – nur was zum Bauen und Starten nötig ist.
py -3.12 tools/push_gitea.py "Nachricht"
Der Zweig `gitea-main` hat eine eigene, schlanke Historie (ohne _Archiv, Spritegenerator und alte
Sprites). Das Skript übernimmt den Stand der Ordner unten aus dem Arbeitszweig `main` als neuen
Commit in `gitea-main` (in einem eigenen Arbeitsordner, der Arbeitsbaum bleibt unberührt) und
pusht ihn nach gitea main.
"""
import os
import subprocess
import sys
import tempfile
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
REMOTE = "ssh://git@gitea.oezcan.cloud:32772/malkano.michael/GladiatorIdle.git"
BRANCH = "gitea-main"
PATHS = [".gitignore", "README.md", "CLAUDE.md", "build-release.bat", "Mono", "Game", "Core", "Languages",
"Assets", "tools", "docs", "Spiel/3D-Ansicht.bat"]
def git(*args, cwd=ROOT, check=True):
r = subprocess.run(["git", *args], cwd=cwd, capture_output=True, text=True, encoding="utf-8")
if check and r.returncode != 0:
sys.exit(f"git {' '.join(args)}: {r.stderr.strip()}")
return r.stdout
def main():
msg = sys.argv[1] if len(sys.argv) > 1 else "Aktueller Stand"
source = git("rev-parse", "HEAD").strip()
work = os.path.join(tempfile.gettempdir(), "gi_gitea_push")
git("worktree", "remove", "--force", work, check=False)
git("worktree", "prune")
git("worktree", "add", "-q", work, BRANCH)
try:
# Stand der nötigen Pfade aus main; was es dort nicht mehr gibt, fliegt raus
wanted = set(git("ls-tree", "-r", "--name-only", source, "--", *PATHS).splitlines())
have = set(git("ls-files", cwd=work).splitlines())
gone = sorted(have - wanted)
if gone:
for i in range(0, len(gone), 200):
git("rm", "-q", "--", *gone[i:i + 200], cwd=work)
git("checkout", source, "--", *[p for p in PATHS if any(w == p or w.startswith(p + "/") for w in wanted)], cwd=work)
if not git("status", "--porcelain", cwd=work).strip():
print("Nichts Neues für Gitea.")
return
git("add", "-A", cwd=work)
git("commit", "-q", "-m", f"{msg}\n\nStand von main {source[:8]}.\n\nCo-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>", cwd=work)
print(git("log", "--oneline", "-1", cwd=work).strip())
r = subprocess.run(["git", "push", REMOTE, f"{BRANCH}:main"], cwd=work, capture_output=True, text=True)
print((r.stdout + r.stderr).strip().splitlines()[-1] if (r.stdout + r.stderr).strip() else "")
if r.returncode != 0:
sys.exit("Push fehlgeschlagen")
finally:
git("worktree", "remove", "--force", work, check=False)
git("worktree", "prune", check=False)
if __name__ == "__main__":
main()