mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
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:
1 parent
52b6147ed3
commit
53238a6324
89 files changed
+7704
-793
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import { z } from 'zod'
|
||||
import { getBranchNameError } from '../utils/repo'
|
||||
|
||||
const branchNameSchema = z.string().trim().superRefine((value, ctx) => {
|
||||
const error = getBranchNameError(value)
|
||||
if (error) {
|
||||
ctx.addIssue({ code: 'custom', message: error })
|
||||
}
|
||||
})
|
||||
|
||||
export const RenameBranchRequestSchema = z.object({
|
||||
from: branchNameSchema,
|
||||
to: branchNameSchema,
|
||||
})
|
||||
|
||||
export const DeleteBranchRequestSchema = z.object({
|
||||
name: branchNameSchema,
|
||||
force: z.boolean().default(false),
|
||||
deleteRemote: z.boolean().default(false),
|
||||
})
|
||||
|
||||
export const DeleteBranchResultSchema = z.object({
|
||||
remoteDeleted: z.boolean(),
|
||||
})
|
||||
|
||||
export const GitStashEntrySchema = z.object({
|
||||
index: z.number().int().nonnegative(),
|
||||
ref: z.string(),
|
||||
hash: z.string(),
|
||||
message: z.string(),
|
||||
branch: z.string().nullable(),
|
||||
date: z.string(),
|
||||
})
|
||||
|
||||
export const StashPushRequestSchema = z.object({
|
||||
message: z.string().trim().max(500).optional(),
|
||||
includeUntracked: z.boolean().default(true),
|
||||
})
|
||||
|
||||
export const StashApplyRequestSchema = z.object({
|
||||
hash: z.string().trim().min(1),
|
||||
pop: z.boolean().default(false),
|
||||
})
|
||||
|
||||
export const StashDropRequestSchema = z.object({
|
||||
hash: z.string().trim().min(1),
|
||||
})
|
||||
|
||||
export const GitOperationKindSchema = z.enum(['merge', 'rebase', 'cherry-pick', 'revert'])
|
||||
|
||||
export const GitOperationStateSchema = z.object({
|
||||
kind: GitOperationKindSchema,
|
||||
conflictedFiles: z.array(z.string()),
|
||||
})
|
||||
|
||||
export const IntegrateBranchRequestSchema = z.object({
|
||||
targetBranch: branchNameSchema,
|
||||
strategy: z.enum(['merge', 'cherry-pick']).default('merge'),
|
||||
})
|
||||
|
||||
export const IntegrateBranchResultSchema = z.object({
|
||||
targetRepoId: z.number().int(),
|
||||
integratedCommits: z.number().int(),
|
||||
})
|
||||
|
||||
export const GitIdentityScopeSchema = z.enum(['repository', 'default', 'global', 'none'])
|
||||
|
||||
export const RepoGitIdentitySchema = z.object({
|
||||
name: z.string().nullable(),
|
||||
email: z.string().nullable(),
|
||||
scope: GitIdentityScopeSchema,
|
||||
presetId: z.string().nullable(),
|
||||
})
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from './settings'
|
||||
export * from './repo'
|
||||
export * from './git'
|
||||
export * from './files'
|
||||
export * from './filesystem'
|
||||
export * from './opencode'
|
||||
|
||||
@@ -48,6 +48,20 @@ export const UpdateRepoRequestSchema = z.object({
|
||||
name: z.string().trim().max(100).nullable(),
|
||||
})
|
||||
|
||||
export const DeleteRepoRequestSchema = z.object({
|
||||
deleteBranch: z.enum(['none', 'local', 'local-and-remote']).default('none'),
|
||||
})
|
||||
|
||||
export const DeleteRepoResultSchema = z.object({
|
||||
success: z.literal(true),
|
||||
branch: z.object({
|
||||
name: z.string(),
|
||||
deleted: z.boolean(),
|
||||
remoteDeleted: z.boolean(),
|
||||
error: z.string().optional(),
|
||||
}).optional(),
|
||||
})
|
||||
|
||||
export const DiscoverReposResponseSchema = z.object({
|
||||
repos: z.array(RepoSchema),
|
||||
discoveredCount: z.number().int().nonnegative(),
|
||||
|
||||
@@ -106,6 +106,12 @@ export const GitIdentitySchema = z.object({
|
||||
|
||||
export type GitIdentity = z.infer<typeof GitIdentitySchema>;
|
||||
|
||||
export const GitIdentityProfileSchema = GitIdentitySchema.extend({
|
||||
id: z.string().min(1),
|
||||
});
|
||||
|
||||
export type GitIdentityProfile = z.infer<typeof GitIdentityProfileSchema>;
|
||||
|
||||
export const ServerEnvVarSchema = z.object({
|
||||
key: z.string().min(1),
|
||||
value: z.string(),
|
||||
@@ -160,6 +166,7 @@ export const UserPreferencesSchema = z.object({
|
||||
gitCredentials: z.array(GitCredentialSchema).optional(),
|
||||
defaultGitCredentialId: z.string().optional(),
|
||||
gitIdentity: GitIdentitySchema.optional(),
|
||||
gitIdentities: z.array(GitIdentityProfileSchema).optional(),
|
||||
tts: TTSConfigSchema.optional(),
|
||||
stt: STTConfigSchema.optional(),
|
||||
notifications: NotificationPreferencesSchema.optional(),
|
||||
|
||||
@@ -11,7 +11,17 @@ export type GitErrorCode =
|
||||
| 'DETACHED_HEAD'
|
||||
| 'BRANCH_EXISTS'
|
||||
| 'BRANCH_NOT_FOUND'
|
||||
| 'BRANCH_CHECKED_OUT'
|
||||
| 'BRANCH_IN_OTHER_WORKTREE'
|
||||
| 'BRANCH_NOT_MERGED'
|
||||
| 'STASH_CHANGED'
|
||||
| 'UNCOMMITTED_CHANGES'
|
||||
| 'NO_OPERATION_IN_PROGRESS'
|
||||
| 'INTEGRATE_DETACHED_HEAD'
|
||||
| 'INTEGRATE_INTO_SELF'
|
||||
| 'INTEGRATE_TARGET_NOT_CHECKED_OUT'
|
||||
| 'INTEGRATE_TARGET_NOT_MANAGED'
|
||||
| 'INTEGRATE_NOTHING_TO_INTEGRATE'
|
||||
| 'UNKNOWN'
|
||||
|
||||
export type ApiErrorCode = GitErrorCode | 'INVALID_JSON' | 'TIMEOUT'
|
||||
|
||||
@@ -18,10 +18,26 @@ import {
|
||||
DiscoverReposRequestSchema,
|
||||
DiscoverReposResponseSchema,
|
||||
UpdateRepoRequestSchema,
|
||||
DeleteRepoRequestSchema,
|
||||
DeleteRepoResultSchema,
|
||||
RepoStatusSchema,
|
||||
AssistantModeStatusSchema,
|
||||
AssistantModeInitRequestSchema,
|
||||
} from '../schemas/repo'
|
||||
import {
|
||||
RenameBranchRequestSchema,
|
||||
DeleteBranchRequestSchema,
|
||||
DeleteBranchResultSchema,
|
||||
GitStashEntrySchema,
|
||||
StashPushRequestSchema,
|
||||
StashApplyRequestSchema,
|
||||
StashDropRequestSchema,
|
||||
GitOperationKindSchema,
|
||||
GitOperationStateSchema,
|
||||
IntegrateBranchRequestSchema,
|
||||
IntegrateBranchResultSchema,
|
||||
RepoGitIdentitySchema,
|
||||
} from '../schemas/git'
|
||||
import {
|
||||
FileInfoSchema,
|
||||
CreateFileRequestSchema,
|
||||
@@ -73,9 +89,24 @@ export type DiscoverReposRequest = z.infer<typeof DiscoverReposRequestSchema>
|
||||
export type DiscoverReposResponse = z.infer<typeof DiscoverReposResponseSchema>
|
||||
export type RepoStatus = z.infer<typeof RepoStatusSchema>
|
||||
export type UpdateRepoRequest = z.infer<typeof UpdateRepoRequestSchema>
|
||||
export type DeleteRepoRequest = z.infer<typeof DeleteRepoRequestSchema>
|
||||
export type DeleteRepoResult = z.infer<typeof DeleteRepoResultSchema>
|
||||
export type AssistantModeStatus = z.infer<typeof AssistantModeStatusSchema>
|
||||
export type AssistantModeInitRequest = z.infer<typeof AssistantModeInitRequestSchema>
|
||||
|
||||
export type RenameBranchRequest = z.infer<typeof RenameBranchRequestSchema>
|
||||
export type DeleteBranchRequest = z.infer<typeof DeleteBranchRequestSchema>
|
||||
export type DeleteBranchResult = z.infer<typeof DeleteBranchResultSchema>
|
||||
export type GitStashEntry = z.infer<typeof GitStashEntrySchema>
|
||||
export type StashPushRequest = z.infer<typeof StashPushRequestSchema>
|
||||
export type StashApplyRequest = z.infer<typeof StashApplyRequestSchema>
|
||||
export type StashDropRequest = z.infer<typeof StashDropRequestSchema>
|
||||
export type GitOperationKind = z.infer<typeof GitOperationKindSchema>
|
||||
export type GitOperationState = z.infer<typeof GitOperationStateSchema>
|
||||
export type IntegrateBranchRequest = z.infer<typeof IntegrateBranchRequestSchema>
|
||||
export type IntegrateBranchResult = z.infer<typeof IntegrateBranchResultSchema>
|
||||
export type RepoGitIdentity = z.infer<typeof RepoGitIdentitySchema>
|
||||
|
||||
export type FileInfo = z.infer<typeof FileInfoSchema>
|
||||
export type CreateFileRequest = z.infer<typeof CreateFileRequestSchema>
|
||||
export type RenameFileRequest = z.infer<typeof RenameFileRequestSchema>
|
||||
@@ -111,7 +142,7 @@ export interface SuccessResponse {
|
||||
}
|
||||
|
||||
export type { SSHHostKeyRequest, SSHHostKeyResponse, TrustedSSHHost } from '../schemas/ssh'
|
||||
export type { GitCredential } from '../schemas/settings'
|
||||
export type { GitCredential, GitIdentityProfile } from '../schemas/settings'
|
||||
export type {
|
||||
ProviderApiConfig,
|
||||
ModelConfig,
|
||||
|
||||
@@ -56,6 +56,20 @@ export function sanitizeBranchForDirectory(branch: string): string {
|
||||
return branch.replace(/[\\/]/g, '-')
|
||||
}
|
||||
|
||||
export function getBranchNameError(name: string): string | null {
|
||||
const trimmed = name.trim()
|
||||
|
||||
if (!trimmed) {
|
||||
return 'Branch name is required'
|
||||
}
|
||||
|
||||
if (trimmed.startsWith('-')) {
|
||||
return 'Branch name must not start with "-"'
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function isWorktreeSibling(sibling: { worktreeStrategy?: string }): boolean {
|
||||
return sibling.worktreeStrategy !== undefined
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user