(message?: string)
| 427 | * @returns Promise<boolean> - true if stash was successful, false otherwise |
| 428 | */ |
| 429 | export const stashToCleanState = async (message?: string): Promise<boolean> => { |
| 430 | try { |
| 431 | const stashMessage = |
| 432 | message || `Claude Code auto-stash - ${new Date().toISOString()}` |
| 433 | |
| 434 | // First, check if we have untracked files |
| 435 | const { untracked } = await getFileStatus() |
| 436 | |
| 437 | // If we have untracked files, add them to the index first |
| 438 | // This prevents them from being deleted |
| 439 | if (untracked.length > 0) { |
| 440 | const { code: addCode } = await execFileNoThrow( |
| 441 | gitExe(), |
| 442 | ['add', ...untracked], |
| 443 | { preserveOutputOnError: false }, |
| 444 | ) |
| 445 | |
| 446 | if (addCode !== 0) { |
| 447 | return false |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | // Now stash everything (staged and unstaged changes) |
| 452 | const { code } = await execFileNoThrow( |
| 453 | gitExe(), |
| 454 | ['stash', 'push', '--message', stashMessage], |
| 455 | { preserveOutputOnError: false }, |
| 456 | ) |
| 457 | return code === 0 |
| 458 | } catch (_) { |
| 459 | return false |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | export type GitRepoState = { |
| 464 | commitHash: string |
no test coverage detected