(hash: string, cwd: string)
| 277 | } |
| 278 | |
| 279 | export async function getCommitInfo(hash: string, cwd: string): Promise<string> { |
| 280 | try { |
| 281 | const isInstalled = await checkGitInstalled() |
| 282 | if (!isInstalled) { |
| 283 | return "Git is not installed" |
| 284 | } |
| 285 | |
| 286 | const isRepo = await checkGitRepo(cwd) |
| 287 | if (!isRepo) { |
| 288 | return "Not a git repository" |
| 289 | } |
| 290 | |
| 291 | // Get commit info, stats, and diff separately |
| 292 | const { stdout: info } = await execAsync(`git show --format="%H%n%h%n%s%n%an%n%ad%n%b" --no-patch ${hash}`, { |
| 293 | cwd, |
| 294 | }) |
| 295 | const [fullHash, shortHash, subject, author, date, body] = info.trim().split("\n") |
| 296 | |
| 297 | const { stdout: stats } = await execAsync(`git show --stat --format="" ${hash}`, { cwd }) |
| 298 | |
| 299 | const { stdout: diff } = await execAsync(`git show --format="" ${hash}`, { cwd }) |
| 300 | |
| 301 | const summary = [ |
| 302 | `Commit: ${shortHash} (${fullHash})`, |
| 303 | `Author: ${author}`, |
| 304 | `Date: ${date}`, |
| 305 | `\nMessage: ${subject}`, |
| 306 | body ? `\nDescription:\n${body}` : "", |
| 307 | "\nFiles Changed:", |
| 308 | stats.trim(), |
| 309 | "\nFull Changes:", |
| 310 | ].join("\n") |
| 311 | |
| 312 | const output = summary + "\n\n" + diff.trim() |
| 313 | return truncateOutput(output, GIT_OUTPUT_LINE_LIMIT) |
| 314 | } catch (error) { |
| 315 | console.error("Error getting commit info:", error) |
| 316 | return `Failed to get commit info: ${error instanceof Error ? error.message : String(error)}` |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | export async function getWorkingState(cwd: string): Promise<string> { |
| 321 | try { |
no test coverage detected