feat(git): extend source control with worktrees, stashes, conflicts and identities

- Create a worktree from a new or existing branch
- Integrate a worktree branch into a target branch by merge commit or cherry-pick, with continue/abort on conflicts
- Delete a worktree with keep, delete-local, or delete-local-and-remote branch options, using safe branch deletion for unmerged branches
- Add a stash tab (list, push, apply, pop, drop) shared across a repository and its worktrees
- Rename and delete branches, optionally deleting the remote branch and updating scheduled base branches
- Detect in-progress merge, rebase, cherry-pick and revert operations and hand conflicts to an agent session
- Generate commit messages from staged changes with the default model
- Add a default git identity and saved per-repository identities written to git config
- Unify git error mapping behind a typed error and one route helper; consolidate git mutations and cache invalidation
- Update repository docs
This commit is contained in:
Chris Scott committed 2026-10-03 21:59:00 -04:00
1 parent 52b6147ed3
commit 53238a6324
89 files changed
+7704 -793

No files matched your search

@@ -4,7 +4,6 @@ import os from 'os'
import { StringDecoder } from 'node:string_decoder'
import { promises as fs, accessSync, constants } from 'fs'
import { logger } from '../utils/logger'
import { createGitIdentityEnv, resolveGitIdentity } from '../utils/git-auth'
import {
buildSSHCommandWithKnownHosts,
buildSSHCommandWithConfig,
@@ -43,6 +42,7 @@ import { restoreQuarantinedOpenCodePlugins } from './opencode-plugin-quarantine'
import { resolveProcessIdentityProvider } from './opencode/process-identity'
import { SandboxRuntimeService } from './sandbox/runtime'
import { CredentialProvider } from './credential-provider'
import { syncManagerGitIdentityConfig } from './git-identity'
import { mkdirSafe, writeFileAtomic } from '../utils/fs-safe'
import { createProcessLogForwarder } from '../utils/log-buffer'
import { OPENCODE_SERVICE_SERVE_ARGS, prepareOpenCodeServiceLaunch } from './opencode-service-mode'
@@ -435,14 +435,12 @@ class OpenCodeServerManager {
const openCodeServerHost = getOpenCodeServerHost()
let credentialProvider: CredentialProvider | null = null
let gitIdentityEnv: Record<string, string> = {}
let userEnvVars: Record<string, string> = {}
if (this.db) {
try {
credentialProvider = new CredentialProvider(this.db)
const settingsService = new SettingsService(this.db)
const settings = settingsService.getSettings('default')
const gitCredentials = credentialProvider.getGitCredentials()
const rawEnvVars = settings.preferences.serverEnvVars || []
if (rawEnvVars.length > 0) {
userEnvVars = Object.fromEntries(
@@ -460,11 +458,7 @@ class OpenCodeServerManager {
logger.info(`Injecting ${Object.keys(userEnvVars).length} custom server env vars`)
}
const identity = await resolveGitIdentity(settings.preferences.gitIdentity, gitCredentials)
if (identity) {
gitIdentityEnv = createGitIdentityEnv(identity)
logger.info(`Git identity resolved: ${identity.name} <${identity.email}>`)
}
await syncManagerGitIdentityConfig(this.db)
} catch (error) {
logger.warn('Failed to get git settings:', error)
}
@@ -641,7 +635,6 @@ class OpenCodeServerManager {
...userEnvVars,
...microsandboxEnv,
...gitEnv,
...gitIdentityEnv,
...(this.db
? {
OCM_INTERNAL_API_URL: `http://localhost:${ENV.SERVER.PORT}/api/internal`,