(repoRoot: string, resolvedPath: string)
| 22 | } |
| 23 | |
| 24 | function assertPathUnderRoot(repoRoot: string, resolvedPath: string) { |
| 25 | const relativePath = path.relative(repoRoot, resolvedPath); |
| 26 | |
| 27 | if ( |
| 28 | relativePath === '..' || |
| 29 | relativePath.startsWith(`..${path.sep}`) || |
| 30 | path.isAbsolute(relativePath) |
| 31 | ) { |
| 32 | throw new Error(invalidPathMessage); |
| 33 | } |
| 34 | |
| 35 | // Git's config and hooks live under .git, so writing there runs commands |
| 36 | // (a clean filter on the next `git add`, a hook on the next commit). |
| 37 | if (relativePath.split(/[\\/]/).some(isGitDirSegment)) { |
| 38 | throw new Error(gitPathMessage); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | export function resolveRepoPath(repoPath: string, filePath: string) { |
| 43 | const repoRoot = path.resolve(repoPath); |
no test coverage detected