test state refresh after branch removal #6
@@ -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"""
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user