Skip to content

Commit 3140f48

Browse files
authored
test: add cleanup for autobranches created in tests (#3506)
1 parent 2542934 commit 3140f48

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

renku/infrastructure/repository.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,8 +1625,14 @@ def add(self, name: str) -> Branch:
16251625
else:
16261626
return Branch.from_head(repository=self._repository, head=head)
16271627

1628-
def remove(self, branch: Union[Branch, str], force: bool = False):
1628+
def remove(self, branch: Union[Branch, str], force: bool = False, remote: bool = False):
16291629
"""Remove an existing branch."""
1630+
if isinstance(branch, str):
1631+
branch = self[branch]
1632+
1633+
if remote and branch.remote_branch is not None:
1634+
_run_git_command(self._repository, branch.remote_branch.remote.name, branch, delete=True)
1635+
16301636
_run_git_command(self._repository, "branch", branch, delete=True, force=force)
16311637

16321638

tests/core/fixtures/core_models.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,27 @@ def git_repository_with_multiple_remotes(git_repository_with_remote):
9393
@pytest.fixture
9494
def protected_git_repository(tmp_path):
9595
"""A Git repository with remote."""
96+
from renku.core import errors
97+
9698
parsed_url = urllib.parse.urlparse(IT_PROTECTED_REMOTE_REPO_URL)
9799

98100
url = f"oauth2:{os.getenv('IT_OAUTH_GIT_TOKEN')}@{parsed_url.netloc}"
99101
parsed_url = parsed_url._replace(netloc=url).geturl()
100102

101103
repository = Repository.clone_from(url=parsed_url, path=tmp_path)
102104

105+
branches_before = set(repository.branches)
106+
103107
with repository.get_configuration(writable=True) as config:
104108
config.set_value("pull", "rebase", "false")
105109

106110
yield repository
111+
112+
branches_after = set(repository.branches)
113+
114+
for branch in branches_after - branches_before:
115+
# delete created branches
116+
try:
117+
repository.branches.remove(branch, force=True, remote=True)
118+
except errors.GitCommandError:
119+
continue

0 commit comments

Comments
 (0)