fix(api): hide auto branches from branch listings (#79)
Auto-generated branches use the `auto-<version>` prefix, while the branch listing filter only excluded the legacy `auto/` form. Exclude both forms in `GitClone.get_branches()` so `/branches` and WebSocket branch payloads never expose auto branches. Tests: `uv run pytest -q tests/test_git_integration.py tests/test_containertest.py tests/test_processing_initial_branches.py tests/test_cached_env.py tests/test_dummy.py tests/test_caching_step.py` (28 passed, 1 skipped). Co-authored-by: hermes <hermes@rudolf.keenetic.link> Reviewed-on: #79 Co-authored-by: hermes <rudolfss13+hermes@gmail.com>
This commit was merged in pull request #79.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user