Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ai_prompt_auto_commit/prepare_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ def prepare_repository(
# Add .prompts/ to the root .gitignore
root_gitignore = repo_root / ".gitignore"
pattern = f"/{prompts_directory}/"
existing = root_gitignore.read_text(encoding="utf-8").splitlines() if root_gitignore.exists() else []
existing_text = root_gitignore.read_text(encoding="utf-8") if root_gitignore.exists() else ""
existing = existing_text.splitlines()
if pattern not in existing:
with root_gitignore.open("a", encoding="utf-8") as fh:
if existing_text and not existing_text.endswith("\n"):
fh.write("\n")
fh.write(f"{pattern}\n")
print(f"Added '{pattern}' to {root_gitignore}")
else:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_prepare_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def test_root_gitignore_existing_content_preserved(repo: Path) -> None:
assert f"/{PROMPTS_DIRECTORY}/" in content


def test_root_gitignore_newline_added_when_missing(repo: Path) -> None:
(repo / ".gitignore").write_text("*.pyc", encoding="utf-8") # no trailing newline
prepare_repository()
lines = (repo / ".gitignore").read_text(encoding="utf-8").splitlines()
assert f"/{PROMPTS_DIRECTORY}/" in lines
assert lines[0] == "*.pyc"


# ---------------------------------------------------------------------------
# get_default_claude_settings
# ---------------------------------------------------------------------------
Expand Down
Loading