diff --git a/packages/insomnia/src/sync/vcs/insomnia-sync.ts b/packages/insomnia/src/sync/vcs/insomnia-sync.ts index 528ad1246d6..290278685ce 100644 --- a/packages/insomnia/src/sync/vcs/insomnia-sync.ts +++ b/packages/insomnia/src/sync/vcs/insomnia-sync.ts @@ -6,6 +6,13 @@ import { VCS } from './vcs'; let vcs: VCS | null = null; +export class UserAbortResolveMergeConflictError extends Error { + constructor(msg: string = 'User aborted merge') { + super(msg); + } + name = 'UserAbortResolveMergeConflictError'; +} + export const VCSInstance = () => { if (vcs) { return vcs; @@ -21,9 +28,9 @@ export const VCSInstance = () => { handleDone: (conflicts?: MergeConflict[]) => { if (conflicts && conflicts.length) { resolve(conflicts); + } else { + reject(new UserAbortResolveMergeConflictError()); } - - reject(new Error('User aborted merge')); }, }); }); diff --git a/packages/insomnia/src/ui/components/modals/sync-branches-modal.tsx b/packages/insomnia/src/ui/components/modals/sync-branches-modal.tsx index 790a26785b4..ad931f5672f 100644 --- a/packages/insomnia/src/ui/components/modals/sync-branches-modal.tsx +++ b/packages/insomnia/src/ui/components/modals/sync-branches-modal.tsx @@ -95,12 +95,15 @@ const LocalBranchItem = ({ doneMessage="Merged" confirmMessage='Confirm' disabled={isCurrent} - onClick={() => mergeBranchFetcher.submit({ - branch, - }, { - method: 'POST', - action: `/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/insomnia-sync/branch/merge`, - })} + onClick={() => { + // file://./../../routes/remote-collections.tsx#mergeBranchAction + mergeBranchFetcher.submit({ + branch, + }, { + method: 'POST', + action: `/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/insomnia-sync/branch/merge`, + }); + }} > Merge diff --git a/packages/insomnia/src/ui/routes/remote-collections.tsx b/packages/insomnia/src/ui/routes/remote-collections.tsx index 6b665df58b1..ebecbc983f6 100644 --- a/packages/insomnia/src/ui/routes/remote-collections.tsx +++ b/packages/insomnia/src/ui/routes/remote-collections.tsx @@ -24,7 +24,7 @@ import type { Status, StatusCandidate, } from '../../sync/types'; -import { VCSInstance } from '../../sync/vcs/insomnia-sync'; +import { UserAbortResolveMergeConflictError, VCSInstance } from '../../sync/vcs/insomnia-sync'; import { pullBackendProject } from '../../sync/vcs/pull-backend-project'; import { invariant } from '../../utils/invariant'; @@ -417,7 +417,16 @@ export const mergeBranchAction: ActionFunction = async ({ invariant(typeof branch === 'string', 'Branch is required'); const vcs = VCSInstance(); const { syncItems } = await getSyncItems({ workspaceId }); - const delta = await vcs.merge(syncItems, branch); + let delta; + try { + delta = await vcs.merge(syncItems, branch); + } catch (err) { + if (err instanceof UserAbortResolveMergeConflictError) { + return null; + } else { + throw err; + } + } try { await database.batchModifyDocs(delta as Operation); delete remoteCompareCache[workspaceId];