Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/insomnia/src/sync/vcs/insomnia-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ export const VCSInstance = () => {
const driver = FileSystemDriver.create(
process.env['INSOMNIA_DATA_PATH'] || window.app.getPath('userData'),
);
vcs = new VCS(driver, async conflicts => {
vcs = new VCS(driver, async (conflicts, labels) => {
return new Promise(resolve => {
showModal(SyncMergeModal, {
conflicts,
labels,
handleDone: (conflicts?: MergeConflict[]) =>
resolve(conflicts || []),
});
Expand Down
7 changes: 4 additions & 3 deletions packages/insomnia/src/sync/vcs/vcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {

const EMPTY_HASH = crypto.createHash('sha1').digest('hex').replace(/./g, '0');

type ConflictHandler = (conflicts: MergeConflict[]) => Promise<MergeConflict[]>;
type ConflictHandler = (conflicts: MergeConflict[], labels: { ours: string; theirs: string }) => Promise<MergeConflict[]>;

// breaks one array into multiple arrays of size chunkSize
export function chunkArray<T>(arr: T[], chunkSize: number) {
Expand Down Expand Up @@ -331,6 +331,7 @@ export class VCS {

async handleAnyConflicts(
conflicts: MergeConflict[],
labels: { ours: string; theirs: string },
errorMsg: string,
): Promise<MergeConflict[]> {
if (conflicts.length === 0) {
Expand All @@ -341,7 +342,7 @@ export class VCS {
throw new Error(errorMsg);
}

return this._conflictHandler(conflicts);
return this._conflictHandler(conflicts, labels);
}

async allDocuments(): Promise<Record<string, any>> {
Expand Down Expand Up @@ -674,7 +675,7 @@ export class VCS {
latestStateOther,
);
// Update state with conflict resolutions applied
const conflictResolutions = await this.handleAnyConflicts(mergeConflicts, '');
const conflictResolutions = await this.handleAnyConflicts(mergeConflicts, otherBranchName.includes('.hidden') ? { ours: `${trunkBranchName} local`, theirs: `${otherBranchName.replace('.hidden', '')} remote` } : { ours: trunkBranchName, theirs: otherBranchName }, '');
const state = updateStateWithConflictResolutions(stateBeforeConflicts, conflictResolutions);

// Sometimes we want to merge into trunk but keep the other branch's history
Expand Down
13 changes: 10 additions & 3 deletions packages/insomnia/src/ui/components/modals/sync-merge-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Icon } from '../icon';

export interface SyncMergeModalOptions {
conflicts?: MergeConflict[];
labels: { ours: string; theirs: string };
handleDone?: (conflicts?: MergeConflict[]) => void;
}
export interface SyncMergeModalHandle {
Expand All @@ -17,18 +18,21 @@ export const SyncMergeModal = forwardRef<SyncMergeModalHandle>((_, ref) => {
const [state, setState] = useState<SyncMergeModalOptions & { isOpen: boolean }>({
conflicts: [],
isOpen: false,
labels: { ours: '', theirs: '' },
});

useImperativeHandle(ref, () => ({
hide: () => setState({
conflicts: [],
isOpen: false,
labels: { ours: '', theirs: '' },
}),
show: ({ conflicts, handleDone }) => {
show: ({ conflicts, labels, handleDone }) => {
setState({
conflicts,
handleDone,
isOpen: true,
labels,
});

window.main.trackSegmentEvent({
Expand All @@ -46,6 +50,7 @@ export const SyncMergeModal = forwardRef<SyncMergeModalHandle>((_, ref) => {
!isOpen && setState({
conflicts: [],
isOpen: false,
labels: { ours: '', theirs: '' },
});
}}
isDismissable
Expand All @@ -56,6 +61,7 @@ export const SyncMergeModal = forwardRef<SyncMergeModalHandle>((_, ref) => {
!isOpen && setState({
conflicts: [],
isOpen: false,
labels: { ours: '', theirs: '' },
});
}}
className="flex flex-col max-w-4xl w-full rounded-md border border-solid border-[--hl-sm] p-[--padding-lg] max-h-full bg-[--color-bg] text-[--color-font]"
Expand Down Expand Up @@ -95,6 +101,7 @@ export const SyncMergeModal = forwardRef<SyncMergeModalHandle>((_, ref) => {
setState({
conflicts: [],
isOpen: false,
labels: { ours: '', theirs: '' },
});
}}
>
Expand Down Expand Up @@ -162,7 +169,7 @@ export const SyncMergeModal = forwardRef<SyncMergeModalHandle>((_, ref) => {
>
<Icon icon="laptop" />
<span>
Accept ours
Accept ours ({state.labels.ours})
</span>
</Radio>
<Radio
Expand All @@ -171,7 +178,7 @@ export const SyncMergeModal = forwardRef<SyncMergeModalHandle>((_, ref) => {
>
<Icon icon="globe" />
<span>
Accept theirs
Accept theirs ({state.labels.theirs})
</span>
</Radio>
</div>
Expand Down