How to use the isomorphic-git.readObject function in isomorphic-git

To help you get started, weโ€™ve selected a few isomorphic-git examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github elastic / kibana / x-pack / legacy / plugins / code / server / git_operations.ts View on Github external
}
    // test if it is a reference
    if (!obj) {
      try {
        // try local branches or tags
        oid = await isogit.resolveRef({ gitdir, ref, depth: 10 });
      } catch (e) {
        // try remote branches
        try {
          oid = await isogit.resolveRef({ gitdir, ref: `origin/${ref}`, depth: 10 });
        } catch (e1) {
          // no match
        }
      }
      if (oid) {
        obj = await isogit.readObject({ gitdir, oid, format: 'parsed' });
      }
    }
    if (obj) {
      if (obj.type === 'commit') {
        const commit = obj.object as isogit.CommitDescription;
        return {
          id: obj.oid,
          author: commit.author.name,
          committer: commit.committer.name,
          message: commit.message,
          updated: new Date(commit.committer.timestamp * 1000),
          parents: commit.parent,
        } as CommitInfo;
      } else if (obj.type === 'tag') {
        const tag = obj.object as isogit.TagDescription;
        if (tag.type === 'commit') {
github mizchi / next-editor / src / domain / git / queries / getRefOids.ts View on Github external
export async function getCommitOids(projectRoot: string, oid: string) {
  const { object: commit } = await git.readObject({ dir: projectRoot, oid })
  return await searchTree(projectRoot, commit.tree)
}
github elastic / kibana / x-pack / legacy / plugins / code / server / git_operations.ts View on Github external
yield {
                name: entry.path,
                type,
                path,
                repoUri: uri,
                sha1: entry.oid,
              } as FileTree;
            }
          }
        }
      }
    }

    const commit = await this.getCommitOr404(uri, revision);
    const gitdir = this.repoDir(uri);
    const commitObject = await isogit.readObject({ gitdir, oid: commit.id });
    const treeId = (commitObject.object as CommitDescription).tree;
    return await walk(treeId);
  }
github mizchi / next-editor / src / domain / git / queries / getRefOids.ts View on Github external
async function _searchTree({
  dir,
  oid,
  prefix
}: {
  dir: string
  oid: string
  prefix: string
}): Promise> {
  const { object: tree } = await git.readObject({ dir, oid })
  const files = await Promise.all(
    tree.entries.map(async (entry: any) => {
      if (entry.type === "blob") {
        return [
          {
            oid: entry.oid,
            filepath: path.join(prefix, entry.path)
          }
        ]
      } else if (entry.type === "tree") {
        return _searchTree({
          dir,
          oid: entry.oid,
          prefix: path.join(prefix, entry.path)
        })
      }
github elastic / kibana / x-pack / legacy / plugins / code / server / git_operations.ts View on Github external
public async countRepoFiles(uri: RepositoryUri, revision: string): Promise {
    let count = 0;
    const commit = await this.getCommitOr404(uri, revision);
    const gitdir = this.repoDir(uri);
    const commitObject = await isogit.readObject({ gitdir, oid: commit.id });
    const treeId = (commitObject.object as CommitDescription).tree;

    async function walk(oid: string) {
      const { object } = await isogit.readObject({ gitdir, oid });
      const tree = object as TreeDescription;
      for (const entry of tree.entries) {
        if (entry.type === 'tree') {
          await walk(entry.oid);
        } else if (entry.type === 'blob') {
          const type = GitOperations.mode2type(entry.mode);
          if (type === FileTreeItemType.File) {
            const blob = await isogit.readObject({ gitdir, oid: entry.oid, format: 'content' });
            if (!isBinaryFileSync(blob.object as Buffer)) {
              count++;
            }
          }
github elastic / kibana / x-pack / legacy / plugins / code / server / git_operations.ts View on Github external
async function walk(oid: string) {
      const { object } = await isogit.readObject({ gitdir, oid });
      const tree = object as TreeDescription;
      for (const entry of tree.entries) {
        if (entry.type === 'tree') {
          await walk(entry.oid);
        } else if (entry.type === 'blob') {
          const type = GitOperations.mode2type(entry.mode);
          if (type === FileTreeItemType.File) {
            const blob = await isogit.readObject({ gitdir, oid: entry.oid, format: 'content' });
            if (!isBinaryFileSync(blob.object as Buffer)) {
              count++;
            }
          }
        }
      }
    }
github elastic / kibana / x-pack / legacy / plugins / code / server / git_operations.ts View on Github external
async function* walk(oid: string, prefix: string = ''): AsyncIterableIterator {
      const { object } = await isogit.readObject({ gitdir, oid });
      const tree = object as TreeDescription;
      for (const entry of tree.entries) {
        const path = prefix ? `${prefix}/${entry.path}` : entry.path;
        if (entry.type === 'tree') {
          yield* walk(entry.oid, path);
        } else if (entry.type === 'blob') {
          const type = GitOperations.mode2type(entry.mode);
          if (type === FileTreeItemType.File) {
            const blob = await isogit.readObject({ gitdir, oid: entry.oid, format: 'content' });
            if (!isBinaryFileSync(blob.object as Buffer)) {
              yield {
                name: entry.path,
                type,
                path,
                repoUri: uri,
                sha1: entry.oid,
              } as FileTree;
            }
          }
        }
      }
    }
github elastic / kibana / x-pack / legacy / plugins / code / server / git_operations.ts View on Github external
public async fileContent(uri: RepositoryUri, path: string, revision: string = 'master') {
    const gitdir = this.repoDir(uri);
    const commit: CommitInfo = await this.getCommitOr404(uri, revision);
    const file = await isogit.readObject({
      gitdir,
      oid: commit.id,
      filepath: path,
      format: 'content',
    });
    if (file && file.type === 'blob') {
      return {
        isBinary() {
          return isBinaryFileSync(file.object as Buffer);
        },
        content() {
          return file.object as Buffer;
        },
        rawsize() {
          return (file.object as Buffer).length;
        },