lib/git.js
async function resolveBlob(dir, ref, pathName, includeUncommitted) {
  const commitSha = await resolveCommit(dir, ref);

  // project-helix/#150: check for uncommitted local changes
  // project-helix/#183: serve newly created uncommitted files
  // project-helix/#187: only serve uncommitted content if currently
  //                     checked-out and requested refs match

  if (!includeUncommitted) {
    return (await git.readObject({ dir, oid: commitSha, filepath: pathName })).oid;
  }
  // check working dir status
  const status = await git.status({ dir, filepath: pathName });
  if (status.endsWith('unmodified')) {
    return (await git.readObject({ dir, oid: commitSha, filepath: pathName })).oid;
  }
  if (status.endsWith('absent') || status.endsWith('deleted')) {
    const err = new Error(`Not found: ${pathName}`);
    err.code = git.E.TreeOrBlobNotFoundError;
    throw err;
  }
  // return blob id representing working dir file
  const content = await fse.readFile(resolvePath(dir, pathName));
  return git.writeObject({
    dir,
    object: content,
    type: 'blob',
    format: 'content',
  });
}
async function resolveBlob(dir, ref, pathName, includeUncommitted) {
  const commitSha = await resolveCommit(dir, ref);

  // project-helix/#150: check for uncommitted local changes
  // project-helix/#183: serve newly created uncommitted files
  // project-helix/#187: only serve uncommitted content if currently
  //                     checked-out and requested refs match

  if (!includeUncommitted) {
    return (await git.readObject({ dir, oid: commitSha, filepath: pathName })).oid;
  }
  // check working dir status
  const status = await git.status({ dir, filepath: pathName });
  if (status.endsWith('unmodified')) {
    return (await git.readObject({ dir, oid: commitSha, filepath: pathName })).oid;
  }
  if (status.endsWith('absent') || status.endsWith('deleted')) {
    const err = new Error(`Not found: ${pathName}`);
    err.code = git.E.TreeOrBlobNotFoundError;
    throw err;
  }
  // return blob id representing working dir file
  const content = await fse.readFile(resolvePath(dir, pathName));
  return git.writeObject({
    dir,
    object: content,
    type: 'blob',
    format: 'content',
  });
}
async function resolveBlob ( dir , ref , pathName , includeUncommitted ) { const commitSha = await resolveCommit ( dir , ref ) ; // project-helix/#150: check for uncommitted local changes // project-helix/#183: serve newly created uncommitted files // project-helix/#187: only serve uncommitted content if currently //                     checked-out and requested refs match if ( ! includeUncommitted ) { return ( await git . readObject ( { dir , oid : commitSha , filepath : pathName } ) ) . oid ; } // check working dir status const status = await git . status ( { dir , filepath : pathName } ) ; if ( status . endsWith ( 'unmodified' ) ) { return ( await git . readObject ( { dir , oid : commitSha , filepath : pathName } ) ) . oid ; } if ( status . endsWith ( 'absent' ) || status . endsWith ( 'deleted' ) ) { const err = new Error ( ` ${ pathName } ` ) ; err . code = git . E . TreeOrBlobNotFoundError ; throw err ; } // return blob id representing working dir file const content = await fse . readFile ( resolvePath ( dir , pathName ) ) ; return git . writeObject ( { dir , object : content , type : 'blob' , format : 'content' , } ) ; }
Returns the blob oid of the file at revision `ref` and `pathName`

@param {string} dir git repo path
@param {string} ref reference (branch, tag or commit sha)
@param {string} filePath relative path to file
@param {boolean} includeUncommitted include uncommitted changes in working dir
@returns {Promise<string>} blob oid of specified file
@throws {GitError} `err.code === 'TreeOrBlobNotFoundError'`: resource not found
`err.code === 'ResolveRefError'`: invalid reference
Returns the blob oid of the file at revision ref and pathName