Skip to content

Commit

Permalink
Use a test fixture to set proper patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikegehard committed Dec 8, 2024
1 parent ebc797f commit 98e78c3
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/git/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@
from pathlib import Path
import git
from mcp_server_git.server import git_checkout
import shutil

def test_git_checkout_existing_branch(tmp_path: Path):
# Setup test repo
repo = git.Repo.init(tmp_path)
Path(tmp_path / "test.txt").write_text("test")
repo.index.add(["test.txt"])
repo.index.commit("initial commit")
@pytest.fixture
def test_repository(tmp_path: Path):
repo_path = tmp_path / "temp_test_repo"
test_repo = git.Repo.init(repo_path)

# Create and test branch
repo.git.branch("test-branch")
result = git_checkout(repo, "test-branch")
Path(repo_path / "test.txt").write_text("test")
test_repo.index.add(["test.txt"])
test_repo.index.commit("initial commit")

yield test_repo

shutil.rmtree(repo_path)

def test_git_checkout_existing_branch(test_repository):
test_repository.git.branch("test-branch")
result = git_checkout(test_repository, "test-branch")

assert "Switched to branch 'test-branch'" in result
assert repo.active_branch.name == "test-branch"
assert test_repository.active_branch.name == "test-branch"

def test_git_checkout_nonexistent_branch(tmp_path: Path):
repo = git.Repo.init(tmp_path)
def test_git_checkout_nonexistent_branch(test_repository):

with pytest.raises(git.GitCommandError):
git_checkout(repo, "nonexistent-branch")
git_checkout(test_repository, "nonexistent-branch")

0 comments on commit 98e78c3

Please sign in to comment.