( gitDir: string, refPath: string, branchPrefix: string, )
| 285 | * Checks loose file only — packed-refs doesn't store symrefs. |
| 286 | */ |
| 287 | export 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. |
no test coverage detected