MCPcopy Index your code
hub / github.com/Noumena-Network/code / stashToCleanState

Function stashToCleanState

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

Source from the content-addressed store, hash-verified

442 * @returns Promise<boolean> - true if stash was successful, false otherwise
443 */
444export 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
478export type GitRepoState = {
479 commitHash: string

Callers 1

handleStashFunction · 0.85

Calls 2

getFileStatusFunction · 0.85
execFileNoThrowFunction · 0.70

Tested by

no test coverage detected