I am trying to get output from isomorphic-git that is similar to git diff for a GitHub action.
I took a look at the map function on the git.walk implementation in isomorphic-git here but I'm having trouble using it.
I'm successfully able to walk the tree using the following code:
async function main() {
const ref = 'HEAD'
const trees = [git.TREE({ref}), git.WORKDIR()]
const walk = await git.walk({
fs,
dir: '.github',
trees,
map: (filepath, [workdir, tree]) => [filepath, !!workdir, !!tree]
})
console.log(walk)
}
main()
How can I improve the map function here and use jsdiff to output the changes in the files between my current worktree and HEAD to stdout?
There is an example code on performing a git diff on the isomorphic-git code snippets page.
https://isomorphic-git.org/docs/en/snippets#git-diff-name-status-commithash1-commithash2
The result looks like this:
For each file, it generates the oid
With those, I believe you can use the readObject method to get the content to diff.
https://isomorphic-git.org/docs/en/readObject