( projectRoot: string, hooks: GitHookName[] = DEFAULT_SYNC_HOOKS, )
| 168 | * the user's content untouched. |
| 169 | */ |
| 170 | export function removeGitSyncHook( |
| 171 | projectRoot: string, |
| 172 | hooks: GitHookName[] = DEFAULT_SYNC_HOOKS, |
| 173 | ): GitHookResult { |
| 174 | const hooksDir = gitHooksDir(projectRoot); |
| 175 | if (!hooksDir) { |
| 176 | return { installed: [], hooksDir: null, skipped: 'not a git repository' }; |
| 177 | } |
| 178 | |
| 179 | const removed: GitHookName[] = []; |
| 180 | |
| 181 | for (const hook of hooks) { |
| 182 | const file = path.join(hooksDir, hook); |
| 183 | if (!fs.existsSync(file)) continue; |
| 184 | |
| 185 | const original = fs.readFileSync(file, 'utf8'); |
| 186 | if (!original.includes(MARKER_BEGIN)) continue; |
| 187 | |
| 188 | const stripped = stripMarkerBlock(original); |
| 189 | if (isEffectivelyEmpty(stripped)) { |
| 190 | fs.unlinkSync(file); |
| 191 | } else { |
| 192 | fs.writeFileSync(file, `${stripped.replace(/\s*$/, '')}\n`); |
| 193 | chmodExecutable(file); |
| 194 | } |
| 195 | removed.push(hook); |
| 196 | } |
| 197 | |
| 198 | return { installed: removed, hooksDir }; |
| 199 | } |
| 200 | |
| 201 | /** Whether any CodeGraph sync hook is currently installed. */ |
| 202 | export function isSyncHookInstalled( |
no test coverage detected