[英]Creating a line diff with isomorphic-git
我正在嘗試從isomorphic-git獲取 output,它類似於git diff
的 GitHub 操作。
我在這里查看了git.walk
實現中的map
function,但我在使用它時遇到了問題。
我成功地能夠使用以下代碼走樹:
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()
如何改進map
function 並使用jsdiff將當前工作樹和HEAD
之間的文件更改為 output 到標准輸出?
在 isomorphic-git 代碼片段頁面上有一個關於執行 git diff 的示例代碼。
https://isomorphic-git.org/docs/en/snippets#git-diff-name-status-commithash1-commithash2
結果如下所示:
[
{ path: '/.gitignore', type: 'equal' },
{ path: '/package.json', type: 'modify' },
]
對於每個文件,它生成 oid
const Aoid = await A.oid()
const Boid = await B.oid()
有了這些,我相信您可以使用 readObject 方法來獲取差異內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.