MCPcopy
hub / github.com/Kong/insomnia / diff

Method diff

packages/insomnia/src/sync/git/git-vcs.ts:603–881  ·  view source on GitHub ↗

* Get the status of all files with their content diffs and classification. * This method returns the filepath, git status information, file classification, * and detailed line-by-line diffs for staged and unstaged changes. * * For each file, you can have: * - stagedDiff: Line-by-line

()

Source from the content-addressed store, hash-verified

601 * @returns Array of file status objects with detailed diff information
602 */
603 async diff() {
604 const baseOpts = this._baseOpts;
605 const classifyStatusFn = this.classifyStatus.bind(this);
606
607 // Adopted from statusMatrix of isomorphic-git https://github.com/isomorphic-git/isomorphic-git/blob/main/src/api/statusMatrix.js#L157
608 const status: {
609 filepath: string;
610 head: { name: string; status: git.HeadStatus };
611 workdir: { name: string; status: git.WorkdirStatus };
612 stage: { name: string; status: git.StageStatus };
613 classification: { type: GitFileStatus; symbol: GitFileStatusSymbol };
614 stagedDiff?: Change[];
615 unstagedDiff?: Change[];
616 }[] = await git.walk({
617 ...baseOpts,
618 trees: [
619 // What the latest commit on the current branch looks like
620 git.TREE({ ref: 'HEAD' }),
621 // What the working directory looks like
622 git.WORKDIR(),
623 // What the index (staging area) looks like
624 git.STAGE(),
625 ],
626 map: async function map(filepath, [head, workdir, stage]) {
627 if (baseOpts.legacyDiff) {
628 const isInsomniaFile =
629 filepath.startsWith(GIT_INSOMNIA_DIR_NAME) || filepath.startsWith('insomnia.') || filepath === '.';
630 if (!isInsomniaFile) {
631 return null;
632 }
633 } else {
634 // If the path is a file with an extension different than yaml we don't want to check it
635 if (path.extname(filepath) && path.extname(filepath) !== '.yaml') {
636 return null;
637 }
638 }
639
640 if (
641 await git.isIgnored({
642 ...baseOpts,
643 filepath,
644 })
645 ) {
646 return null;
647 }
648 const [headType, workdirType, stageType] = await Promise.all([
649 head && head.type(),
650 workdir && workdir.type(),
651 stage && stage.type(),
652 ]);
653
654 const isBlob = [headType, workdirType, stageType].includes('blob');
655
656 // For now, bail on directories unless the file is also a blob in another tree
657 if ((headType === 'tree' || headType === 'special') && !isBlob) {
658 return;
659 }
660 if (headType === 'commit') {

Callers 4

clientActionFunction · 0.80
diffFunction · 0.80
micromatchFunction · 0.80
matchFunction · 0.80

Calls 8

walkMethod · 0.80
mapMethod · 0.80
shiftMethod · 0.80
readBlobMethod · 0.80
allMethod · 0.65
indexOfMethod · 0.45
logMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected