({ fs, cache, gitdir, oid, filepath })
| 7 | import { resolveTree } from '../utils/resolveTree.js' |
| 8 | |
| 9 | export async function resolveFilepath({ fs, cache, gitdir, oid, filepath }) { |
| 10 | // Ensure there are no leading or trailing directory separators. |
| 11 | // I was going to do this automatically, but then found that the Git Terminal for Windows |
| 12 | // auto-expands --filepath=/src/utils to --filepath=C:/Users/Will/AppData/Local/Programs/Git/src/utils |
| 13 | // so I figured it would be wise to promote the behavior in the application layer not just the library layer. |
| 14 | if (filepath.startsWith('/')) { |
| 15 | throw new InvalidFilepathError('leading-slash') |
| 16 | } else if (filepath.endsWith('/')) { |
| 17 | throw new InvalidFilepathError('trailing-slash') |
| 18 | } |
| 19 | const _oid = oid |
| 20 | const result = await resolveTree({ fs, cache, gitdir, oid }) |
| 21 | const tree = result.tree |
| 22 | if (filepath === '') { |
| 23 | oid = result.oid |
| 24 | } else { |
| 25 | const pathArray = filepath.split('/') |
| 26 | oid = await _resolveFilepath({ |
| 27 | fs, |
| 28 | cache, |
| 29 | gitdir, |
| 30 | tree, |
| 31 | pathArray, |
| 32 | oid: _oid, |
| 33 | filepath, |
| 34 | }) |
| 35 | } |
| 36 | return oid |
| 37 | } |
| 38 | |
| 39 | async function _resolveFilepath({ |
| 40 | fs, |
no test coverage detected
searching dependent graphs…