Files
orca/src/relay/git-handler-push-target.ts
T
Neil 5a626dcdf4 refactor(git): share push-target resolution between local and the SSH relay (#18406)
`src/relay/git-handler-push-target.ts` and `src/main/git/remote.ts` carried
identical ~160-line copies of the resolver that decides which remote a plain
`git push` hits. Identical today is exactly when to share it: the cost of a
future divergence is pushing to the wrong remote, which retrying does not undo.

Move the resolver to src/shared/git-push-target-resolution.ts, parameterized on
a `(args) => Promise<{ stdout }>` runner — the only thing the two hosts actually
differ in — and delete both copies. The relay entry point keeps only the work
that is genuinely relay-side: re-validating an explicit target that arrived over
the wire and running `check-ref-format` on it.

No behavior change on either path, and nothing new or different is published, so
this engages no rule in remote-wire-compatibility. No git command changes.

src/relay/git-push-target-local-parity.test.ts scripts one repository's config
and requires `git.push` over the real relay dispatcher and the desktop's
`gitPush` to emit the same push argv, plus the argv each case should produce.
2026-09-03 14:42:58 -07:00

28 lines
1.1 KiB
TypeScript

import { assertGitPushTargetShape } from '../shared/git-push-target-validation'
import {
resolveConfiguredGitPushTarget,
type ResolvedGitPushTarget
} from '../shared/git-push-target-resolution'
import type { GitPushTarget } from '../shared/worktree/types'
type RelayGit = (args: string[], cwd: string) => Promise<{ stdout: string; stderr: string }>
export async function resolveRelayPushTarget(
git: RelayGit,
worktreePath: string,
pushTarget: unknown
): Promise<ResolvedGitPushTarget | null> {
if (pushTarget === undefined) {
return resolveConfiguredGitPushTarget((args) => git(args, worktreePath))
}
assertGitPushTargetShape(pushTarget)
const explicitTarget: GitPushTarget = pushTarget
// Why here and not in the shared resolver: an explicit target arrives over the wire,
// so the host re-validates its shape and asks Git to vet the branch name itself.
await git(['check-ref-format', '--branch', explicitTarget.branchName], worktreePath)
return {
remote: explicitTarget.remoteName,
refspec: `HEAD:${explicitTarget.branchName}`
}
}