refactor(git): centralize auto branch prefix
Python package / build (3.12.3) (pull_request) Canceled after 52s
Python package / build (3.13) (pull_request) Canceled after 0s
Python package / build (3.14) (pull_request) Canceled after 0s

This commit is contained in:
hermes
2026-09-29 21:37:20 +00:00
parent bcd99d0ec9
commit 895cd648e9
+5 -4
View File
@@ -13,6 +13,7 @@ from git.objects import Commit
logger = logging.getLogger(__name__)
AUTO_BRANCH_PREFIX = "auto-"
class GitClone(AbstractStep[str]):
@@ -125,7 +126,7 @@ class GitClone(AbstractStep[str]):
if not ref.is_remote() or ref.name.endswith('/HEAD'):
continue
remote_name, branch_name = ref.name.split('/', 1)
if branch_name.startswith('auto-') or branch_name.startswith('auto/'):
if branch_name.startswith(AUTO_BRANCH_PREFIX) or branch_name.startswith('auto/'):
continue
branch_key = branch_name if remote_name == 'origin' else ref.name
result[branch_key] = []
@@ -308,7 +309,7 @@ class CheckoutMerged(AbstractStep[CheckoutAndMergeResult]):
break
if self.push and remote_branch_name is None:
auto_branch_hash = hashlib.sha1(''.join([x.hexsha for x in sorted_commits]).encode()).hexdigest()
auto_branch_name = f"auto-{version}"
auto_branch_name = f"{AUTO_BRANCH_PREFIX}{version}"
logger.info(f"Pushing {repo.head.commit.hexsha} -> {auto_branch_name}")
repo.git.push('-f', 'origin', f"HEAD:refs/heads/{auto_branch_name}")
@@ -359,8 +360,8 @@ class GitUnmerge(AbstractStep[GitUnmergeResult]):
raise BaseException(f"Expected exactly one version, got: {versions}")
repo = git.Repo(wd)
childs: Dict[Commit, List[Commit]] | None = None
if 'auto-' in version:
version_parts = version[len('auto-'):].split('-')
if version.startswith(AUTO_BRANCH_PREFIX):
version_parts = version[len(AUTO_BRANCH_PREFIX):].split('-')
commits: List[Tuple[str, str]] = []
for v in version_parts: