mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-16 14:52:11 +00:00
Compare commits
561 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f9ad679833 | |||
| c4fa88e8ee | |||
| d43980c976 | |||
| f6607440ad | |||
| 8750430cde | |||
| 640f8bd824 | |||
| bf2835cfc7 | |||
| a0663d32e0 | |||
| 534b1feb58 | |||
| bb9cdc483d | |||
| 04799a8ac1 | |||
| 75e2205b3d | |||
| 75014d2ec9 | |||
| 28685780f3 | |||
| 609dbae864 | |||
| 7ef1502249 | |||
| 2f13853084 | |||
| 9f262e5d2f | |||
| ba80523d6c | |||
| af20f6128c | |||
| 92f2992b97 | |||
| ab1ebed5f4 | |||
| 6dc4c9d1b3 | |||
| c49615aab6 | |||
| 340a2e706b | |||
| 5204c257cf | |||
| 3126ad5266 | |||
| 2fa4771b54 | |||
| dd869cef36 | |||
| 62b4046366 | |||
| f0bd6c4015 | |||
| 6cc43ed16d | |||
| 5b8d1ebb27 | |||
| c0326288ff | |||
| 97f43bc6a7 | |||
| b52e9be5f9 | |||
| cae1f48035 | |||
| 1f5b678139 | |||
| b778a1c3f9 | |||
| 074452e6a9 | |||
| 7edd60c10a | |||
| c7af223155 | |||
| a79aa4e9a7 | |||
| d0c972c69b | |||
| 78c958e8f5 | |||
| 3ee7fcab59 | |||
| 75932ec507 | |||
| ee84d6ec32 | |||
| a8001ec19d | |||
| 95cd4760b7 | |||
| 0297527965 | |||
| f56935e48b | |||
| b9e0f73534 | |||
| 7f560decd3 | |||
| 88fdf35dc5 | |||
| b4fe6270a9 | |||
| c103b6b22e | |||
| 0e860fe6a9 | |||
| 894235569e | |||
| fdccde6137 | |||
| 043b1d3628 | |||
| afc5c42e30 | |||
| 74b7c22b6c | |||
| cf27b2f3f9 | |||
| 4aa442a802 | |||
| 3964336370 | |||
| 625579ebbb | |||
| ed71f7871d | |||
| ff8d1abf8a | |||
| a74b18f62a | |||
| 323a1ac021 | |||
| 993b303e2f | |||
| 3b7248cb00 | |||
| e35e028001 | |||
| 2c19e4565e | |||
| 853e952128 | |||
| 041544917c | |||
| 3ed4dcfbb4 | |||
| 276e814515 | |||
| 5dd2aadd7c | |||
| 19fbd27f3a | |||
| 8deea0584c | |||
| 9f0fadf908 | |||
| d176b762f7 | |||
| 85d276f2d4 | |||
| b031bd9fdc | |||
| b3722deef2 | |||
| 961ca74c14 | |||
| 0f596cbdba | |||
| 85be1ce9fc | |||
| 5983439a5d | |||
| fd4c066008 | |||
| dc8787956d | |||
| b499a6b456 | |||
| 1a4f4a6f17 | |||
| f44994688e | |||
| 2da45012f3 | |||
| ff9d2c67f0 | |||
| 20ac94b61d | |||
| e2d286d7b6 | |||
| 21ec8d8bc9 | |||
| e263857e4f | |||
| aa92b7f512 | |||
| 4ece2f215e | |||
| 85f91b3994 | |||
| ca2e1a35aa | |||
| f9dcec6d9e | |||
| 8ba676df9f | |||
| 69bf2973b9 | |||
| 41ad91ab93 | |||
| a4065684b0 | |||
| cc57b0c52d | |||
| 2e23956986 | |||
| f9c2bbf993 | |||
| b6bbb50707 | |||
| 3d5d8a2c14 | |||
| 9823a94025 | |||
| 194674705e | |||
| b513704a3d | |||
| 15253f95fb | |||
| 69afb00897 | |||
| e4a47d025c | |||
| 4f109da335 | |||
| 230242bf5c | |||
| e290e7d656 | |||
| 62f6b64bfb | |||
| cd307d642e | |||
| 81c43aadcc | |||
| 73057921ec | |||
| cd1beac93f | |||
| 784163b9c9 | |||
| 8429d4efd5 | |||
| 06192c41ad | |||
| 22730776d4 | |||
| a72dba291b | |||
| b98e3e4ebc | |||
| ff2669d079 | |||
| 05166859a3 | |||
| 4a6afa14cc | |||
| 5a74e813eb | |||
| be3f639573 | |||
| 620e6ddc06 | |||
| 6a6821ce4c | |||
| 2bb65bbc40 | |||
| aa63ffc754 | |||
| 0dbb79719b | |||
| 06d17a2e4d | |||
| ecc2e1f107 | |||
| a981209399 | |||
| 885f492f69 | |||
| 5363969456 | |||
| 637926973c | |||
| 9701c7233f | |||
| e6960c98b8 | |||
| 3f4018fa00 | |||
| 9af2d34179 | |||
| 93db61558c | |||
| 97f780688e | |||
| 49e1121967 | |||
| f4f4deb848 | |||
| b15c2f06b8 | |||
| 14b9a50f51 | |||
| 090adf3741 | |||
| 68d17a11b3 | |||
| 1b26fdd841 | |||
| f1129f18cb | |||
| 64669887a3 | |||
| 6d3ce5d714 | |||
| e05f58624a | |||
| 651d796254 | |||
| b3e5a1aaf3 | |||
| 1f0e03590d | |||
| 0ad06cc69c | |||
| 6b5d312231 | |||
| 0674e1a1a8 | |||
| 61acd3f3f3 | |||
| 3ccc89f572 | |||
| 86f512cb34 | |||
| bf808eb634 | |||
| d3bd79b505 | |||
| 24247aa760 | |||
| 443d06280b | |||
| 1625149c64 | |||
| 93330638be | |||
| a830dfb18c | |||
| 28c1565405 | |||
| de3bae7a7f | |||
| 94132a8962 | |||
| 88d8a1bcbe | |||
| dbe33286da | |||
| bbc91fbd73 | |||
| f0bb8f7ac2 | |||
| 061bab8e6d | |||
| bda7c6cc2e | |||
| 3d02d06862 | |||
| c225a3e252 | |||
| 489dd9feb6 | |||
| 63366f7ea1 | |||
| 73f184b263 | |||
| d53feec563 | |||
| ab199fc285 | |||
| baeb3de67e | |||
| 6aec5d05d2 | |||
| d56b0b7f1d | |||
| f0d0ebb859 | |||
| 972387f660 | |||
| 9a0f869839 | |||
| 28fdfa0982 | |||
| 1b4746aa9d | |||
| f81763a865 | |||
| 2147de594d | |||
| c6f57bc2aa | |||
| ffeaa9437b | |||
| c4e0dea7da | |||
| a8e32d6b05 | |||
| 02cd2ba5df | |||
| 46de87e874 | |||
| 7197309e1d | |||
| b82dfe38da | |||
| 4448b079e6 | |||
| f45dc906ac | |||
| 253a82e694 | |||
| 6019b92d15 | |||
| c33cfc27ba | |||
| ee785bbdb8 | |||
| b4d1a7b321 | |||
| aec60b217c | |||
| ef0be53a96 | |||
| 3398d5df92 | |||
| e5d202ad3d | |||
| 71e5462617 | |||
| 8e6f562fd4 | |||
| 58617dc410 | |||
| c7e02c48ae | |||
| 77e22e6cb7 | |||
| 1cc7c0b51c | |||
| 94fe448326 | |||
| 66906c4486 | |||
| 62d60218db | |||
| 28c5f36cb0 | |||
| 024c42a800 | |||
| 590ab187d8 | |||
| 80c69a8823 | |||
| 61a6d1f530 | |||
| a1cfa1852e | |||
| 422209c3f5 | |||
| 81c477999f | |||
| c714bdb2d7 | |||
| 26c34c6fa9 | |||
| f1d73fc0a1 | |||
| d027a961b7 | |||
| 0278dc3a49 | |||
| 4184cbb687 | |||
| 88926ec627 | |||
| e628b18354 | |||
| b025790b3d | |||
| b3121aaaf2 | |||
| 2e13593433 | |||
| b78f542778 | |||
| 39865253fe | |||
| b2e414a268 | |||
| e3ad25b95e | |||
| 62bb650b37 | |||
| dbca290979 | |||
| 0ed0f60b9f | |||
| 02e8d4effd | |||
| 9c686ded98 | |||
| 6a50568d25 | |||
| a60e99cd6e | |||
| cc5f97f1d6 | |||
| 0a248ef3fb | |||
| 582ae365c7 | |||
| fad17ef9a8 | |||
| 945ed5677b | |||
| 6c68b574a2 | |||
| 3c177b7538 | |||
| 1419be48a1 | |||
| 80360e0dde | |||
| 48fce96250 | |||
| e1a38bcdcd | |||
| 529c8ba20a | |||
| 2a87153e71 | |||
| 4a769006a8 | |||
| 13029b25b5 | |||
| 9567cb07e2 | |||
| 33ded0ffe9 | |||
| a4dceb8651 | |||
| ada24f505d | |||
| 28db612fad | |||
| 520d995553 | |||
| 49f393fc47 | |||
| 0ce3710b29 | |||
| cb8ad5ca08 | |||
| 373ea608d9 | |||
| 9052e3e505 | |||
| ad2a1a21e2 | |||
| e1e0a3569b | |||
| 2f183c3afb | |||
| 1b0695d6c2 | |||
| 1a31175db9 | |||
| e34dc37dc1 | |||
| 2646178a28 | |||
| dd0b679bfc | |||
| 73b7a4bfa4 | |||
| 8b134ddcc9 | |||
| 6011ab5cd4 | |||
| 5697f057d9 | |||
| 2d43f6a658 | |||
| c6c1c2f25d | |||
| 3930b940e8 | |||
| 12efaceaf6 | |||
| d3ac0ed0b1 | |||
| 554852bc53 | |||
| 7f57da86f0 | |||
| acfda1e29e | |||
| 94208918d5 | |||
| cea6a37de5 | |||
| 6c58ce90ac | |||
| fddc6b1976 | |||
| 89f4b0e51e | |||
| 781b83c9b1 | |||
| 944bb7e5fa | |||
| 7e4e8f167f | |||
| b59bd4c41d | |||
| 6dd0e1865d | |||
| b6cb5e03b7 | |||
| 7fae6b601e | |||
| f9c854e2fc | |||
| 169552e8d5 | |||
| c448201823 | |||
| 7857226e12 | |||
| e6648926a6 | |||
| ce9beb5ecf | |||
| 63fb7a3b8a | |||
| fd23518f7a | |||
| 5ea792bcd2 | |||
| 1d520c4aeb | |||
| dbcb8cce27 | |||
| 215a36f91e | |||
| ecabfc8876 | |||
| 20f045e92a | |||
| c90e90ea10 | |||
| fcefaf11ef | |||
| 8c6e80d832 | |||
| 96b93488c7 | |||
| c31390859f | |||
| 314a77c1f9 | |||
| 0345573cb8 | |||
| 4842ccdc22 | |||
| adb0f9b468 | |||
| ce806c873f | |||
| a54a6686c2 | |||
| d226d99236 | |||
| a827c5e429 | |||
| 71d8e03933 | |||
| 803ad01a83 | |||
| 81d5fcfb8f | |||
| 4d79c51e20 | |||
| f320b20850 | |||
| c39900e15f | |||
| c728396205 | |||
| 0f7e5d4a25 | |||
| ce91aec6ff | |||
| 759c06aa50 | |||
| 1ebd58b8ac | |||
| 82bb6cbbad | |||
| e54150fd5d | |||
| 167fe59456 | |||
| 3a02846a17 | |||
| 9c3e51631c | |||
| c3dd4ad8cf | |||
| 5d51e99c70 | |||
| 2c9c86990c | |||
| b87cf7f4d8 | |||
| a68745713b | |||
| bbe1b89007 | |||
| 27fefdccb5 | |||
| 64849f728f | |||
| 9b09c2c13f | |||
| f2fb2232ee | |||
| 7e4dfbf8cd | |||
| 81a387eb4f | |||
| 408f6e5c4e | |||
| a266e5d240 | |||
| 917b57c586 | |||
| 0e15218abd | |||
| f56773b2e1 | |||
| 944dfe2c18 | |||
| 2fd362a1d5 | |||
| 47945ab3dd | |||
| c0b362df6d | |||
| 575237812f | |||
| 60787d8162 | |||
| 8dc4eef149 | |||
| 0f49cb89a3 | |||
| 99f24e6b77 | |||
| 9b14610cc9 | |||
| 14df489b38 | |||
| 8a99ee7c99 | |||
| 3684003150 | |||
| f3b03827e2 | |||
| 848668b8ed | |||
| f1cc24cc06 | |||
| 1cbd44c333 | |||
| 9ba3f1d3ed | |||
| 032cc41c9b | |||
| 217533c91f | |||
| 80f4254ebe | |||
| 5967aefda7 | |||
| 3b232ac3d7 | |||
| 7c0de660fd | |||
| 7de1ad43fd | |||
| fcbda81213 | |||
| 1e00c1fe33 | |||
| 5e810d23ab | |||
| 439c5c753c | |||
| cc11d3f75e | |||
| a35d7da6e3 | |||
| 2c50318f1c | |||
| addc534c36 | |||
| 430b4de995 | |||
| 9d00e40b41 | |||
| 7d29c1d397 | |||
| ce3ad9f8f0 | |||
| abef18f4ad | |||
| 5beb1c6fdd | |||
| ff69091495 | |||
| 69d3c8849c | |||
| b2aab28460 | |||
| 082b25c89c | |||
| 6fefede271 | |||
| c1054241eb | |||
| 04ad1e7005 | |||
| 89bd1b16ae | |||
| 90674c288f | |||
| b4d4f47519 | |||
| 477430e9a3 | |||
| 7dc53ef6b4 | |||
| 837d9be348 | |||
| 499d9c5715 | |||
| 70959da16a | |||
| 8f360417a9 | |||
| aad0477e29 | |||
| fe81f5e8fc | |||
| 6d51412ea3 | |||
| 382cf5d501 | |||
| e121c6dc39 | |||
| 548496e0a6 | |||
| 99409f7c0b | |||
| fd1107cd1b | |||
| f08ce02e85 | |||
| 78346d8448 | |||
| c780308541 | |||
| cc0af0ce32 | |||
| 99e3dd7dca | |||
| 16ead67cf3 | |||
| 5ca73d6ac9 | |||
| f3e690f395 | |||
| 8293b3a69c | |||
| 0ac9006665 | |||
| d912d9bc1b | |||
| b08642dd88 | |||
| 8b1950823b | |||
| 6589b73329 | |||
| 89003c32c9 | |||
| 17eace3e73 | |||
| 3f2248336d | |||
| f8664c0fd1 | |||
| 82273df13c | |||
| ae0d807714 | |||
| edc0a4a502 | |||
| 39ecb82395 | |||
| d8f5bd1805 | |||
| 3f68c6aaed | |||
| aee53de258 | |||
| 20caa5600a | |||
| 4a4f8df06e | |||
| 6c9f01971a | |||
| 211c45891e | |||
| de3d6a8f42 | |||
| 9c027fd636 | |||
| 9af6b8e187 | |||
| d00ede6c62 | |||
| 5b7d7b31b2 | |||
| 00172920a9 | |||
| 5e3ffdacb5 | |||
| 471d4e923b | |||
| d11f5d8d24 | |||
| cfb26d95a4 | |||
| 5e14299fef | |||
| 126de9a4a4 | |||
| 0d132983fc | |||
| 67cae0e68e | |||
| eabd0e8e1e | |||
| f7c91e3874 | |||
| c224b2ccc8 | |||
| 3ca9f2c6f3 | |||
| c52d55e0a2 | |||
| e1fa15abb3 | |||
| 74c76e639d | |||
| 35a65e48e9 | |||
| 5d5c136b41 | |||
| b9fbc0f910 | |||
| fd742c8f1c | |||
| 1c240342c5 | |||
| 7bd0c0aca4 | |||
| 7c8ad99743 | |||
| 90896fa9be | |||
| e3bec6bc11 | |||
| aa00045dec | |||
| 06e3671ec2 | |||
| 0879796cc6 | |||
| 9f756b3092 | |||
| 579a3f2a52 | |||
| 5505022dbb | |||
| d2e5a34b87 | |||
| c7696fafdc | |||
| 7f3de2ea13 | |||
| ec505f050f | |||
| f55c4ce1a7 | |||
| 432abc73b9 | |||
| cdaf2589b3 | |||
| 67ab3b4bba | |||
| 71623d9812 | |||
| ce54233908 | |||
| b0df66c5da | |||
| fda2733600 | |||
| 027050a4dd | |||
| b22b9add15 | |||
| 1fd5b8cfac | |||
| 5e3d90c038 | |||
| fef53a3587 | |||
| be1e338e54 | |||
| d6dd276a92 | |||
| a0cddaa1f0 | |||
| 38355da861 | |||
| 03c73fc55e | |||
| 77089d408b | |||
| f05ae2b006 | |||
| bca63dd94a | |||
| 2641965792 | |||
| dc9946533e | |||
| 0a39eba723 | |||
| 114cfc35bc | |||
| 6a92ff4956 | |||
| c9d371d941 | |||
| 8aa980ff9c | |||
| 063f15e3a6 | |||
| 8e64482623 | |||
| f686552337 | |||
| f29672684a | |||
| c8d47ee118 | |||
| 5173ed2e52 | |||
| ddf1c5fdca | |||
| 0c9298baa4 | |||
| d3169786ff | |||
| f2d5673555 | |||
| 907a1aa987 | |||
| 6bc77f3720 | |||
| 48f49d59e0 | |||
| 39d3c12072 |
@@ -81,7 +81,7 @@ sudo apt-get install docker-compose-plugin
|
|||||||
`/mnt/conjurer`.
|
`/mnt/conjurer`.
|
||||||
5. Start only the musician service:
|
5. Start only the musician service:
|
||||||
```bash
|
```bash
|
||||||
docker compose up --build -d musician
|
docker compose --profile musician up --build -d musician
|
||||||
```
|
```
|
||||||
Alternatively, duplicate `docker-compose.yml`, strip other services, and run
|
Alternatively, duplicate `docker-compose.yml`, strip other services, and run
|
||||||
`docker compose up -d`.
|
`docker compose up -d`.
|
||||||
|
|||||||
@@ -1,296 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
"""
|
|
||||||
Buduje nową gałąź z "próbkowanych" commitów na podstawie tagów z bieżącej gałęzi,
|
|
||||||
a na końcu dodaje stan bieżącego HEAD (jeśli nie jest otagowany).
|
|
||||||
Autor: (drop-in)
|
|
||||||
"""
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
from typing import List, Tuple, Optional
|
|
||||||
|
|
||||||
# --- Logging setup ---
|
|
||||||
logger = logging.getLogger("tag_branch_builder")
|
|
||||||
handler = logging.StreamHandler(sys.stdout)
|
|
||||||
formatter = logging.Formatter("%(levelname)s: %(message)s")
|
|
||||||
handler.setFormatter(formatter)
|
|
||||||
logger.addHandler(handler)
|
|
||||||
logger.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
|
|
||||||
class GitError(RuntimeError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def run_git(args: List[str], cwd: Optional[str] = None, check: bool = True) -> str:
|
|
||||||
"""Run a git command and return stdout (stripped)."""
|
|
||||||
cmd = ["git"] + args
|
|
||||||
logger.debug("Running: %s", " ".join(cmd))
|
|
||||||
try:
|
|
||||||
proc = subprocess.run(
|
|
||||||
cmd,
|
|
||||||
cwd=cwd,
|
|
||||||
check=False,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.PIPE,
|
|
||||||
text=True,
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
raise Exception("Nie udało się uruchomić gita.") from e
|
|
||||||
raise
|
|
||||||
|
|
||||||
if check and proc.returncode != 0:
|
|
||||||
logger.error("Git error (%s): %s", " ".join(cmd), proc.stderr.strip())
|
|
||||||
raise GitError(proc.stderr.strip())
|
|
||||||
return proc.stdout.strip()
|
|
||||||
|
|
||||||
|
|
||||||
def ensure_git_repo() -> None:
|
|
||||||
try:
|
|
||||||
run_git(["rev-parse", "--is-inside-work-tree"])
|
|
||||||
except Exception:
|
|
||||||
logger.exception("To nie wygląda na repozytorium git.")
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
def ensure_clean_worktree() -> None:
|
|
||||||
# Untracked + changes
|
|
||||||
status = run_git(["status", "--porcelain"])
|
|
||||||
if status.strip():
|
|
||||||
raise GitError(
|
|
||||||
"Drzewo robocze nie jest czyste. Zacommituj/stashuj zmiany i spróbuj ponownie."
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def current_branch() -> str:
|
|
||||||
# Returns branch or 'HEAD' when detached
|
|
||||||
ref = run_git(["rev-parse", "--abbrev-ref", "HEAD"])
|
|
||||||
return ref
|
|
||||||
|
|
||||||
|
|
||||||
def head_sha() -> str:
|
|
||||||
return run_git(["rev-parse", "HEAD"])
|
|
||||||
|
|
||||||
|
|
||||||
def sha_has_tag(sha: str) -> List[str]:
|
|
||||||
# tags pointing at sha
|
|
||||||
tags = run_git(["tag", "--points-at", sha])
|
|
||||||
return [t for t in tags.splitlines() if t.strip()]
|
|
||||||
|
|
||||||
|
|
||||||
def tags_merged_into(branch: str) -> List[str]:
|
|
||||||
out = run_git(["tag", "--merged", branch])
|
|
||||||
return [t for t in out.splitlines() if t.strip()]
|
|
||||||
|
|
||||||
|
|
||||||
def tag_commit_sha(tag: str) -> str:
|
|
||||||
return run_git(["rev-list", "-n", "1", tag])
|
|
||||||
|
|
||||||
|
|
||||||
def commit_unix_time(sha: str) -> int:
|
|
||||||
return int(run_git(["show", "-s", "--format=%ct", sha]))
|
|
||||||
|
|
||||||
|
|
||||||
def sort_tags_by_commit_time(tags: List[str]) -> List[Tuple[str, str, int]]:
|
|
||||||
triples = []
|
|
||||||
for t in tags:
|
|
||||||
sha = tag_commit_sha(t)
|
|
||||||
ts = commit_unix_time(sha)
|
|
||||||
triples.append((t, sha, ts))
|
|
||||||
triples.sort(key=lambda x: x[2]) # oldest first
|
|
||||||
return triples
|
|
||||||
|
|
||||||
|
|
||||||
def list_intermediate_messages(old_sha: Optional[str], new_sha: str) -> List[str]:
|
|
||||||
"""
|
|
||||||
Zwróć listę komunikatów commitów POŚREDNICH (wyłącznie) od old_sha do new_sha.
|
|
||||||
Kolejność: od najstarszego do najnowszego.
|
|
||||||
"""
|
|
||||||
if old_sha is None:
|
|
||||||
# Nie ma commitów pośrednich przed pierwszym tagiem
|
|
||||||
return []
|
|
||||||
# ancestry-path: tylko ścieżka od old_sha do new_sha (jeśli wiele rodziców)
|
|
||||||
# Zakres old_sha..new_sha zawiera new_sha, dlatego pominiemy go w output.
|
|
||||||
rng = f"{old_sha}..{new_sha}"
|
|
||||||
try:
|
|
||||||
out = run_git(
|
|
||||||
["log", "--format=%s", "--reverse", "--ancestry-path", rng], check=True
|
|
||||||
)
|
|
||||||
except GitError:
|
|
||||||
# Brak ścieżki (np. tag nie jest potomkiem old_sha) – wtedy nie ma pośrednich
|
|
||||||
return []
|
|
||||||
msgs = [ln for ln in out.splitlines() if ln.strip()]
|
|
||||||
if msgs:
|
|
||||||
# Ostatnia pozycja może być new_sha (w praktyce git log na %s nie odróżnia, ale
|
|
||||||
# jeśli zakres zwróci message z new_sha na końcu, usuniemy go porównując SHA).
|
|
||||||
# Prostsze: usuń ostatni wpis, bo to najnowszy (new_sha).
|
|
||||||
msgs = msgs[:-1]
|
|
||||||
return msgs
|
|
||||||
|
|
||||||
|
|
||||||
def checkout_orphan_branch(new_branch: str) -> None:
|
|
||||||
run_git(["checkout", "--orphan", new_branch])
|
|
||||||
# Usuń wszystko z indeksu i roboczego (z wyjątkiem .git)
|
|
||||||
# Najpierw usuń śledzone:
|
|
||||||
run_git(["rm", "-r", "--quiet", "--cached", "--force", "."], check=False)
|
|
||||||
# Potem pliki robocze:
|
|
||||||
for root, dirs, files in os.walk(".", topdown=False):
|
|
||||||
# pomiń .git
|
|
||||||
if root.startswith("./.git") or root == ".git":
|
|
||||||
continue
|
|
||||||
for name in files:
|
|
||||||
try:
|
|
||||||
os.remove(os.path.join(root, name))
|
|
||||||
except FileNotFoundError:
|
|
||||||
pass
|
|
||||||
for name in dirs:
|
|
||||||
p = os.path.join(root, name)
|
|
||||||
if p == "./.git":
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
os.rmdir(p)
|
|
||||||
except OSError:
|
|
||||||
# Niepuste – to OK, wyczyścimy przy checkout
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def replace_worktree_with_commit(sha: str) -> None:
|
|
||||||
"""
|
|
||||||
Nadpisz zawartość roboczą drzewem z commit-a sha.
|
|
||||||
"""
|
|
||||||
# Najpierw usuń aktualne pliki (również nieśledzone), potem wczytaj tree wybranego commita:
|
|
||||||
# 1) git checkout <sha> -- . (zapisze pliki do working tree + index)
|
|
||||||
# 2) git add -A
|
|
||||||
# Aby dopilnować usunięć: zrób czyszczenie przez git rm -r ., potem checkout.
|
|
||||||
run_git(["rm", "-r", "--quiet", "--ignore-unmatch", "."], check=False)
|
|
||||||
# Przywróć pliki ze wskazanego commita:
|
|
||||||
# Uwaga: jeśli repo ma submoduły/large files – to wykracza poza zakres, ale zadziała dla standardowych plików.
|
|
||||||
run_git(["checkout", sha, "--", "."])
|
|
||||||
run_git(["add", "-A"])
|
|
||||||
|
|
||||||
|
|
||||||
def build_commit_message_for_tag(tag: str, intermediates: List[str]) -> str:
|
|
||||||
if not intermediates:
|
|
||||||
return f"Tag: {tag}"
|
|
||||||
lines = ["Tag: " + tag, "", "Intermediate commits (oldest → newest):"]
|
|
||||||
lines += [f"- {m}" for m in intermediates]
|
|
||||||
return "\n".join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def build_commit_message_for_head(since_tag: Optional[str], intermediates: List[str]) -> str:
|
|
||||||
title = "HEAD (unreleased)"
|
|
||||||
hdr = title if since_tag is None else f"{title} since tag {since_tag}"
|
|
||||||
if not intermediates:
|
|
||||||
return hdr
|
|
||||||
lines = [hdr, "", "Intermediate commits (oldest → newest):"]
|
|
||||||
lines += [f"- {m}" for m in intermediates]
|
|
||||||
return "\n".join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def commit_all(message: str) -> None:
|
|
||||||
# Zacommituj wszystko co w indeksie (po replace_worktree_with_commit daliśmy add -A)
|
|
||||||
run_git(["commit", "-m", message])
|
|
||||||
|
|
||||||
|
|
||||||
def push_new_branch(remote_url: str, branch: str) -> None:
|
|
||||||
# Dodaj zdalny 'newrepo' jeśli nie istnieje, ustaw URL i wypchnij
|
|
||||||
remotes = run_git(["remote"]).splitlines()
|
|
||||||
if "newrepo" not in remotes:
|
|
||||||
run_git(["remote", "add", "newrepo", remote_url])
|
|
||||||
else:
|
|
||||||
# podmień URL na wszelki wypadek
|
|
||||||
run_git(["remote", "set-url", "newrepo", remote_url])
|
|
||||||
run_git(["push", "-u", "newrepo", f"{branch}:{branch}"])
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
description="Zbuduj nową gałąź na podstawie tagów z bieżącej gałęzi."
|
|
||||||
)
|
|
||||||
parser.add_argument("new_branch", help="Nazwa nowej gałęzi do utworzenia")
|
|
||||||
parser.add_argument(
|
|
||||||
"--new-repo-url",
|
|
||||||
dest="new_repo_url",
|
|
||||||
default=None,
|
|
||||||
help="(Opcjonalnie) adres URL nowego zdalnego repo – zostanie dodany jako 'newrepo' i wykonany push nowej gałęzi.",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"-v", "--verbose", action="store_true", help="Bardziej gadatliwe logi"
|
|
||||||
)
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
if args.verbose:
|
|
||||||
logger.setLevel(logging.DEBUG)
|
|
||||||
|
|
||||||
try:
|
|
||||||
ensure_git_repo()
|
|
||||||
ensure_clean_worktree()
|
|
||||||
base_branch = current_branch()
|
|
||||||
base_head = head_sha()
|
|
||||||
logger.info("Bieżąca gałąź: %s", base_branch)
|
|
||||||
logger.info("HEAD: %s", base_head[:12])
|
|
||||||
|
|
||||||
# Zbierz tagi osiągalne z bieżącej gałęzi
|
|
||||||
merged_tags = tags_merged_into(base_branch)
|
|
||||||
if not merged_tags:
|
|
||||||
logger.warning(
|
|
||||||
"Nie znaleziono tagów osiągalnych z bieżącej gałęzi. Gałąź zostanie zbudowana tylko z HEAD."
|
|
||||||
)
|
|
||||||
|
|
||||||
# Posortuj tagi po czasie commita
|
|
||||||
sorted_tags = sort_tags_by_commit_time(merged_tags)
|
|
||||||
|
|
||||||
# Sprawdź czy HEAD jest otagowany
|
|
||||||
head_tags = sha_has_tag(base_head)
|
|
||||||
head_is_tagged = bool(head_tags)
|
|
||||||
|
|
||||||
# Utwórz orphan branch
|
|
||||||
logger.info("Tworzę sierocą gałąź: %s", args.new_branch)
|
|
||||||
checkout_orphan_branch(args.new_branch)
|
|
||||||
|
|
||||||
prev_sha: Optional[str] = None
|
|
||||||
last_tag_name: Optional[str] = None
|
|
||||||
|
|
||||||
# Dla każdego tagu – commit z jego zawartości
|
|
||||||
for tag_name, tag_sha, _ts in sorted_tags:
|
|
||||||
logger.info("Przetwarzam tag: %s (%s)", tag_name, tag_sha[:12])
|
|
||||||
replace_worktree_with_commit(tag_sha)
|
|
||||||
intermediates = list_intermediate_messages(prev_sha, tag_sha)
|
|
||||||
msg = build_commit_message_for_tag(tag_name, intermediates)
|
|
||||||
commit_all(msg)
|
|
||||||
prev_sha = tag_sha
|
|
||||||
last_tag_name = tag_name
|
|
||||||
|
|
||||||
# Jeśli HEAD nie jest dokładnie ostatnim tagiem – dorzuć "unreleased"
|
|
||||||
if not head_is_tagged:
|
|
||||||
logger.info("Dodaję końcowy commit z bieżącego HEAD (unreleased).")
|
|
||||||
replace_worktree_with_commit(base_head)
|
|
||||||
inter = list_intermediate_messages(prev_sha, base_head)
|
|
||||||
msg = build_commit_message_for_head(last_tag_name, inter)
|
|
||||||
commit_all(msg)
|
|
||||||
else:
|
|
||||||
logger.info("HEAD jest oznaczony tagiem – kończę na ostatnim tagu.")
|
|
||||||
|
|
||||||
# Push do nowego repo jeśli podano
|
|
||||||
if args.new_repo_url:
|
|
||||||
logger.info("Wypycham nową gałąź do: %s", args.new_repo_url)
|
|
||||||
push_new_branch(args.new_repo_url, args.new_branch)
|
|
||||||
|
|
||||||
logger.info("Zakończono pomyślnie.")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
except GitError as ge:
|
|
||||||
logger.error("Błąd gita: %s", ge)
|
|
||||||
return 2
|
|
||||||
except Exception as e:
|
|
||||||
raise Exception("Nieoczekiwany błąd.") from e
|
|
||||||
return 1
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(main())
|
|
||||||
Reference in New Issue
Block a user