@@ -52,6 +52,10 @@ class GitCheckout(BaseModel):
5252 repo_path : str
5353 branch_name : str
5454
55+ class GitShow (BaseModel ):
56+ repo_path : str
57+ revision : str
58+
5559class GitTools (str , Enum ):
5660 STATUS = "git_status"
5761 DIFF_UNSTAGED = "git_diff_unstaged"
@@ -63,6 +67,7 @@ class GitTools(str, Enum):
6367 LOG = "git_log"
6468 CREATE_BRANCH = "git_create_branch"
6569 CHECKOUT = "git_checkout"
70+ SHOW = "git_show"
6671
6772def git_status (repo : git .Repo ) -> str :
6873 return repo .git .status ()
@@ -113,6 +118,24 @@ def git_checkout(repo: git.Repo, branch_name: str) -> str:
113118 repo .git .checkout (branch_name )
114119 return f"Switched to branch '{ branch_name } '"
115120
121+ def git_show (repo : git .Repo , revision : str ) -> str :
122+ commit = repo .commit (revision )
123+ output = [
124+ f"Commit: { commit .hexsha } \n "
125+ f"Author: { commit .author } \n "
126+ f"Date: { commit .authored_datetime } \n "
127+ f"Message: { commit .message } \n "
128+ ]
129+ if commit .parents :
130+ parent = commit .parents [0 ]
131+ diff = parent .diff (commit , create_patch = True )
132+ else :
133+ diff = commit .diff (git .NULL_TREE , create_patch = True )
134+ for d in diff :
135+ output .append (f"\n --- { d .a_path } \n +++ { d .b_path } \n " )
136+ output .append (d .diff .decode ('utf-8' ))
137+ return "" .join (output )
138+
116139async def serve (repository : Path | None ) -> None :
117140 logger = logging .getLogger (__name__ )
118141
@@ -179,6 +202,11 @@ async def list_tools() -> list[Tool]:
179202 description = "Switches branches" ,
180203 inputSchema = GitCheckout .schema (),
181204 ),
205+ Tool (
206+ name = GitTools .SHOW ,
207+ description = "Shows the contents of a commit" ,
208+ inputSchema = GitShow .schema (),
209+ )
182210 ]
183211
184212 async def list_repos () -> Sequence [str ]:
@@ -290,6 +318,13 @@ async def call_tool(name: str, arguments: dict) -> list[TextContent]:
290318 text = result
291319 )]
292320
321+ case GitTools .SHOW :
322+ result = git_show (repo , arguments ["revision" ])
323+ return [TextContent (
324+ type = "text" ,
325+ text = result
326+ )]
327+
293328 case _:
294329 raise ValueError (f"Unknown tool: { name } " )
295330
0 commit comments