listFiles
List all the files in the git index or a commit
param | type [= default] | description |
---|---|---|
fs | FsClient | a file system client |
dir | string | The working tree directory path |
gitdir | string = join(dir,'.git') | The git directory path |
ref | string | Return a list of all the files in the commit at ref instead of the files currently in the git index (aka staging area) |
cache | object | a cache object |
return | Promise<Array<string>> | Resolves successfully with an array of filepaths |
Note: This function is efficient for listing the files in the staging area, but listing all the files in a commit requires recursively walking through the git object store. If you do not require a complete list of every file, better performance can be achieved by using walk and ignoring subdirectories you don't care about.
Example Code:
// All the files in the previous commit
let files = await git.listFiles({ fs, dir: '/tutorial', ref: 'HEAD' })
console.log(files)
// All the files in the current staging area
files = await git.listFiles({ fs, dir: '/tutorial' })
console.log(files)
Tip: If you need a clean slate, expand and run this snippet to clean up the file system.
window.fs = new LightningFS('fs', { wipe: true })
window.pfs = window.fs.promises
console.log('done')