MCPcopy Index your code
hub / github.com/codeaashu/claude-code / stashToCleanState

Function stashToCleanState

src/utils/git.ts:429–461  ·  view source on GitHub ↗
(message?: string)

Source from the content-addressed store, hash-verified

427 * @returns Promise<boolean> - true if stash was successful, false otherwise
428 */
429export 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
463export type GitRepoState = {
464 commitHash: string

Callers 1

handleStashFunction · 0.85

Calls 2

getFileStatusFunction · 0.85
execFileNoThrowFunction · 0.85

Tested by

no test coverage detected