Add ``/.cocoindex_code/`` to ``.gitignore`` if ``.git`` exists. Creates ``.gitignore`` if it doesn't exist. Skips if the entry is already present.
(project_root: Path)
| 271 | |
| 272 | |
| 273 | def add_to_gitignore(project_root: Path) -> None: |
| 274 | """Add ``/.cocoindex_code/`` to ``.gitignore`` if ``.git`` exists. |
| 275 | |
| 276 | Creates ``.gitignore`` if it doesn't exist. Skips if the entry is already |
| 277 | present. |
| 278 | """ |
| 279 | if not (project_root / ".git").is_dir(): |
| 280 | return |
| 281 | |
| 282 | gitignore = project_root / ".gitignore" |
| 283 | if gitignore.is_file(): |
| 284 | content = gitignore.read_text() |
| 285 | if _GITIGNORE_ENTRY in content.splitlines(): |
| 286 | return # already present |
| 287 | # Ensure a trailing newline before appending |
| 288 | if content and not content.endswith("\n"): |
| 289 | content += "\n" |
| 290 | content += f"{_GITIGNORE_COMMENT}\n{_GITIGNORE_ENTRY}\n" |
| 291 | gitignore.write_text(content) |
| 292 | else: |
| 293 | gitignore.write_text(f"{_GITIGNORE_COMMENT}\n{_GITIGNORE_ENTRY}\n") |
| 294 | |
| 295 | |
| 296 | def remove_from_gitignore(project_root: Path) -> None: |
no outgoing calls