({
fs,
dir,
gitdir,
treePair, // [TREE({ ref: 'HEAD' }), 'STAGE'] would be the equivalent of `git write-tree`
})
| 92 | } |
| 93 | |
| 94 | export async function writeTreeChanges({ |
| 95 | fs, |
| 96 | dir, |
| 97 | gitdir, |
| 98 | treePair, // [TREE({ ref: 'HEAD' }), 'STAGE'] would be the equivalent of `git write-tree` |
| 99 | }) { |
| 100 | const isStage = treePair[1] === 'stage' |
| 101 | const trees = treePair.map(t => (typeof t === 'string' ? _TreeMap[t]() : t)) |
| 102 | |
| 103 | const changedEntries = [] |
| 104 | // transform WalkerEntry objects into the desired format |
| 105 | const map = async (filepath, [head, stage]) => { |
| 106 | if ( |
| 107 | filepath === '.' || |
| 108 | (await GitIgnoreManager.isIgnored({ fs, dir, gitdir, filepath })) |
| 109 | ) { |
| 110 | return |
| 111 | } |
| 112 | |
| 113 | if (stage) { |
| 114 | if ( |
| 115 | !head || |
| 116 | ((await head.oid()) !== (await stage.oid()) && |
| 117 | (await stage.oid()) !== undefined) |
| 118 | ) { |
| 119 | changedEntries.push([head, stage]) |
| 120 | } |
| 121 | return { |
| 122 | mode: await stage.mode(), |
| 123 | path: filepath, |
| 124 | oid: await stage.oid(), |
| 125 | type: await stage.type(), |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | // combine mapped entries with their parent results |
| 131 | const reduce = async (parent, children) => { |
| 132 | children = children.filter(Boolean) // Remove undefined entries |
| 133 | if (!parent) { |
| 134 | return children.length > 0 ? children : undefined |
| 135 | } else { |
| 136 | parent.children = children |
| 137 | return parent |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | // if parent is skipped, skip the children |
| 142 | const iterate = async (walk, children) => { |
| 143 | const filtered = [] |
| 144 | for (const child of children) { |
| 145 | const [head, stage] = child |
| 146 | if (isStage) { |
| 147 | if (stage) { |
| 148 | // for deleted file in work dir, it also needs to be added on stage |
| 149 | if (await fs.exists(`${dir}/${stage.toString()}`)) { |
| 150 | filtered.push(child) |
| 151 | } else { |
no test coverage detected
searching dependent graphs…