MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / validateWorktreeSlug

Function validateWorktreeSlug

source code/utils/worktree.ts:68–89  ·  view source on GitHub ↗
(slug: string)

Source from the content-addressed store, hash-verified

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