static async acquire({ fs, gitdir, cache, allowUnmerged = true }, closure) {
    if (!cache[IndexCache]) {
      cache[IndexCache] = createCache()
    }

    const filepath = `${gitdir}/index`
    if (lock === null) lock = new AsyncLock({ maxPending: Infinity })
    let result
    let unmergedPaths = []
    await lock.acquire(filepath, async () => {
      // Acquire a file lock while we're reading the index
      // to make sure other processes aren't writing to it
      // simultaneously, which could result in a corrupted index.
      // const fileLock = await Lock(filepath)
      const theIndexCache = cache[IndexCache]
      if (await isIndexStale(fs, filepath, theIndexCache)) {
        await updateCachedIndexFile(fs, filepath, theIndexCache)
      }
      const index = theIndexCache.map.get(filepath)
      unmergedPaths = index.unmergedPaths

      if (unmergedPaths.length && !allowUnmerged)
        throw new UnmergedPathsError(unmergedPaths)

      result = await closure(index)
      if (index._dirty) {
        // Acquire a file lock while we're writing the index file
        // let fileLock = await Lock(filepath)
        const buffer = await index.toObject()
        await fs.write(filepath, buffer)
        // Update cached stat value
        theIndexCache.stats.set(filepath, await fs.lstat(filepath))
        index._dirty = false
      }
    })

    return result
  }
@param {object} opts
@param {import('../models/FileSystem.js').FileSystem} opts.fs
@param {string} opts.gitdir
@param {object} opts.cache
@param {bool} opts.allowUnmerged
@param {function(GitIndex): any} closure