(message?: string)
| 442 | * @returns Promise<boolean> - true if stash was successful, false otherwise |
| 443 | */ |
| 444 | export const stashToCleanState = async (message?: string): Promise<boolean> => { |
| 445 | try { |
| 446 | const stashMessage = |
| 447 | message || `NCode auto-stash - ${new Date().toISOString()}` |
| 448 | |
| 449 | // First, check if we have untracked files |
| 450 | const { untracked } = await getFileStatus() |
| 451 | |
| 452 | // If we have untracked files, add them to the index first |
| 453 | // This prevents them from being deleted |
| 454 | if (untracked.length > 0) { |
| 455 | const { code: addCode } = await execFileNoThrow( |
| 456 | gitExe(), |
| 457 | ['add', ...untracked], |
| 458 | { preserveOutputOnError: false }, |
| 459 | ) |
| 460 | |
| 461 | if (addCode !== 0) { |
| 462 | return false |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | // Now stash everything (staged and unstaged changes) |
| 467 | const { code } = await execFileNoThrow( |
| 468 | gitExe(), |
| 469 | ['stash', 'push', '--message', stashMessage], |
| 470 | { preserveOutputOnError: false }, |
| 471 | ) |
| 472 | return code === 0 |
| 473 | } catch (_) { |
| 474 | return false |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | export type GitRepoState = { |
| 479 | commitHash: string |
no test coverage detected