( projectRoot: string, hooks: GitHookName[] = DEFAULT_SYNC_HOOKS, )
| 287 | * the user's content untouched. |
| 288 | */ |
| 289 | export function removeGitSyncHook( |
| 290 | projectRoot: string, |
| 291 | hooks: GitHookName[] = DEFAULT_SYNC_HOOKS, |
| 292 | ): GitHookResult { |
| 293 | const hooksDir = gitHooksDir(projectRoot); |
| 294 | if (!hooksDir) { |
| 295 | return { installed: [], hooksDir: null, skipped: 'not a git repository' }; |
| 296 | } |
| 297 | |
| 298 | const owns = ownerFor(projectRoot); |
| 299 | const removed: GitHookName[] = []; |
| 300 | |
| 301 | for (const hook of hooks) { |
| 302 | const file = path.join(hooksDir, hook); |
| 303 | if (!fs.existsSync(file)) continue; |
| 304 | |
| 305 | const original = fs.readFileSync(file, 'utf8'); |
| 306 | if (!blockRoots(original).some(owns)) continue; |
| 307 | |
| 308 | const stripped = stripMarkerBlocks(original, owns); |
| 309 | if (isEffectivelyEmpty(stripped)) { |
| 310 | fs.unlinkSync(file); |
| 311 | } else { |
| 312 | fs.writeFileSync(file, `${stripped.replace(/\s*$/, '')}\n`); |
| 313 | chmodExecutable(file); |
| 314 | } |
| 315 | removed.push(hook); |
| 316 | } |
| 317 | |
| 318 | return { installed: removed, hooksDir }; |
| 319 | } |
| 320 | |
| 321 | /** Whether a CodeGraph sync hook is installed for this project root. */ |
| 322 | export function isSyncHookInstalled( |
no test coverage detected