MCPcopy Create free account
hub / github.com/bearlyai/OpenADE / handleCommitWorkTree

Function handleCommitWorkTree

projects/electron/src/modules/code/git.ts:1348–1397  ·  view source on GitHub ↗

* Commit changes in a worktree

(params: CommitWorkTreeParams)

Source from the content-addressed store, hash-verified

1346 * Commit changes in a worktree
1347 */
1348async function handleCommitWorkTree(params: CommitWorkTreeParams): Promise<CommitWorkTreeResponse> {
1349 const startTime = Date.now()
1350 logger.info("[Git:commitWorkTree] Committing changes", JSON.stringify({
1351 repoDir: params.repoDir,
1352 workTreeId: params.workTreeId,
1353 message: params.message.slice(0, 50),
1354 }))
1355
1356 try {
1357 validateRepoDir(params.repoDir)
1358 validateWorkTreeId(params.workTreeId)
1359
1360 const worktreePath = getWorktreePath(params.workTreeId)
1361
1362 // Validate worktree exists
1363 if (!fs.existsSync(worktreePath)) {
1364 throw new Error(`Worktree does not exist: ${worktreePath}`)
1365 }
1366
1367 // Stage all changes
1368 const addResult = await execGit(["add", "-A"], worktreePath)
1369 if (!addResult.success) {
1370 throw new Error(`Failed to stage changes: ${addResult.stderr}`)
1371 }
1372
1373 logger.info("[Git:commitWorkTree] Changes staged")
1374
1375 // Commit
1376 const commitResult = await execGit(["commit", "-m", params.message], worktreePath)
1377
1378 if (!commitResult.success) {
1379 // Check if it's "nothing to commit"
1380 if (commitResult.stdout.includes("nothing to commit") || commitResult.stderr.includes("nothing to commit")) {
1381 logger.info("[Git:commitWorkTree] Nothing to commit", JSON.stringify({ duration: Date.now() - startTime }))
1382 return { committed: false, error: "Nothing to commit" }
1383 }
1384 throw new Error(`Failed to commit: ${commitResult.stderr}`)
1385 }
1386
1387 // Extract SHA from output
1388 const shaMatch = commitResult.stdout.match(/\[[\w\/\-]+\s+([a-f0-9]+)\]/)
1389 const sha = shaMatch ? shaMatch[1] : undefined
1390
1391 logger.info("[Git:commitWorkTree] Commit successful", JSON.stringify({ sha, duration: Date.now() - startTime }))
1392 return { committed: true, sha }
1393 } catch (error: any) {
1394 logger.error("[Git:commitWorkTree] Error:", JSON.stringify({ error: error.message, stack: error.stack, duration: Date.now() - startTime }))
1395 return { committed: false, error: error.message }
1396 }
1397}
1398
1399/**
1400 * List branches in a repository

Callers 1

commitRuntimeWorkTreeFunction · 0.85

Calls 5

validateRepoDirFunction · 0.85
validateWorkTreeIdFunction · 0.85
getWorktreePathFunction · 0.85
execGitFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected