refactor(git): split status.ts into source-control modules (#16393)

This commit is contained in:
Neil
2026-08-25 02:24:11 -07:00
committed by GitHub
parent 127fa7fae0
commit 33587fb77d
34 changed files with 2587 additions and 2363 deletions
@@ -0,0 +1,34 @@
import type { GitRuntimeOptions } from '../git-runtime-options'
import { gitOptionsForWorktree } from '../git-runtime-options'
import { gitExecFileAsync } from '../runner'
import { invalidateGitReadCaches } from './git-read-cache-invalidation'
export async function commitChanges(
worktreePath: string,
message: string,
options: GitRuntimeOptions = {}
): Promise<{ success: boolean; error?: string }> {
invalidateGitReadCaches()
try {
await gitExecFileAsync(['commit', '-m', message], gitOptionsForWorktree(worktreePath, options))
return { success: true }
} catch (error) {
// Why: useful message may be on stderr (hook/GPG failures) or stdout ("nothing to commit"), so try both then message.
const readStringField = (field: string): string | null => {
if (typeof error === 'object' && error && field in error) {
const v = (error as Record<string, unknown>)[field]
if (typeof v === 'string' && v.length > 0) {
return v
}
}
return null
}
const errorMessage =
readStringField('stderr') ??
readStringField('stdout') ??
(error instanceof Error ? error.message : 'Commit failed')
return { success: false, error: errorMessage }
} finally {
invalidateGitReadCaches()
}
}