mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
- 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
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { execFileSync } from 'node:child_process'
|
|
import { mkdirSync } from 'node:fs'
|
|
import type { GitAuthService } from '../../src/services/git-auth'
|
|
|
|
export function git(args: string[], cwd?: string): string {
|
|
return execFileSync('git', args, {
|
|
cwd,
|
|
encoding: 'utf-8',
|
|
env: { ...process.env, GIT_TERMINAL_PROMPT: '0', GIT_CONFIG_NOSYSTEM: '1' },
|
|
}).trim()
|
|
}
|
|
|
|
export function createCommittedRepo(repoPath: string, branch = 'main'): void {
|
|
mkdirSync(repoPath, { recursive: true })
|
|
git(['init', '-b', branch], repoPath)
|
|
git(['config', 'user.email', 'test@test.com'], repoPath)
|
|
git(['config', 'user.name', 'Test'], repoPath)
|
|
git(['commit', '--allow-empty', '-m', 'init'], repoPath)
|
|
}
|
|
|
|
export function createOrigin(originPath: string, workPath: string, extraBranches: string[] = []): void {
|
|
mkdirSync(originPath, { recursive: true })
|
|
git(['init', '--bare', originPath])
|
|
mkdirSync(workPath, { recursive: true })
|
|
git(['init', '-b', 'main'], workPath)
|
|
git(['config', 'user.email', 'test@test.com'], workPath)
|
|
git(['config', 'user.name', 'Test'], workPath)
|
|
git(['commit', '--allow-empty', '-m', 'init'], workPath)
|
|
git(['remote', 'add', 'origin', originPath], workPath)
|
|
git(['push', 'origin', 'main'], workPath)
|
|
git(['symbolic-ref', 'HEAD', 'refs/heads/main'], originPath)
|
|
|
|
for (const branch of extraBranches) {
|
|
git(['checkout', '-b', branch], workPath)
|
|
git(['commit', '--allow-empty', '-m', branch], workPath)
|
|
git(['push', 'origin', branch], workPath)
|
|
git(['checkout', 'main'], workPath)
|
|
}
|
|
}
|
|
|
|
export function cloneOrigin(originPath: string, clonePath: string): void {
|
|
git(['clone', originPath, clonePath])
|
|
git(['config', 'user.email', 'test@test.com'], clonePath)
|
|
git(['config', 'user.name', 'Test'], clonePath)
|
|
}
|
|
|
|
let seq = 0
|
|
|
|
export function uniqueName(prefix: string): string {
|
|
seq += 1
|
|
return `${prefix}-${seq}`
|
|
}
|
|
|
|
export function createGitAuthService(env: Record<string, string> = {}): GitAuthService {
|
|
return {
|
|
getGitEnvironment: () => env,
|
|
getSSHEnvironment: () => ({}),
|
|
setupSSHForRepoUrl: async () => false,
|
|
cleanupSSHKey: async () => {},
|
|
} as unknown as GitAuthService
|
|
}
|