| 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 { |
| 152 | changedEntries.push([null, stage]) // record the change (deletion) while stop the iteration |
| 153 | } |
| 154 | } |
| 155 | } else if (head) { |
| 156 | // for deleted file in workdir, "stage" (workdir in our case) will be undefined |
| 157 | if (!stage) { |
| 158 | changedEntries.push([head, null]) // record the change (deletion) while stop the iteration |
| 159 | } else { |
| 160 | filtered.push(child) // workdir, tracked only |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | return filtered.length ? Promise.all(filtered.map(walk)) : [] |
| 165 | } |
| 166 | |
| 167 | const entries = await _walk({ |
| 168 | fs, |