(cwd: string)
| 318 | } |
| 319 | |
| 320 | export async function getWorkingState(cwd: string): Promise<string> { |
| 321 | try { |
| 322 | const isInstalled = await checkGitInstalled() |
| 323 | if (!isInstalled) { |
| 324 | return "Git is not installed" |
| 325 | } |
| 326 | |
| 327 | const isRepo = await checkGitRepo(cwd) |
| 328 | if (!isRepo) { |
| 329 | return "Not a git repository" |
| 330 | } |
| 331 | |
| 332 | // Get status of working directory |
| 333 | const { stdout: status } = await execAsync("git status --short", { cwd }) |
| 334 | if (!status.trim()) { |
| 335 | return "No changes in working directory" |
| 336 | } |
| 337 | |
| 338 | // Get all changes (both staged and unstaged) compared to HEAD |
| 339 | const { stdout: diff } = await execAsync("git diff HEAD", { cwd }) |
| 340 | const lineLimit = GIT_OUTPUT_LINE_LIMIT |
| 341 | const output = `Working directory changes:\n\n${status}\n\n${diff}`.trim() |
| 342 | return truncateOutput(output, lineLimit) |
| 343 | } catch (error) { |
| 344 | console.error("Error getting working state:", error) |
| 345 | return `Failed to get working state: ${error instanceof Error ? error.message : String(error)}` |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Gets git status output with configurable file limit |
no test coverage detected