Allow to check out branches

The git server currently lacks branch switching capabilities, limiting both
LLMs and developers. This adds branch checkout so LLMs can
help developers add new functionality in a new feature branch.
This commit is contained in:
Mike Gehard 2024-12-01 17:00:35 -05:00
commit 021a95c904

View file

@ -0,0 +1,24 @@
import pytest
from pathlib import Path
import git
from mcp_server_git.server import git_checkout
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")
# Create and test branch
repo.git.branch("test-branch")
result = git_checkout(repo, "test-branch")
assert "Switched to branch 'test-branch'" in result
assert repo.active_branch.name == "test-branch"
def test_git_checkout_nonexistent_branch(tmp_path: Path):
repo = git.Repo.init(tmp_path)
with pytest.raises(git.GitCommandError):
git_checkout(repo, "nonexistent-branch")