lib/git.js
async function commitLog(dir, ref, path) {
  return git.log({ dir, ref, path })
    .catch(async (err) => {
      if (err.code === 'ResolveRefError') {
        // fallback: is ref a shortened oid prefix?
        const oid = await git.expandOid({ dir, oid: ref });
        return git.log({ dir, ref: oid, path });
      }
      // re-throw
      throw err;
    })
    .then(async (commits) => {
      if (typeof path === 'string' && path.length) {
        // filter by path
        let lastSHA = null;
        let lastCommit = null;
        const filteredCommits = [];
        for (let i = 0; i < commits.length; i += 1) {
          const commit = commits[i];
          /* eslint-disable no-await-in-loop */
          try {
            const o = await git.readObject({ dir, oid: commit.oid, filepath: path });
            if (i === commits.length - 1) {
              // file already existed in first commit
              filteredCommits.push(commit);
              break;
            }
            if (o.oid !== lastSHA) {
              if (lastSHA !== null) {
                filteredCommits.push(lastCommit);
              }
              lastSHA = o.oid;
            }
          } catch (err) {
            // file no longer there
            filteredCommits.push(lastCommit);
            break;
          }
          lastCommit = commit;
        }
        // unfiltered commits
        return filteredCommits;
      }
      // unfiltered commits
      return commits;
    });
}
async function commitLog(dir, ref, path) {
  return git.log({ dir, ref, path })
    .catch(async (err) => {
      if (err.code === 'ResolveRefError') {
        // fallback: is ref a shortened oid prefix?
        const oid = await git.expandOid({ dir, oid: ref });
        return git.log({ dir, ref: oid, path });
      }
      // re-throw
      throw err;
    })
    .then(async (commits) => {
      if (typeof path === 'string' && path.length) {
        // filter by path
        let lastSHA = null;
        let lastCommit = null;
        const filteredCommits = [];
        for (let i = 0; i < commits.length; i += 1) {
          const commit = commits[i];
          /* eslint-disable no-await-in-loop */
          try {
            const o = await git.readObject({ dir, oid: commit.oid, filepath: path });
            if (i === commits.length - 1) {
              // file already existed in first commit
              filteredCommits.push(commit);
              break;
            }
            if (o.oid !== lastSHA) {
              if (lastSHA !== null) {
                filteredCommits.push(lastCommit);
              }
              lastSHA = o.oid;
            }
          } catch (err) {
            // file no longer there
            filteredCommits.push(lastCommit);
            break;
          }
          lastCommit = commit;
        }
        // unfiltered commits
        return filteredCommits;
      }
      // unfiltered commits
      return commits;
    });
}
async function commitLog ( dir , ref , path ) { return git . log ( { dir , ref , path } ) . catch ( async ( err ) => { if ( err . code === 'ResolveRefError' ) { // fallback: is ref a shortened oid prefix? const oid = await git . expandOid ( { dir , oid : ref } ) ; return git . log ( { dir , ref : oid , path } ) ; } // re-throw throw err ; } ) . then ( async ( commits ) => { if ( typeof path === 'string' && path . length ) { // filter by path let lastSHA = null ; let lastCommit = null ; const filteredCommits = [ ] ; for ( let i = 0 ; i < commits . length ; i += 1 ) { const commit = commits [ i ] ; /* eslint-disable no-await-in-loop */ try { const o = await git . readObject ( { dir , oid : commit . oid , filepath : path } ) ; if ( i === commits . length - 1 ) { // file already existed in first commit filteredCommits . push ( commit ) ; break ; } if ( o . oid !== lastSHA ) { if ( lastSHA !== null ) { filteredCommits . push ( lastCommit ) ; } lastSHA = o . oid ; } } catch ( err ) { // file no longer there filteredCommits . push ( lastCommit ) ; break ; } lastCommit = commit ; } // unfiltered commits return filteredCommits ; } // unfiltered commits return commits ; } ) ; }
Returns a commit log, i.e. an array of commits in reverse chronological order.

@param {string} dir git repo path
@param {string} ref reference (branch, tag or commit sha)
@param {string} path only commits containing this file path will be returned
@throws {GitError} `err.code === 'ResolveRefError'`: invalid reference
`err.code === 'ReadObjectFail'`: not found
Returns a commit log i . e . an array of commits in reverse chronological order .