|
15 | 15 | import git |
16 | 16 | from pydantic import BaseModel |
17 | 17 |
|
| 18 | +# Default number of context lines to show in diff output |
| 19 | +DEFAULT_CONTEXT_LINES = 3 |
| 20 | + |
18 | 21 | class GitStatus(BaseModel): |
19 | 22 | repo_path: str |
20 | 23 |
|
21 | 24 | class GitDiffUnstaged(BaseModel): |
22 | 25 | repo_path: str |
| 26 | + context_lines: int = DEFAULT_CONTEXT_LINES |
23 | 27 |
|
24 | 28 | class GitDiffStaged(BaseModel): |
25 | 29 | repo_path: str |
| 30 | + context_lines: int = DEFAULT_CONTEXT_LINES |
26 | 31 |
|
27 | 32 | class GitDiff(BaseModel): |
28 | 33 | repo_path: str |
29 | 34 | target: str |
| 35 | + context_lines: int = DEFAULT_CONTEXT_LINES |
30 | 36 |
|
31 | 37 | class GitCommit(BaseModel): |
32 | 38 | repo_path: str |
@@ -76,14 +82,14 @@ class GitTools(str, Enum): |
76 | 82 | def git_status(repo: git.Repo) -> str: |
77 | 83 | return repo.git.status() |
78 | 84 |
|
79 | | -def git_diff_unstaged(repo: git.Repo) -> str: |
80 | | - return repo.git.diff() |
| 85 | +def git_diff_unstaged(repo: git.Repo, context_lines: int = DEFAULT_CONTEXT_LINES) -> str: |
| 86 | + return repo.git.diff(f"--unified={context_lines}") |
81 | 87 |
|
82 | | -def git_diff_staged(repo: git.Repo) -> str: |
83 | | - return repo.git.diff("--cached") |
| 88 | +def git_diff_staged(repo: git.Repo, context_lines: int = DEFAULT_CONTEXT_LINES) -> str: |
| 89 | + return repo.git.diff(f"--unified={context_lines}", "--cached") |
84 | 90 |
|
85 | | -def git_diff(repo: git.Repo, target: str) -> str: |
86 | | - return repo.git.diff(target) |
| 91 | +def git_diff(repo: git.Repo, target: str, context_lines: int = DEFAULT_CONTEXT_LINES) -> str: |
| 92 | + return repo.git.diff(f"--unified={context_lines}", target) |
87 | 93 |
|
88 | 94 | def git_commit(repo: git.Repo, message: str) -> str: |
89 | 95 | commit = repo.index.commit(message) |
@@ -278,21 +284,21 @@ async def call_tool(name: str, arguments: dict) -> list[TextContent]: |
278 | 284 | )] |
279 | 285 |
|
280 | 286 | case GitTools.DIFF_UNSTAGED: |
281 | | - diff = git_diff_unstaged(repo) |
| 287 | + diff = git_diff_unstaged(repo, arguments.get("context_lines", DEFAULT_CONTEXT_LINES)) |
282 | 288 | return [TextContent( |
283 | 289 | type="text", |
284 | 290 | text=f"Unstaged changes:\n{diff}" |
285 | 291 | )] |
286 | 292 |
|
287 | 293 | case GitTools.DIFF_STAGED: |
288 | | - diff = git_diff_staged(repo) |
| 294 | + diff = git_diff_staged(repo, arguments.get("context_lines", DEFAULT_CONTEXT_LINES)) |
289 | 295 | return [TextContent( |
290 | 296 | type="text", |
291 | 297 | text=f"Staged changes:\n{diff}" |
292 | 298 | )] |
293 | 299 |
|
294 | 300 | case GitTools.DIFF: |
295 | | - diff = git_diff(repo, arguments["target"]) |
| 301 | + diff = git_diff(repo, arguments["target"], arguments.get("context_lines", DEFAULT_CONTEXT_LINES)) |
296 | 302 | return [TextContent( |
297 | 303 | type="text", |
298 | 304 | text=f"Diff with {arguments['target']}:\n{diff}" |
|
0 commit comments