File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,9 +56,12 @@ def prepare_repository(
5656 # Add .prompts/ to the root .gitignore
5757 root_gitignore = repo_root / ".gitignore"
5858 pattern = f"/{ prompts_directory } /"
59- existing = root_gitignore .read_text (encoding = "utf-8" ).splitlines () if root_gitignore .exists () else []
59+ existing_text = root_gitignore .read_text (encoding = "utf-8" ) if root_gitignore .exists () else ""
60+ existing = existing_text .splitlines ()
6061 if pattern not in existing :
6162 with root_gitignore .open ("a" , encoding = "utf-8" ) as fh :
63+ if existing_text and not existing_text .endswith ("\n " ):
64+ fh .write ("\n " )
6265 fh .write (f"{ pattern } \n " )
6366 print (f"Added '{ pattern } ' to { root_gitignore } " )
6467 else :
Original file line number Diff line number Diff line change @@ -44,6 +44,14 @@ def test_root_gitignore_existing_content_preserved(repo: Path) -> None:
4444 assert f"/{ PROMPTS_DIRECTORY } /" in content
4545
4646
47+ def test_root_gitignore_newline_added_when_missing (repo : Path ) -> None :
48+ (repo / ".gitignore" ).write_text ("*.pyc" , encoding = "utf-8" ) # no trailing newline
49+ prepare_repository ()
50+ lines = (repo / ".gitignore" ).read_text (encoding = "utf-8" ).splitlines ()
51+ assert f"/{ PROMPTS_DIRECTORY } /" in lines
52+ assert lines [0 ] == "*.pyc"
53+
54+
4755# ---------------------------------------------------------------------------
4856# get_default_claude_settings
4957# ---------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments