MCPcopy Index your code
hub / github.com/isomorphic-git/isomorphic-git / applyTreeChanges

Function applyTreeChanges

src/utils/walkerToTreeEntryMap.js:199–304  ·  view source on GitHub ↗
({
  fs,
  dir,
  gitdir,
  stashCommit,
  parentCommit,
  wasStaged,
})

Source from the content-addressed store, hash-verified

197}
198
199export 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 }

Callers 2

_cherryPickFunction · 0.90
_stashApplyFunction · 0.90

Calls 15

_walkFunction · 0.90
TREEFunction · 0.90
joinFunction · 0.90
_readObjectFunction · 0.90
isIgnoredMethod · 0.80
lstatMethod · 0.80
rmdirMethod · 0.80
mkdirMethod · 0.80
rmMethod · 0.80
acquireMethod · 0.80
insertMethod · 0.80
acquireLockFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…