mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-18 08:03:26 +02:00
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.
24 lines
743 B
Python
24 lines
743 B
Python
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") |