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

Method getTreeMap

packages/insomnia/src/sync/git/git-vcs.ts:1676–1702  ·  view source on GitHub ↗
(oid: string)

Source from the content-addressed store, hash-verified

1674 }
1675
1676 async getTreeMap(oid: string): Promise<Record<string, git.TreeEntry>> {
1677 const { commit } = await git.readCommit({ ...this._baseOpts, oid });
1678 const { tree } = await git.readTree({ ...this._baseOpts, oid: commit.tree });
1679
1680 const treeMap: Record<string, git.TreeEntry> = {};
1681
1682 const baseOpts = this._baseOpts;
1683
1684 async function walkTree(entries: ArrayIterator<git.TreeEntry>, prefix = '') {
1685 for (const entry of entries) {
1686 const filepath = path.posix.join(prefix, entry.path);
1687 if (entry.type === 'tree') {
1688 const { tree: subtree } = await git.readTree({ ...baseOpts, oid: entry.oid });
1689 await walkTree(subtree.values(), filepath);
1690 } else if (entry.type === 'blob') {
1691 treeMap[filepath] = entry;
1692 }
1693 }
1694 }
1695
1696 await walkTree(tree.values());
1697
1698 // Return the tree map with file paths as keys and git.TreeEntry as values
1699 // This allows us to easily check for conflicts between local and remote trees
1700 // and to extract file contents when needed
1701 return treeMap;
1702 }
1703
1704 /**
1705 * Whether a conflicted file is an Insomnia file, judged by its content (a top-level `type` that is an

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected