From 0190fc747410ad30ed45f19416cd2885adb99604 Mon Sep 17 00:00:00 2001 From: rudolf Date: Tue, 25 Aug 2026 19:53:32 +0200 Subject: [PATCH] test state refresh after branch removal --- tests/test_cached_env.py | 19 +++++++++++++++++++ tests/test_remote_repo.py | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/tests/test_cached_env.py b/tests/test_cached_env.py index 0d4a90f..89d247f 100644 --- a/tests/test_cached_env.py +++ b/tests/test_cached_env.py @@ -1,5 +1,6 @@ import pytest from enironment import wrap_in_cached, SharedStateConflictError +from steps.shared_state import SharedStateHolderInMemory from tests.test_remote_repo import RemoteRepoHelper @@ -7,6 +8,24 @@ from tests.test_remote_repo import RemoteRepoHelper class TestCachedEnv: """Tests for the CachedEnv wrapper around GitEnv.""" + def test_inmemory_state_refreshes_removed_branch(self, repo_helper: RemoteRepoHelper) -> None: + repo_helper.create_commit(repo_helper.repo, "master", "master", "file1.txt", "content1", "Initial commit") + commit1 = repo_helper.create_commit(repo_helper.repo, "master", "branch1", "file2.txt", "content2", "Branch1 commit") + commit2 = repo_helper.create_commit(repo_helper.repo, "master", "branch2", "file3.txt", "content3", "Branch2 commit") + + repo_helper.set_desired_branches([("branch1", "HEAD"), ("branch2", "HEAD")]) + _ = repo_helper.checkout_merged.progress() + setattr(repo_helper.mock_check, "version", lambda: f"auto-{commit1.hexsha[:8]}-{commit2.hexsha[:8]}") + state = SharedStateHolderInMemory(repo_helper.git_unmerge) + + assert state.progress().branches == [("branch1", commit1.hexsha), ("branch2", commit2.hexsha)] + + repo_helper.delete_branch("branch2") + repo_helper.git_clone.progress() + + assert repo_helper.git_unmerge.progress().branches == [("branch1", commit1.hexsha)] + assert state.progress().branches == [("branch1", commit1.hexsha)] + def test_checkout_merged_empty_branches(self, repo_helper: RemoteRepoHelper) -> None: """Test CheckoutMerged with empty branches list - should fail""" diff --git a/tests/test_remote_repo.py b/tests/test_remote_repo.py index 009856a..917e576 100644 --- a/tests/test_remote_repo.py +++ b/tests/test_remote_repo.py @@ -144,6 +144,14 @@ class RemoteRepoHelper: repo.index.add([filename]) return repo.index.commit(message) + def delete_branch(self, branch_name: str) -> None: + if not self.repo.head.is_detached and self.repo.active_branch.name == branch_name: + remaining_heads = [head for head in self.repo.heads if head.name != branch_name] + if not remaining_heads: + raise ValueError(f"Cannot delete the only branch: {branch_name}") + remaining_heads[0].checkout() + self.repo.delete_head(branch_name, force=True) + def verify_working_directory_files(self, expected_files: List[Tuple[str, str]]) -> None: """Verify that working directory contains exactly the expected files with correct content. -- 2.54.0