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

Method listRefs

src/managers/GitRefManager.js:449–473  ·  view source on GitHub ↗

* Lists all refs matching a given filepath prefix. * * @param {Object} args * @param {FSClient} args.fs - A file system implementation. * @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path * @param {string} args.filepath - The filep

({ fs, gitdir, filepath })

Source from the content-addressed store, hash-verified

447 * @returns {Promise<string[]>} - A sorted list of refs.
448 */
449 static async listRefs({ fs, gitdir, filepath }) {
450 const packedMap = GitRefManager.packedRefs({ fs, gitdir })
451 let files = null
452 try {
453 files = await fs.readdirDeep(`${gitdir}/${filepath}`)
454 files = files.map(x => x.replace(`${gitdir}/${filepath}/`, ''))
455 } catch (err) {
456 files = []
457 }
458
459 for (let key of (await packedMap).keys()) {
460 // filter by prefix
461 if (key.startsWith(filepath)) {
462 // remove prefix
463 key = key.replace(filepath + '/', '')
464 // Don't include duplicates; the loose files have precedence anyway
465 if (!files.includes(key)) {
466 files.push(key)
467 }
468 }
469 }
470 // since we just appended things onto an array, we need to sort them now
471 files.sort(compareRefNames)
472 return files
473 }
474
475 /**
476 * Lists all branches, optionally filtered by remote.

Callers 8

_fetchFunction · 0.80
uploadPackFunction · 0.80
updateRemoteRefsMethod · 0.80
listBranchesMethod · 0.80
listTagsMethod · 0.80
listRefsFunction · 0.80

Calls 2

packedRefsMethod · 0.80
readdirDeepMethod · 0.80

Tested by

no test coverage detected