fix(ocm): make /ocm-move worktree moves safe and round-trippable

- Answer the old /mirror/target routes with a 410 upgrade message and
  serve the lookup at GET /mirror/checkouts; detect older Managers via
  the token probe (MANAGER_FEATURE_MISSING).
- Create the move worktree and import the bundle in one call; worktree
  setup runs after the import and the worktree is removed on failure.
- Never rewind a server branch: suffix the new worktree branch when the
  server branch has commits the local branch lacks, and skip both the
  source and target branch when updating refs.
- Reuse clean <branch>-ocm[-N] worktrees and legacy worktree repo rows
  instead of creating new ones on every move.
- Let ocm push/pull target the worktree on the local branch via a
  directory parameter on the mirror read routes; no tarball fallback
  for worktrees.
- Share one sibling loader (listRepoSiblings), validate branch names,
  compare canonical paths in isDirectoryInUse, and cut redundant git
  work in the checkouts lookup and the CLI destination choice.
This commit is contained in:
Chris Scott committed 2026-10-08 23:23:00 -04:00
1 parent bd7c3e3fef
commit 67f70e9635
21 files changed
+1777 -517

No files matched your search

+13 -6
View File
@@ -1,5 +1,6 @@
import { z } from 'zod'
import { getRepoDirectoryNameError } from '../utils/repo'
import { WorktreeSetupResultSchema } from './project-config'
export const RepoStatusSchema = z.enum(['cloning', 'ready', 'error'])
@@ -156,17 +157,23 @@ export const MirrorCheckoutStateSchema = z.object({
export type MirrorCheckoutState = z.infer<typeof MirrorCheckoutStateSchema>
export const MirrorMoveTargetResponseSchema = z.object({
export const MirrorCheckoutsResponseSchema = z.object({
main: MirrorCheckoutStateSchema,
branchWorktree: MirrorCheckoutStateSchema.nullable(),
newWorktreeBranch: z.string().min(1),
worktrees: z.array(MirrorCheckoutStateSchema),
branchHead: z.string().min(1).nullable(),
branchCheckedOut: z.boolean(),
suffixedWorktreeBranch: z.string().min(1),
})
export type MirrorMoveTargetResponse = z.infer<typeof MirrorMoveTargetResponseSchema>
export type MirrorCheckoutsResponse = z.infer<typeof MirrorCheckoutsResponseSchema>
export const MirrorWorktreeCreateResponseSchema = z.object({
directory: z.string().min(1),
branch: z.string().min(1),
repoId: z.number(),
fullPath: z.string().min(1),
branch: z.string().min(1).nullable(),
head: z.string().min(1).nullable(),
created: z.literal(true),
worktreeSetup: WorktreeSetupResultSchema,
})
export type MirrorWorktreeCreateResponse = z.infer<typeof MirrorWorktreeCreateResponseSchema>