import os import shutil import struct from unittest import mock import pytest from git import GitError, Repo from aider import urls from aider.main import sanity_check_repo @pytest.fixture def mock_io(): """Fixture to create a mock io object.""" return mock.Mock() @pytest.fixture def create_repo(tmp_path): """ Fixture to create a standard Git repository. Returns the path to the repo and the Repo object. """ repo_path = tmp_path / "test_repo" repo = Repo.init(repo_path) # Create an initial commit file_path = repo_path / "README.md" file_path.write_text("# Test Repository") repo.index.add([str(file_path.relative_to(repo_path))]) repo.index.commit("Initial commit") return repo_path, repo def set_git_index_version(repo_path, version): """ Sets the Git index version by modifying the .git/index file. The index version is stored in the first 4 bytes as a little-endian integer. """ index_path = os.path.join(repo_path, ".git", "index") with open(index_path, "r+b") as f: # Read the first 4 bytes (signature) and the next 4 bytes (version) signature = f.read(4) if signature != b"DIRC": raise ValueError("Invalid git index file signature.") # Write the new version f.seek(4) f.write(struct.pack("