({
fs,
dir,
gitdir,
stashCommit,
parentCommit,
wasStaged,
})
| 197 | } |
| 198 | |
| 199 | export async function applyTreeChanges({ |
| 200 | fs, |
| 201 | dir, |
| 202 | gitdir, |
| 203 | stashCommit, |
| 204 | parentCommit, |
| 205 | wasStaged, |
| 206 | }) { |
| 207 | const dirRemoved = [] |
| 208 | const stageUpdated = [] |
| 209 | |
| 210 | // analyze the changes |
| 211 | const ops = await _walk({ |
| 212 | fs, |
| 213 | cache: {}, |
| 214 | dir, |
| 215 | gitdir, |
| 216 | trees: [TREE({ ref: parentCommit }), TREE({ ref: stashCommit })], |
| 217 | map: async (filepath, [parent, stash]) => { |
| 218 | if ( |
| 219 | filepath === '.' || |
| 220 | (await GitIgnoreManager.isIgnored({ fs, dir, gitdir, filepath })) |
| 221 | ) { |
| 222 | return |
| 223 | } |
| 224 | const type = stash ? await stash.type() : await parent.type() |
| 225 | if (type !== 'tree' && type !== 'blob') { |
| 226 | return |
| 227 | } |
| 228 | |
| 229 | // deleted tree or blob |
| 230 | if (!stash && parent) { |
| 231 | const method = type === 'tree' ? 'rmdir' : 'rm' |
| 232 | if (type === 'tree') dirRemoved.push(filepath) |
| 233 | if (type === 'blob' && wasStaged) |
| 234 | stageUpdated.push({ filepath, oid: await parent.oid() }) // stats is undefined, will stage the deletion with index.insert |
| 235 | return { method, filepath } |
| 236 | } |
| 237 | |
| 238 | const oid = await stash.oid() |
| 239 | if (!parent || (await parent.oid()) !== oid) { |
| 240 | // only apply changes if changed from the parent commit or doesn't exist in the parent commit |
| 241 | if (type === 'tree') { |
| 242 | return { method: 'mkdir', filepath } |
| 243 | } else { |
| 244 | if (wasStaged) |
| 245 | stageUpdated.push({ |
| 246 | filepath, |
| 247 | oid, |
| 248 | stats: await fs.lstat(join(dir, filepath)), |
| 249 | }) |
| 250 | return { |
| 251 | method: 'write', |
| 252 | filepath, |
| 253 | oid, |
| 254 | } |
| 255 | } |
| 256 | } |
no test coverage detected
searching dependent graphs…