fix(git): cache unsupported capabilities per host (#8109)
* fix(git): cache unsupported capabilities per host Old Git worktree, ref-search, and merge-tree fallbacks retried unsupported flags on recurring operations, flooding subprocess traces. Centralize capability probing per native, WSL, and SSH execution host, coalesce concurrent probes, and retry periodically for in-place Git upgrades. * fix(git): recognize real old-Git merge-tree rejection * test(git): enforce real binary compatibility matrix * fix(ci): preserve Git compatibility test ownership * fix(git): retain supported capability state
This commit is contained in:
@@ -3,15 +3,8 @@ import type { RemoveWorktreeResult } from '../shared/types'
|
||||
import { assertWorktreeUnlockedForRemoval } from '../shared/worktree-removal'
|
||||
import { deleteAlreadyMergedRelayBranchAfterSafeDeleteFailure } from './git-handler-branch-cleanup'
|
||||
import type { GitExec } from './git-handler-ops'
|
||||
import { isUnsupportedWorktreeListZError, parseWorktreeList } from './git-handler-utils'
|
||||
|
||||
type RelayWorktreeInfo = {
|
||||
path: string
|
||||
branch?: string
|
||||
head?: string
|
||||
locked?: boolean
|
||||
lockReason?: string
|
||||
}
|
||||
import type { GitCapabilityCache } from '../shared/git-capability-cache'
|
||||
import { readRelayWorktreeList } from './git-handler-worktree-list'
|
||||
|
||||
function getErrorText(error: unknown): string {
|
||||
if (typeof error === 'object' && error !== null) {
|
||||
@@ -77,36 +70,13 @@ function areRelayWorktreePathsEqual(leftPath: string, rightPath: string): boolea
|
||||
return compareCaseInsensitive ? left.toLowerCase() === right.toLowerCase() : left === right
|
||||
}
|
||||
|
||||
function normalizeRelayWorktrees(worktrees: Record<string, unknown>[]): RelayWorktreeInfo[] {
|
||||
return worktrees
|
||||
.map((worktree) => ({
|
||||
path: typeof worktree.path === 'string' ? worktree.path : '',
|
||||
head: typeof worktree.head === 'string' ? worktree.head : undefined,
|
||||
branch: typeof worktree.branch === 'string' ? worktree.branch : undefined,
|
||||
locked: worktree.locked === true ? true : undefined,
|
||||
lockReason: typeof worktree.lockReason === 'string' ? worktree.lockReason : undefined
|
||||
}))
|
||||
.filter((worktree) => worktree.path.length > 0)
|
||||
}
|
||||
|
||||
async function readRelayWorktreeList(git: GitExec, repoPath: string): Promise<RelayWorktreeInfo[]> {
|
||||
async function listRelayWorktreesForRemoval(
|
||||
git: GitExec,
|
||||
repoPath: string,
|
||||
capabilities: GitCapabilityCache
|
||||
) {
|
||||
try {
|
||||
const { stdout } = await git(['worktree', 'list', '--porcelain', '-z'], repoPath)
|
||||
return normalizeRelayWorktrees(parseWorktreeList(stdout, { nulDelimited: true }))
|
||||
} catch (error) {
|
||||
if (!isUnsupportedWorktreeListZError(error)) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// Why: `-z` preserves newlines; fallback keeps Git <2.36 compatible.
|
||||
const { stdout } = await git(['worktree', 'list', '--porcelain'], repoPath)
|
||||
return normalizeRelayWorktrees(parseWorktreeList(stdout))
|
||||
}
|
||||
|
||||
async function listRelayWorktreesForRemoval(git: GitExec, repoPath: string) {
|
||||
try {
|
||||
return await readRelayWorktreeList(git, repoPath)
|
||||
return await readRelayWorktreeList(git, repoPath, capabilities)
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
@@ -153,7 +123,8 @@ async function deleteRelayBranchAfterWorktreeRemoval(
|
||||
|
||||
export async function removeWorktreeOp(
|
||||
git: GitExec,
|
||||
params: Record<string, unknown>
|
||||
params: Record<string, unknown>,
|
||||
capabilities: GitCapabilityCache
|
||||
): Promise<RemoveWorktreeResult> {
|
||||
const worktreePath = params.worktreePath as string
|
||||
const force = params.force as boolean | undefined
|
||||
@@ -171,7 +142,7 @@ export async function removeWorktreeOp(
|
||||
// fall through with worktreePath as repo
|
||||
}
|
||||
|
||||
const worktreesBeforeRemoval = await listRelayWorktreesForRemoval(git, repoPath)
|
||||
const worktreesBeforeRemoval = await listRelayWorktreesForRemoval(git, repoPath, capabilities)
|
||||
const removedWorktree = worktreesBeforeRemoval.find((worktree) =>
|
||||
areRelayWorktreePathsEqual(worktree.path, worktreePath)
|
||||
)
|
||||
@@ -217,7 +188,8 @@ export async function removeWorktreeOp(
|
||||
git,
|
||||
repoPath,
|
||||
branchName,
|
||||
branchHead
|
||||
branchHead,
|
||||
capabilities
|
||||
)
|
||||
) {
|
||||
return {}
|
||||
|
||||
Reference in New Issue
Block a user