MCPcopy Create free account
hub / github.com/decaporg/decap-cms / assertPathUnderRoot

Function assertPathUnderRoot

packages/decap/src/dev/middlewares/utils/path.ts:24–40  ·  view source on GitHub ↗
(repoRoot: string, resolvedPath: string)

Source from the content-addressed store, hash-verified

22}
23
24function 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
42export function resolveRepoPath(repoPath: string, filePath: string) {
43 const repoRoot = path.resolve(repoPath);

Callers 3

resolveRepoPathFunction · 0.85
resolveExistingRepoPathFunction · 0.85
resolveNewRepoPathFunction · 0.85

Calls 1

someMethod · 0.80

Tested by

no test coverage detected