spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / hooks / git / probes / is-safe-ref-name / is-safe-ref-name.ts
15 lines · 539 BRaw
1import { SAFE_REF_PATTERN } from './safe-ref-pattern'
2
3/**
4 * Whether HEAD's `ref:` text names a ref the poll may stat: under `refs/`,
5 * plain characters, no `..`, no component ending `.lock`.
6 *
7 * Git's refname rules, narrowed; anything else is read through git.
8 *
9 * @param ref the text after `ref: `
10 * @returns whether the ref is safe to join under the common directory
11 */
12export const isSafeRefName = (ref: string) =>
13 SAFE_REF_PATTERN.test(ref) &&
14 !ref.includes('..') &&
15 !ref.split('/').some(part => part.endsWith('.lock'))