MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / readRawSymref

Function readRawSymref

src/utils/git/gitFilesystem.ts:287–309  ·  view source on GitHub ↗
(
  gitDir: string,
  refPath: string,
  branchPrefix: string,
)

Source from the content-addressed store, hash-verified

285 * Checks loose file only — packed-refs doesn't store symrefs.
286 */
287export async function readRawSymref(
288 gitDir: string,
289 refPath: string,
290 branchPrefix: string,
291): Promise<string | null> {
292 try {
293 const content = (await readFile(join(gitDir, refPath), 'utf-8')).trim()
294 if (content.startsWith('ref:')) {
295 const target = content.slice('ref:'.length).trim()
296 if (target.startsWith(branchPrefix)) {
297 const name = target.slice(branchPrefix.length)
298 // Reject path traversal and argument injection from a tampered symref.
299 if (!isSafeRefName(name)) {
300 return null
301 }
302 return name
303 }
304 }
305 } catch {
306 // Not a loose ref
307 }
308 return null
309}
310
311// ---------------------------------------------------------------------------
312// GitFileWatcher — watches git files and caches derived values.

Callers 1

computeDefaultBranchFunction · 0.85

Calls 2

readFileFunction · 0.85
isSafeRefNameFunction · 0.85

Tested by

no test coverage detected