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

Method diff

packages/insomnia/src/sync/git/git-vcs.ts:642–927  ·  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

640 * @returns Array of file status objects with detailed diff information
641 */
642 async diff() {
643 const baseOpts = this._baseOpts;
644 const classifyStatusFn = this.classifyStatus.bind(this);
645
646 // Adopted from statusMatrix of isomorphic-git https://github.com/isomorphic-git/isomorphic-git/blob/main/src/api/statusMatrix.js#L157
647 const status: {
648 filepath: string;
649 head: { name: string; status: git.HeadStatus };
650 workdir: { name: string; status: git.WorkdirStatus };
651 stage: { name: string; status: git.StageStatus };
652 classification: { type: GitFileStatus; symbol: GitFileStatusSymbol };
653 stagedDiff?: Change[];
654 unstagedDiff?: Change[];
655 }[] = await git.walk({
656 ...baseOpts,
657 trees: [
658 // What the latest commit on the current branch looks like
659 git.TREE({ ref: 'HEAD' }),
660 // What the working directory looks like
661 git.WORKDIR(),
662 // What the index (staging area) looks like
663 git.STAGE(),
664 ],
665 map: async function map(filepath, [head, workdir, stage]) {
666 if (baseOpts.legacyDiff) {
667 const isInsomniaFile =
668 filepath.startsWith(GIT_INSOMNIA_DIR_NAME) || filepath.startsWith('insomnia.') || filepath === '.';
669 if (!isInsomniaFile) {
670 return null;
671 }
672 } else {
673 // We want to inspect the repo root '.', directories (so the walk keeps
674 // recursing into them), and yaml files. Skip files with a non-yaml
675 // extension and dotfiles such as .gitignore/.DS_Store (whose extension
676 // is empty) — but keep yaml dotfiles like .spectral.yaml.
677 const ext = path.extname(filepath).toLowerCase();
678 const base = path.basename(filepath);
679 const isYamlFile = ext === '.yaml';
680 const isDotfile = base !== '.' && base.startsWith('.');
681 if (!isYamlFile && (ext || isDotfile)) {
682 return null;
683 }
684 }
685
686 if (
687 await git.isIgnored({
688 ...baseOpts,
689 filepath,
690 })
691 ) {
692 return null;
693 }
694 const [headType, workdirType, stageType] = await Promise.all([
695 head && head.type(),
696 workdir && workdir.type(),
697 stage && stage.type(),
698 ]);
699

Callers 2

clientActionFunction · 0.80
diffFunction · 0.80

Calls 6

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

Tested by

no test coverage detected