MCPcopy Create free account
hub / github.com/Noumena-Network/code / validateWorktreeSlug

Function validateWorktreeSlug

src/utils/worktree.ts:70–91  ·  view source on GitHub ↗
(slug: string)

Source from the content-addressed store, hash-verified

68 * (git commands, hook execution, chdir).
69 */
70export function validateWorktreeSlug(slug: string): void {
71 if (slug.length > MAX_WORKTREE_SLUG_LENGTH) {
72 throw new Error(
73 `Invalid worktree name: must be ${MAX_WORKTREE_SLUG_LENGTH} characters or fewer (got ${slug.length})`,
74 )
75 }
76 // Leading or trailing `/` would make path.join produce an absolute path
77 // or a dangling segment. Splitting and validating each segment rejects
78 // both (empty segments fail the regex) while allowing `user/feature`.
79 for (const segment of slug.split('/')) {
80 if (segment === '.' || segment === '..') {
81 throw new Error(
82 `Invalid worktree name "${slug}": must not contain "." or ".." path segments`,
83 )
84 }
85 if (!VALID_WORKTREE_SLUG_SEGMENT.test(segment)) {
86 throw new Error(
87 `Invalid worktree name "${slug}": each "/"-separated segment must be non-empty and contain only letters, digits, dots, underscores, and dashes`,
88 )
89 }
90 }
91}
92
93// Helper function to create directories recursively
94async function mkdirRecursive(dirPath: string): Promise<void> {

Callers 4

createWorktreeForSessionFunction · 0.85
createAgentWorktreeFunction · 0.85
execIntoTmuxWorktreeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected