feat: add source control action to abort merge (#2092)

Co-authored-by: Orca <help@stably.ai>
Co-authored-by: brennanb2025 <brennankbenson@gmail.com>
This commit is contained in:
Leynier Gutiérrez González
2026-05-27 14:59:23 -07:00
committed by GitHub
co-authored by Orca brennanb2025
parent a65f7b4216
commit 659fe79226
25 changed files with 478 additions and 7 deletions
+31
View File
@@ -8,6 +8,7 @@ import type * as CommitMessageTextGenerationModule from '../text-generation/comm
import { RuntimeGitCommands, type ResolvedRuntimeGitWorktree } from './orca-runtime-git'
const mocks = vi.hoisted(() => ({
abortMerge: vi.fn(),
getStagedCommitContext: vi.fn(),
generateCommitMessageFromContext: vi.fn(),
resolveCommitMessageSettings: vi.fn(),
@@ -16,6 +17,7 @@ const mocks = vi.hoisted(() => ({
vi.mock('../git/status', async () => ({
...(await vi.importActual<typeof GitStatusModule>('../git/status')),
abortMerge: mocks.abortMerge,
getStagedCommitContext: mocks.getStagedCommitContext
}))
@@ -57,6 +59,7 @@ function makeCommands(worktreePath: string): RuntimeGitCommands {
describe('RuntimeGitCommands', () => {
beforeEach(() => {
mocks.abortMerge.mockReset()
mocks.getStagedCommitContext.mockReset()
mocks.generateCommitMessageFromContext.mockReset()
mocks.resolveCommitMessageSettings.mockReset()
@@ -69,6 +72,34 @@ describe('RuntimeGitCommands', () => {
}
})
it('aborts a local merge through the resolved worktree', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const commands = makeCommands(worktreePath)
mocks.abortMerge.mockResolvedValue(undefined)
await expect(commands.abortRuntimeGitMerge('id:wt-1')).resolves.toEqual({ ok: true })
expect(mocks.abortMerge).toHaveBeenCalledWith(worktreePath)
})
it('aborts a remote merge through the SSH git provider', async () => {
const provider = { abortMerge: vi.fn().mockResolvedValue(undefined) }
mocks.getSshGitProvider.mockReturnValue(provider)
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => ({
worktree: makeWorktree('/remote/repo'),
connectionId: 'conn-1'
}),
getRuntimeSettings: () => ({}) as GlobalSettings
})
await expect(commands.abortRuntimeGitMerge('id:wt-1')).resolves.toEqual({ ok: true })
expect(provider.abortMerge).toHaveBeenCalledWith('/remote/repo')
expect(mocks.abortMerge).not.toHaveBeenCalled()
})
it('rejects slash-only git mutation paths before they can target the worktree root', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
+15
View File
@@ -17,6 +17,7 @@ import { getCommitMessageModelDiscoveryHostKey } from '../../shared/commit-messa
import type { GitHistoryOptions, GitHistoryResult } from '../../shared/git-history'
import { getRemoteFileUrl } from '../git/repo'
import {
abortMerge,
bulkDiscardChanges,
bulkStageFiles,
bulkUnstageFiles,
@@ -148,6 +149,20 @@ export class RuntimeGitCommands {
return detectConflictOperation(target.worktree.path)
}
async abortRuntimeGitMerge(worktreeSelector: string): Promise<{ ok: true }> {
const target = await this.host.resolveRuntimeGitTarget(worktreeSelector)
const provider = target.connectionId ? getSshGitProvider(target.connectionId) : null
if (target.connectionId) {
if (!provider) {
throw new Error(SSH_GIT_PROVIDER_UNAVAILABLE_MESSAGE)
}
await provider.abortMerge(target.worktree.path)
return { ok: true }
}
await abortMerge(target.worktree.path)
return { ok: true }
}
async getRuntimeGitDiff(
worktreeSelector: string,
filePath: string,
+2
View File
@@ -2047,6 +2047,8 @@ export class OrcaRuntimeService {
this.gitCommands.getRuntimeGitHistory.bind(this.gitCommands)
getRuntimeGitConflictOperation: RuntimeGitCommands['getRuntimeGitConflictOperation'] =
this.gitCommands.getRuntimeGitConflictOperation.bind(this.gitCommands)
abortRuntimeGitMerge: RuntimeGitCommands['abortRuntimeGitMerge'] =
this.gitCommands.abortRuntimeGitMerge.bind(this.gitCommands)
getRuntimeGitDiff: RuntimeGitCommands['getRuntimeGitDiff'] =
this.gitCommands.getRuntimeGitDiff.bind(this.gitCommands)
getRuntimeGitBranchCompare: RuntimeGitCommands['getRuntimeGitBranchCompare'] =
+3
View File
@@ -197,6 +197,7 @@ describe('git RPC methods', () => {
defaultModelId: 'auto'
}),
cancelRuntimeGenerateCommitMessage: vi.fn().mockResolvedValue({ ok: true }),
abortRuntimeGitMerge: vi.fn().mockResolvedValue({ ok: true }),
pushRuntimeGit: vi.fn().mockResolvedValue({ ok: true }),
getRuntimeGitRemoteFileUrl: vi.fn().mockResolvedValue('https://example.com/file#L3')
} as unknown as OrcaRuntimeService
@@ -216,6 +217,7 @@ describe('git RPC methods', () => {
await dispatcher.dispatch(
makeRequest('git.cancelGenerateCommitMessage', { worktree: 'id:wt-1' })
)
await dispatcher.dispatch(makeRequest('git.abortMerge', { worktree: 'id:wt-1' }))
await dispatcher.dispatch(
makeRequest('git.push', {
worktree: 'id:wt-1',
@@ -237,6 +239,7 @@ describe('git RPC methods', () => {
agentCmdOverrides: { cursor: 'cursor-agent' }
})
expect(runtime.cancelRuntimeGenerateCommitMessage).toHaveBeenCalledWith('id:wt-1')
expect(runtime.abortRuntimeGitMerge).toHaveBeenCalledWith('id:wt-1')
expect(runtime.pushRuntimeGit).toHaveBeenCalledWith(
'id:wt-1',
true,
+5
View File
@@ -51,6 +51,11 @@ export const GIT_METHODS: RpcMethod[] = [
params: WorktreeSelector,
handler: async (params, { runtime }) => runtime.getRuntimeGitConflictOperation(params.worktree)
}),
defineMethod({
name: 'git.abortMerge',
params: WorktreeSelector,
handler: async (params, { runtime }) => runtime.abortRuntimeGitMerge(params.worktree)
}),
defineMethod({
name: 'git.diff',
params: GitDiff,
+14
View File
@@ -761,6 +761,7 @@ describe('OrcaRuntimeRpcServer', () => {
.fn()
.mockResolvedValue({ hasUpstream: true, ahead: 1, behind: 0 })
const rebaseRuntimeGitFromBase = vi.fn().mockResolvedValue({ ok: true })
const abortRuntimeGitMerge = vi.fn().mockResolvedValue({ ok: true })
const bulkStageRuntimeGitPaths = vi.fn().mockResolvedValue({ ok: true })
const bulkUnstageRuntimeGitPaths = vi.fn().mockResolvedValue({ ok: true })
const getRuntimeGitDiff = vi.fn().mockResolvedValue({
@@ -842,6 +843,7 @@ describe('OrcaRuntimeRpcServer', () => {
getRuntimeGitStatus,
getRuntimeGitUpstreamStatus,
rebaseRuntimeGitFromBase,
abortRuntimeGitMerge,
bulkStageRuntimeGitPaths,
bulkUnstageRuntimeGitPaths,
getRuntimeGitDiff,
@@ -1400,6 +1402,16 @@ describe('OrcaRuntimeRpcServer', () => {
(response) => replies.push(JSON.parse(response) as Record<string, unknown>),
() => {}
)
await server['handleWebSocketMessage'](
JSON.stringify({
id: 'req_git_abort_merge',
method: 'git.abortMerge',
deviceToken: mobile.token,
params: { worktree: 'id:wt-1' }
}),
(response) => replies.push(JSON.parse(response) as Record<string, unknown>),
() => {}
)
await server['handleWebSocketMessage'](
JSON.stringify({
id: 'req_git_bulk_unstage',
@@ -1612,6 +1624,7 @@ describe('OrcaRuntimeRpcServer', () => {
expect.objectContaining({ id: 'req_git_rebase_from_base', ok: true })
)
expect(replies).toContainEqual(expect.objectContaining({ id: 'req_git_bulk_stage', ok: true }))
expect(replies).toContainEqual(expect.objectContaining({ id: 'req_git_abort_merge', ok: true }))
expect(replies).toContainEqual(
expect.objectContaining({ id: 'req_git_bulk_unstage', ok: true })
)
@@ -1646,6 +1659,7 @@ describe('OrcaRuntimeRpcServer', () => {
expect(pushRuntimeGit).toHaveBeenCalledWith('id:wt-1', true, undefined, undefined)
expect(getRuntimeGitUpstreamStatus).toHaveBeenCalledWith('id:wt-1')
expect(bulkStageRuntimeGitPaths).toHaveBeenCalledWith('id:wt-1', ['a.ts', 'b.ts'])
expect(abortRuntimeGitMerge).toHaveBeenCalledWith('id:wt-1')
expect(bulkUnstageRuntimeGitPaths).toHaveBeenCalledWith('id:wt-1', ['c.ts'])
expect(openMobileDiff).toHaveBeenCalledWith('id:wt-1', 'docs/readme.md', true)
expect(getRuntimeGitDiff).toHaveBeenCalledWith('id:wt-1', 'docs/readme.md', false, undefined)
+1
View File
@@ -145,6 +145,7 @@ const MOBILE_RPC_METHOD_ALLOWLIST = new Set([
'files.open',
'files.openDiff',
'files.read',
'git.abortMerge',
'git.bulkStage',
'git.bulkUnstage',
'git.commit',