mirror of
https://github.com/stablyai/orca.git
synced 2026-09-28 00:02:41 +00:00
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
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()
|
|
}
|
|
}
|