Skip to content

Commit 993471f

Browse files
committed
Add 'ref' parameter to listFiles command
1 parent 31f2d93 commit 993471f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

docs/listFiles.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@ title: listFiles
33
sidebar_label: listFiles
44
---
55

6-
List all the files in the git index
6+
List all the files in the git index or a commit
77

88
| param | type [= default] | description |
99
| ----------------------- | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
1010
| **fs**, **dir**, gitdir | FSModule, string, string | The filesystem holding the git repo, the [working tree](dir-vs-gitdir.md) directory path, and optionally the [git directory](dir-vs-gitdir.md) path |
11-
| return | Promise\<Array\<string\>\> | Resolves successfully with an array of branch names |
11+
| ref | string = undefined | Return a list of all the files in the commit at `ref` instead of the files currently in the git index (aka staging area) |
12+
| return | Promise\<Array\<string\>\> | Resolves successfully with an array of filepaths |
13+
14+
> 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.
15+
> If you do not require a complete list of every file, better can be achieved by using [readObject](./readObject.html) directly and ignoring subdirectories you don't care about.
1216
1317
```js live
1418
let repo = {fs, dir: '$input((.))'}
19+
// All the files in the previous commit
20+
files = await git.listFiles({...repo, ref: '$input((HEAD))'})
21+
console.log(files)
22+
// All the files in the current staging area
1523
let files = await git.listFiles(repo)
1624
console.log(files)
17-
```
25+
```

0 commit comments

Comments
 (0)