* Retrieves git changes for the project using the provided spawn function
(params: {
cwd: string
spawn: CodebuffSpawn
logger: Logger
})
| 263 | * Retrieves git changes for the project using the provided spawn function |
| 264 | */ |
| 265 | async function getGitChanges(params: { |
| 266 | cwd: string |
| 267 | spawn: CodebuffSpawn |
| 268 | logger: Logger |
| 269 | }): Promise<{ |
| 270 | status: string |
| 271 | diff: string |
| 272 | diffCached: string |
| 273 | lastCommitMessages: string |
| 274 | }> { |
| 275 | const { cwd, spawn, logger } = params |
| 276 | |
| 277 | const status = childProcessToPromise(spawn('git', ['status'], { cwd })) |
| 278 | .then(({ stdout }) => stdout) |
| 279 | .catch((error) => { |
| 280 | logger.debug?.({ error }, 'Failed to get git status') |
| 281 | return '' |
| 282 | }) |
| 283 | |
| 284 | const diff = childProcessToPromise(spawn('git', ['diff'], { cwd })) |
| 285 | .then(({ stdout }) => stdout) |
| 286 | .catch((error) => { |
| 287 | logger.debug?.({ error }, 'Failed to get git diff') |
| 288 | return '' |
| 289 | }) |
| 290 | |
| 291 | const diffCached = childProcessToPromise( |
| 292 | spawn('git', ['diff', '--cached'], { cwd }), |
| 293 | ) |
| 294 | .then(({ stdout }) => stdout) |
| 295 | .catch((error) => { |
| 296 | logger.debug?.({ error }, 'Failed to get git diff --cached') |
| 297 | return '' |
| 298 | }) |
| 299 | |
| 300 | const lastCommitMessages = childProcessToPromise( |
| 301 | spawn('git', ['shortlog', 'HEAD~10..HEAD'], { cwd }), |
| 302 | ) |
| 303 | .then(({ stdout }) => |
| 304 | stdout |
| 305 | .trim() |
| 306 | .split('\n') |
| 307 | .slice(1) |
| 308 | .reverse() |
| 309 | .map((line) => line.trim()) |
| 310 | .join('\n'), |
| 311 | ) |
| 312 | .catch((error) => { |
| 313 | logger.debug?.({ error }, 'Failed to get lastCommitMessages') |
| 314 | return '' |
| 315 | }) |
| 316 | |
| 317 | return { |
| 318 | status: await status, |
| 319 | diff: await diff, |
| 320 | diffCached: await diffCached, |
| 321 | lastCommitMessages: await lastCommitMessages, |
| 322 | } |
no test coverage detected