Skip to content

Commit

Permalink
Resolve error when user aborts merge in cloud sync (#8133)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoweiprc authored Oct 31, 2024
1 parent 2bc22d2 commit 4c759b0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
11 changes: 9 additions & 2 deletions packages/insomnia/src/sync/vcs/insomnia-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'));
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
});
}}
>
<Icon icon={mergeBranchFetcher.state !== 'idle' ? 'spinner' : 'code-merge'} className={`w-5 ${mergeBranchFetcher.state !== 'idle' ? 'animate-spin' : ''}`} />
Merge
Expand Down
13 changes: 11 additions & 2 deletions packages/insomnia/src/ui/routes/remote-collections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 4c759b0

Please sign in to comment.