Remove ``/.cocoindex_code/`` entry and its comment from ``.gitignore``.
(project_root: Path)
| 294 | |
| 295 | |
| 296 | def remove_from_gitignore(project_root: Path) -> None: |
| 297 | """Remove ``/.cocoindex_code/`` entry and its comment from ``.gitignore``.""" |
| 298 | gitignore = project_root / ".gitignore" |
| 299 | if not gitignore.is_file(): |
| 300 | return |
| 301 | |
| 302 | lines = gitignore.read_text().splitlines(keepends=True) |
| 303 | new_lines: list[str] = [] |
| 304 | i = 0 |
| 305 | while i < len(lines): |
| 306 | stripped = lines[i].rstrip("\n\r") |
| 307 | if stripped == _GITIGNORE_ENTRY: |
| 308 | # Skip this line; also remove preceding comment if it matches |
| 309 | if new_lines and new_lines[-1].rstrip("\n\r") == _GITIGNORE_COMMENT: |
| 310 | new_lines.pop() |
| 311 | i += 1 |
| 312 | continue |
| 313 | new_lines.append(lines[i]) |
| 314 | i += 1 |
| 315 | gitignore.write_text("".join(new_lines)) |
| 316 | |
| 317 | |
| 318 | # --------------------------------------------------------------------------- |
no outgoing calls