MCPcopy Create free account
hub / github.com/isomorphic-git/isomorphic-git / resetIndex

Function resetIndex

src/api/resetIndex.js:31–120  ·  view source on GitHub ↗
({
  fs: _fs,
  dir,
  gitdir = join(dir, '.git'),
  filepath,
  ref,
  cache = {},
})

Source from the content-addressed store, hash-verified

29 *
30 */
31export async function resetIndex({
32 fs: _fs,
33 dir,
34 gitdir = join(dir, '.git'),
35 filepath,
36 ref,
37 cache = {},
38}) {
39 try {
40 assertParameter('fs', _fs)
41 assertParameter('gitdir', gitdir)
42 assertParameter('filepath', filepath)
43
44 const fs = new FileSystem(_fs)
45 const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir })
46
47 let oid
48 let workdirOid
49
50 try {
51 // Resolve commit
52 oid = await GitRefManager.resolve({
53 fs,
54 gitdir: updatedGitdir,
55 ref: ref || 'HEAD',
56 })
57 } catch (e) {
58 if (ref) {
59 // Only throw the error if a ref is explicitly provided
60 throw e
61 }
62 }
63
64 // Not having an oid at this point means `resetIndex()` was called without explicit `ref` on a new git
65 // repository. If that happens, we can skip resolving the file path.
66 if (oid) {
67 try {
68 // Resolve blob
69 oid = await resolveFilepath({
70 fs,
71 cache,
72 gitdir: updatedGitdir,
73 oid,
74 filepath,
75 })
76 } catch (e) {
77 // This means we're resetting the file to a "deleted" state
78 oid = null
79 }
80 }
81
82 // For files that aren't in the workdir use zeros
83 let stats = {
84 ctime: new Date(0),
85 mtime: new Date(0),
86 dev: 0,
87 ino: 0,
88 mode: 0,

Callers 2

test-resetIndex.jsFile · 0.85

Calls 11

readMethod · 0.95
lstatMethod · 0.95
joinFunction · 0.90
assertParameterFunction · 0.90
discoverGitdirFunction · 0.90
resolveFilepathFunction · 0.90
hashObjectFunction · 0.90
resolveMethod · 0.80
acquireMethod · 0.80
insertMethod · 0.80
deleteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…