diff --git a/backend/steps/git.py b/backend/steps/git.py index 93ca504..6b3e2eb 100644 --- a/backend/steps/git.py +++ b/backend/steps/git.py @@ -13,6 +13,7 @@ from git.objects import Commit logger = logging.getLogger(__name__) +AUTO_BRANCH_PREFIX = "auto-" class GitClone(AbstractStep[str]): @@ -131,7 +132,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/'): # Skip auto branches + 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] = [] @@ -314,7 +315,7 @@ class CheckoutMerged(AbstractStep[CheckoutAndMergeResult]): break if self.push: 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}" push_remote = self.push if isinstance(self.push, str) else "origin" logger.info(f"Pushing {repo.head.commit.hexsha} -> {auto_branch_name}") @@ -366,8 +367,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: diff --git a/tests/test_git_integration.py b/tests/test_git_integration.py index 3a81c27..aa59181 100644 --- a/tests/test_git_integration.py +++ b/tests/test_git_integration.py @@ -32,6 +32,17 @@ class TestGitIntegration: assert repo.remotes.repo1.url == second_url assert set(clone.get_branches()) == {"master", "repo1/master"} + def test_git_clone_filters_auto_branches(self, repo_helper: RemoteRepoHelper) -> None: + repo_helper.create_commit(repo_helper.repo, "master", "master", "README.md", "content", "Initial commit") + repo_helper.create_commit(repo_helper.repo, "master", "feature", "feature.txt", "feature", "Feature commit") + repo_helper.create_commit(repo_helper.repo, "master", "auto-abc12345", "auto.txt", "auto", "Auto commit") + + clone = GitClone(url=repo_helper.remote_dir) + clone.env = repo_helper.env + clone.progress() + + assert set(clone.get_branches()) == {"master", "feature"} + def test_git_clone_named_remotes(self, repo_helper: RemoteRepoHelper) -> None: # Two real local repos served as separate "remotes". The user controls # their names explicitly via the `remotes=[{name,url}]` API.