({
fs: _fs,
dir,
gitdir = join(dir, '.git'),
filepath,
cache = {},
refresh = true,
})
| 55 | * |
| 56 | */ |
| 57 | export async function status({ |
| 58 | fs: _fs, |
| 59 | dir, |
| 60 | gitdir = join(dir, '.git'), |
| 61 | filepath, |
| 62 | cache = {}, |
| 63 | refresh = true, |
| 64 | }) { |
| 65 | try { |
| 66 | assertParameter('fs', _fs) |
| 67 | assertParameter('gitdir', gitdir) |
| 68 | assertParameter('filepath', filepath) |
| 69 | |
| 70 | const fs = new FileSystem(_fs) |
| 71 | const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir }) |
| 72 | const ignored = await GitIgnoreManager.isIgnored({ |
| 73 | fs, |
| 74 | gitdir: updatedGitdir, |
| 75 | dir, |
| 76 | filepath, |
| 77 | }) |
| 78 | if (ignored) { |
| 79 | return 'ignored' |
| 80 | } |
| 81 | const headTree = await getHeadTree({ fs, cache, gitdir: updatedGitdir }) |
| 82 | const treeOid = await getOidAtPath({ |
| 83 | fs, |
| 84 | cache, |
| 85 | gitdir: updatedGitdir, |
| 86 | tree: headTree, |
| 87 | path: filepath, |
| 88 | }) |
| 89 | const indexEntry = await GitIndexManager.acquire( |
| 90 | { fs, gitdir: updatedGitdir, cache }, |
| 91 | async function (index) { |
| 92 | for (const entry of index) { |
| 93 | if (entry.path === filepath) return entry |
| 94 | } |
| 95 | return null |
| 96 | } |
| 97 | ) |
| 98 | const stats = await fs.lstat(join(dir, filepath)) |
| 99 | |
| 100 | const H = treeOid !== null // head |
| 101 | const I = indexEntry !== null // index |
| 102 | const W = stats !== null // working dir |
| 103 | |
| 104 | const getWorkdirOid = async () => { |
| 105 | if (I && !compareStats(indexEntry, stats)) { |
| 106 | return indexEntry.oid |
| 107 | } else { |
| 108 | const object = await fs.read(join(dir, filepath)) |
| 109 | const workdirOid = await hashObject({ |
| 110 | gitdir: updatedGitdir, |
| 111 | type: 'blob', |
| 112 | object, |
| 113 | }) |
| 114 | // If the oid in the index === working dir oid but stats differed update cache |
searching dependent graphs…