MCPcopy Create free account
hub / github.com/Kong/insomnia / diffFileLoader

Function diffFileLoader

packages/insomnia/src/main/git-service.ts:3592–3672  ·  view source on GitHub ↗
({
  projectId,
  workspaceId,
  filepath,
  staged,
}: {
  projectId: string;
  workspaceId?: string;
  filepath: string;
  staged: boolean;
})

Source from the content-addressed store, hash-verified

3590 };
3591
3592export const diffFileLoader = async ({
3593 projectId,
3594 workspaceId,
3595 filepath,
3596 staged,
3597}: {
3598 projectId: string;
3599 workspaceId?: string;
3600 filepath: string;
3601 staged: boolean;
3602}): Promise<GitDiffResult> => {
3603 try {
3604 await getGitRepository({ workspaceId, projectId });
3605 const fileStatus = await GitVCS.fileStatus(filepath);
3606
3607 const diff = staged
3608 ? {
3609 before: fileStatus.head,
3610 after: fileStatus.stage,
3611 }
3612 : {
3613 before: fileStatus.stage || fileStatus.head,
3614 after: fileStatus.workdir,
3615 };
3616
3617 // The change analysis parses both files, so only pay for it when Debug Mode is on.
3618 let diagnostics: GitDiffDiagnostics | undefined;
3619 if ((await services.settings.get()).debugMode) {
3620 // Analyse the untouched blobs so reordering isn't masked by the normalization
3621 // applied for rendering.
3622 const rawBefore = staged ? fileStatus.rawHead : fileStatus.rawStage || fileStatus.rawHead;
3623 const rawAfter = staged ? fileStatus.rawStage : fileStatus.workdir;
3624
3625 diagnostics = {
3626 appVersion: getAppVersion(),
3627 filepath,
3628 staged,
3629 comparing: staged ? 'HEAD (last commit) → index (staged)' : 'index/HEAD (committed) → working copy (on disk)',
3630 beforeOid: (staged ? fileStatus.oids.head : fileStatus.oids.stage || fileStatus.oids.head) ?? null,
3631 afterOid: (staged ? fileStatus.oids.stage : fileStatus.oids.workdir) ?? null,
3632 displayNormalized: (rawBefore ?? '') !== (diff.before ?? ''),
3633 committedYaml: rawBefore ?? null,
3634 report: buildInsomniaChangeReport(rawBefore, rawAfter),
3635 };
3636 }
3637
3638 const { name, scope } = getPreviewItemNameAndScope(diff);
3639
3640 let undiscardable = false;
3641 if (!staged) {
3642 try {
3643 // `diff.before` is migrated and reordered for display, but discard restores the raw index/HEAD content
3644 undiscardable = await isUndiscardableChange({
3645 filepath,
3646 baselineContent: fileStatus.rawStage || fileStatus.rawHead,
3647 workingCopyContent: fileStatus.workdir,
3648 });
3649 } catch (err) {

Calls 8

getAppVersionFunction · 0.90
isUndiscardableChangeFunction · 0.90
findUnknownFieldRangesFunction · 0.90
getGitRepositoryFunction · 0.85
fileStatusMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected