diff --git a/packages/insomnia/src/common/insomnia-v5.ts b/packages/insomnia/src/common/insomnia-v5.ts index ba1fae2b50..0ce3171808 100644 --- a/packages/insomnia/src/common/insomnia-v5.ts +++ b/packages/insomnia/src/common/insomnia-v5.ts @@ -147,7 +147,7 @@ function getApiSpec(file: InsomniaFile): [WithExportType] | [] { _type: EXPORT_TYPE_API_SPEC, fileName: 'file' in file.spec ? file.spec.file : '', contentType: 'json', - contents: 'contents' in file.spec && file.spec.contents ? JSON.stringify(file.spec.contents) : '', + contents: 'contents' in file.spec && file.spec.contents ? stringify(file.spec.contents) : '', parentId: file.meta?.id || '__WORKSPACE_ID__', }]; } diff --git a/packages/insomnia/src/main/git-service.ts b/packages/insomnia/src/main/git-service.ts index f6bf9c4d9e..831853c759 100644 --- a/packages/insomnia/src/main/git-service.ts +++ b/packages/insomnia/src/main/git-service.ts @@ -1408,9 +1408,17 @@ export const pushToGitRemoteAction = async ({ }); await database.flushChanges(bufferId); } catch (err: unknown) { + if (err instanceof Errors.PushRejectedError && err.data.reason === 'not-fast-forward') { + return { + errors: ['Push Rejected. It seems that the remote repository has changes that you do not have locally. Please pull the changes and try again.'], + gitRepository, + }; + } + if (err instanceof Errors.HttpError) { return { errors: [`${err.message}, ${err.data.response}`], + gitRepository, }; } const errorMessage = err instanceof Error ? err.message : 'Unknown Error'; diff --git a/packages/insomnia/src/sync/git/git-vcs.ts b/packages/insomnia/src/sync/git/git-vcs.ts index f088d7b03d..7e9dea5ba1 100644 --- a/packages/insomnia/src/sync/git/git-vcs.ts +++ b/packages/insomnia/src/sync/git/git-vcs.ts @@ -656,23 +656,36 @@ export class GitVCS { async push(gitCredentials?: GitCredentials | null, force = false) { console.log(`[git] Push remote=origin force=${force ? 'true' : 'false'}`); - // eslint-disable-next-line no-unreachable - const response: git.PushResult = await git.push({ + + const response = await git.push({ ...this._baseOpts, ...gitCallbacks(gitCredentials), remote: 'origin', force, }); - // @ts-expect-error -- TSCONVERSION git errors are not handled correctly - if (response.errors?.length) { + if (response.error) { console.log('[git] Push rejected', response); - // @ts-expect-error -- TSCONVERSION git errors are not handled correctly + throw new Error( + `Push rejected with errors: ${response.error}.\n\nGo to View > Toggle DevTools > Console for more information.` + ); + } + + if ('errors' in response && response.errors && Array.isArray(response.errors)) { + console.log('[git] Push failed with errors', response.errors); const errorsString = JSON.stringify(response.errors); throw new Error( `Push rejected with errors: ${errorsString}.\n\nGo to View > Toggle DevTools > Console for more information.` ); } + + // NOTE: Response can be ok and have errors so we check this in the end to make sure we throw an error if there are any. + if (response.ok) { + console.log('[git] Push successful'); + return; + } + + throw new Error('Push failed with unknown error. Please try again.'); } async _hasUncommittedChanges() { @@ -896,9 +909,15 @@ export class GitVCS { oursBranch, theirsBranch, ); - } else { - throw err; } + + if (err instanceof git.Errors.MergeNotSupportedError) { + const errorMessage = 'Merges with additions are not supported yet.'; + + throw new Error(errorMessage); + } + + throw err; }, ); } diff --git a/packages/insomnia/src/ui/components/modals/git-project-staging-modal.tsx b/packages/insomnia/src/ui/components/modals/git-project-staging-modal.tsx index a3b701308b..bfe6d35b6d 100644 --- a/packages/insomnia/src/ui/components/modals/git-project-staging-modal.tsx +++ b/packages/insomnia/src/ui/components/modals/git-project-staging-modal.tsx @@ -103,8 +103,8 @@ export const GitProjectStagingModal: FC<{ onClose: () => void }> = ({ const { Form, formAction, state, data } = useFetcher<{ errors?: string[] }>(); - const isCreatingSnapshot = state === 'loading' && formAction === '/organization/:organizationId/project/:projectId/workspace/:workspaceId/git/commit'; - const isPushing = state === 'loading' && formAction === '/organization/:organizationId/project/:projectId/workspace/:workspaceId/git/commit-and-push'; + const isCreatingSnapshot = state !== 'idle' && formAction === `/organization/${organizationId}/project/${projectId}/git/commit`; + const isPushing = state !== 'idle' && formAction === `/organization/${organizationId}/project/${projectId}/git/commit-and-push`; const previewDiffItem = diffChangesFetcher.data && 'diff' in diffChangesFetcher.data ? diffChangesFetcher.data : null; const allChanges = [...changes.staged, ...changes.unstaged]; diff --git a/packages/insomnia/src/ui/components/modals/git-repository-settings-modal/git-project-repository-settings-modal.tsx b/packages/insomnia/src/ui/components/modals/git-repository-settings-modal/git-project-repository-settings-modal.tsx index 0a2ebda7e8..78a6aa858d 100644 --- a/packages/insomnia/src/ui/components/modals/git-repository-settings-modal/git-project-repository-settings-modal.tsx +++ b/packages/insomnia/src/ui/components/modals/git-repository-settings-modal/git-project-repository-settings-modal.tsx @@ -30,12 +30,10 @@ function getDefaultOAuthProvider(credentials?: GitCredentials | null): OauthProv return 'custom'; } -export const GitProjectRepositorySettingsModal = (props: ModalProps & { +export const GitProjectRepositorySettingsModal = ({ gitRepository, ...modalProps }: ModalProps & { gitRepository?: GitRepository; }) => { const { organizationId, projectId } = useParams() as { organizationId: string; projectId: string; workspaceId: string }; - const { gitRepository } = props; - const modalRef = useRef(null); const updateGitRepositoryFetcher = useFetcher(); const deleteGitRepositoryFetcher = useFetcher(); @@ -89,7 +87,7 @@ export const GitProjectRepositorySettingsModal = (props: ModalProps & { return ( - + Repository Settings{' '} @@ -159,7 +157,7 @@ export const GitProjectRepositorySettingsModal = (props: ModalProps & { > - + {hasGitRepository ? ( + + ) : ( + + )} diff --git a/packages/insomnia/src/ui/components/modals/git-repository-settings-modal/git-repository-settings-modal.tsx b/packages/insomnia/src/ui/components/modals/git-repository-settings-modal/git-repository-settings-modal.tsx index fa3c3af501..717ea62ef9 100644 --- a/packages/insomnia/src/ui/components/modals/git-repository-settings-modal/git-repository-settings-modal.tsx +++ b/packages/insomnia/src/ui/components/modals/git-repository-settings-modal/git-repository-settings-modal.tsx @@ -30,11 +30,10 @@ function getDefaultOAuthProvider(credentials?: GitCredentials | null): OauthProv return 'custom'; } -export const GitRepositorySettingsModal = (props: ModalProps & { +export const GitRepositorySettingsModal = ({ gitRepository, ...modalProps }: ModalProps & { gitRepository?: GitRepository; }) => { const { organizationId, projectId, workspaceId } = useParams() as { organizationId: string; projectId: string; workspaceId: string }; - const { gitRepository } = props; const modalRef = useRef(null); const updateGitRepositoryFetcher = useFetcher(); const deleteGitRepositoryFetcher = useFetcher(); @@ -88,7 +87,7 @@ export const GitRepositorySettingsModal = (props: ModalProps & { return ( - + Repository Settings{' '} @@ -158,7 +157,7 @@ export const GitRepositorySettingsModal = (props: ModalProps & { >