mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-19 00:23:24 +02:00
Merge pull request #166 from mikegehard/feature/git-checkout-command
Allow to check out branches
This commit is contained in:
@@ -48,6 +48,10 @@ class GitCreateBranch(BaseModel):
|
||||
branch_name: str
|
||||
base_branch: str | None = None
|
||||
|
||||
class GitCheckout(BaseModel):
|
||||
repo_path: str
|
||||
branch_name: str
|
||||
|
||||
class GitTools(str, Enum):
|
||||
STATUS = "git_status"
|
||||
DIFF_UNSTAGED = "git_diff_unstaged"
|
||||
@@ -58,6 +62,7 @@ class GitTools(str, Enum):
|
||||
RESET = "git_reset"
|
||||
LOG = "git_log"
|
||||
CREATE_BRANCH = "git_create_branch"
|
||||
CHECKOUT = "git_checkout"
|
||||
|
||||
def git_status(repo: git.Repo) -> str:
|
||||
return repo.git.status()
|
||||
@@ -104,6 +109,10 @@ def git_create_branch(repo: git.Repo, branch_name: str, base_branch: str | None
|
||||
repo.create_head(branch_name, base)
|
||||
return f"Created branch '{branch_name}' from '{base.name}'"
|
||||
|
||||
def git_checkout(repo: git.Repo, branch_name: str) -> str:
|
||||
repo.git.checkout(branch_name)
|
||||
return f"Switched to branch '{branch_name}'"
|
||||
|
||||
async def serve(repository: Path | None) -> None:
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -165,6 +174,11 @@ async def serve(repository: Path | None) -> None:
|
||||
description="Creates a new branch from an optional base branch",
|
||||
inputSchema=GitCreateBranch.schema(),
|
||||
),
|
||||
Tool(
|
||||
name=GitTools.CHECKOUT,
|
||||
description="Switches branches",
|
||||
inputSchema=GitCheckout.schema(),
|
||||
),
|
||||
]
|
||||
|
||||
async def list_repos() -> Sequence[str]:
|
||||
@@ -269,6 +283,13 @@ async def serve(repository: Path | None) -> None:
|
||||
text=result
|
||||
)]
|
||||
|
||||
case GitTools.CHECKOUT:
|
||||
result = git_checkout(repo, arguments["branch_name"])
|
||||
return [TextContent(
|
||||
type="text",
|
||||
text=result
|
||||
)]
|
||||
|
||||
case _:
|
||||
raise ValueError(f"Unknown tool: {name}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user