* 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 })
| 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. |
no test coverage detected