MCPcopy Create free account
hub / github.com/cocoindex-io/cocoindex-code / remove_from_gitignore

Function remove_from_gitignore

src/cocoindex_code/cli.py:296–315  ·  view source on GitHub ↗

Remove ``/.cocoindex_code/`` entry and its comment from ``.gitignore``.

(project_root: Path)

Source from the content-addressed store, hash-verified

294
295
296def 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# ---------------------------------------------------------------------------

Callers 3

resetFunction · 0.85

Calls

no outgoing calls

Tested by 2